From 55e1f230516a80f9e49ad63e3797d19b3f4918ce Mon Sep 17 00:00:00 2001 From: Holmes Futrell Date: Thu, 14 Feb 2019 23:34:39 -0800 Subject: [PATCH] more precision in Utils.align, tests should really pass now? --- BezierKit/Library/Utils.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/BezierKit/Library/Utils.swift b/BezierKit/Library/Utils.swift index 04ae89b9..f9c557ee 100644 --- a/BezierKit/Library/Utils.swift +++ b/BezierKit/Library/Utils.swift @@ -352,16 +352,17 @@ internal class Utils { } static func align(_ points: [CGPoint], p1: CGPoint, p2: CGPoint) -> [CGPoint] { - let tx = p1.x - let ty = p1.y - let a = -atan2(p2.y-ty, p2.x-tx) - let d = {( v: CGPoint) in + let tx = Double(p1.x) + let ty = Double(p1.y) + let a = -atan2(Double(p2.y)-ty, Double(p2.x)-tx) + return points.map { v in + let vx = Double(v.x) + let vy = Double(v.y) return CGPoint( - x: (v.x-tx)*cos(a) - (v.y-ty)*sin(a), - y: (v.x-tx)*sin(a) + (v.y-ty)*cos(a) + x: (vx-tx)*cos(a) - (vy-ty)*sin(a), + y: (vx-tx)*sin(a) + (vy-ty)*cos(a) ) } - return points.map(d) } static func closest(_ LUT: [CGPoint],_ point: CGPoint) -> (mdist: CGFloat, mpos: Int) {