From 021e24e9f559f0ca2328137b1d816425731489ff Mon Sep 17 00:00:00 2001 From: brett <20871604+brettinternet@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:49:21 +0000 Subject: [PATCH 1/2] Use overflow-safe Euclidean point distance --- HyperWindow/CGPoint+ext.swift | 2 +- HyperWindowTests/CGPointTests.swift | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 HyperWindowTests/CGPointTests.swift diff --git a/HyperWindow/CGPoint+ext.swift b/HyperWindow/CGPoint+ext.swift index bf8d43e..8d60cf1 100644 --- a/HyperWindow/CGPoint+ext.swift +++ b/HyperWindow/CGPoint+ext.swift @@ -4,7 +4,7 @@ import Foundation extension CGPoint { func distance(to point: CGPoint) -> CGFloat { - return sqrt(pow(point.x - self.x, 2) + pow(point.y - self.y, 2)) + return hypot(point.x - self.x, point.y - self.y) } } diff --git a/HyperWindowTests/CGPointTests.swift b/HyperWindowTests/CGPointTests.swift new file mode 100644 index 0000000..2284180 --- /dev/null +++ b/HyperWindowTests/CGPointTests.swift @@ -0,0 +1,12 @@ +import XCTest +@testable import HyperWindow + +final class CGPointTests: XCTestCase { + func test_distanceRemainsFiniteForLargeFiniteCoordinates() { + let coordinate = CGFloat.greatestFiniteMagnitude / 4 + let distance = CGPoint.zero.distance(to: CGPoint(x: coordinate, y: coordinate)) + + XCTAssertTrue(distance.isFinite) + XCTAssertEqual(distance / coordinate, sqrt(2), accuracy: 1e-15) + } +} From 295a13d8a40e64bff4b877a871fdf438a8828e10 Mon Sep 17 00:00:00 2001 From: brett <20871604+brettinternet@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:42:23 -0600 Subject: [PATCH 2/2] Drop overflow test --- HyperWindowTests/CGPointTests.swift | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 HyperWindowTests/CGPointTests.swift diff --git a/HyperWindowTests/CGPointTests.swift b/HyperWindowTests/CGPointTests.swift deleted file mode 100644 index 2284180..0000000 --- a/HyperWindowTests/CGPointTests.swift +++ /dev/null @@ -1,12 +0,0 @@ -import XCTest -@testable import HyperWindow - -final class CGPointTests: XCTestCase { - func test_distanceRemainsFiniteForLargeFiniteCoordinates() { - let coordinate = CGFloat.greatestFiniteMagnitude / 4 - let distance = CGPoint.zero.distance(to: CGPoint(x: coordinate, y: coordinate)) - - XCTAssertTrue(distance.isFinite) - XCTAssertEqual(distance / coordinate, sqrt(2), accuracy: 1e-15) - } -}