TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Incorrect positioning of the path

Forums > SwiftUI

@Sanda  

This is my Path type propery in which I try to start from firstPoint coordinates and draw lines to different points.

var linePath: Path {
        var path = Path()
        if let firstPoint = multimeaVarfurilor.first {
            path.move(to: CGPoint(x: CGFloat(firstPoint.x) + 150 , y: CGFloat(firstPoint.y)))
        }
        for point in multimeaVarfurilor.dropFirst() {
            path.addLine(to: CGPoint(x: CGFloat(point.x * 10) + 150, y: CGFloat(point.y * 10)))

        }
        return path
    }

The problem is that no matter what are the firstPoint coordinates, it alwais starts drawing from (x: 150 , y: 0). Respectively, when drawing, from example a triangle, it is not drawn correctly. Can someone explain me why it is happening and how to fix it?

2      

Hacking with Swift is sponsored by Blaze.

SPONSORED Still waiting on your CI build? Speed it up ~3x with Blaze - change one line, pay less, keep your existing GitHub workflows. First 25 HWS readers to use code HACKING at checkout get 50% off the first year. Try it now for free!

Reserve your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.