PGSSoft / PuzzleMaker

Swift framework responsible for generating puzzles from the image
MIT License
128 stars 24 forks source link

FYI PuzzleUnit Path must be flipped vertically for usage #11

Open sabiland opened 6 months ago

sabiland commented 6 months ago

This is just informationally. To use puzzleUnit.path, you have to flip the path vertically. Extension UIBezierPath:

func flipIt(vertically: Bool)
{
    let rect = self.bounds
    if vertically
    {
        self.apply(CGAffineTransform(translationX: 0, y: -rect.origin.y))
        self.apply(CGAffineTransform(scaleX: 1, y: -1))
        self.apply(CGAffineTransform(translationX: 0, y: rect.origin.y + rect.height))
    }
    else
    {
        //first, you need to move the view all the way to the left
        //because otherwise, if you mirror it in its current position,
        //the view will be thrown way off screen to the left
        self.apply(CGAffineTransform(translationX: -rect.origin.x, y: 0))
        //then you mirror it
        self.apply(CGAffineTransform(scaleX: -1, y: 1))
        //then, after its mirrored, move it back to its original position
        self.apply(CGAffineTransform(translationX: rect.origin.x + rect.width, y: 0))
    }
}