Skip to content

Commit f77bafb

Browse files
Floating Points (#2)
Replaced all default 'Float' types with 'Double'.
1 parent cba4bfb commit f77bafb

26 files changed

+99
-1037
lines changed

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,15 @@ let package = Package(
1414
products: [
1515
.library(
1616
name: "GraphPoint",
17-
targets: ["GraphPoint", "GraphPointUI"]),
17+
targets: ["GraphPoint"]),
1818
],
1919
dependencies: [
20-
.package(url: "https://github.com/richardpiazza/Swift2D", .upToNextMinor(from: "1.1.0")),
20+
.package(url: "https://github.com/richardpiazza/Swift2D", .upToNextMajor(from: "2.0.0")),
2121
],
2222
targets: [
2323
.target(
2424
name: "GraphPoint",
2525
dependencies: ["Swift2D"]),
26-
.target(
27-
name: "GraphPointUI",
28-
dependencies: ["GraphPoint"]),
2926
.testTarget(
3027
name: "GraphPointTests",
3128
dependencies: ["GraphPoint"]),

Sources/GraphPoint/CartesianFrame.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public extension CartesianFrame {
4747
public extension CartesianFrame {
4848
/// Identifies the minimum `CartesianFrame` that contains all of the provided points.
4949
///
50-
/// - parameter points: The `CartesianPoint`s with which to map into a frame.
50+
/// - parameters:
51+
/// - points: The `CartesianPoint`s with which to map into a frame.
5152
/// - returns: A `CartesianFrame` containing all of the points.
5253
static func make(for points: [CartesianPoint]) -> CartesianFrame {
5354
var minXMaxY = Point()
@@ -112,8 +113,9 @@ public extension CartesianFrame {
112113
/// ▼
113114
/// ```
114115
///
115-
/// - parameter arc: The points and radius of the circle on which the chord is present.
116-
/// - parameter points: Additional points that extend the resulting frame.
116+
/// - parameters:
117+
/// - arc: The points and radius of the circle on which the chord is present.
118+
/// - points: Additional points that extend the resulting frame.
117119
/// - returns: A `CartesianFrame` containing all of the points.
118120
/// - throws: GraphPointError.unhandledQuadrantTransition(_:_:)
119121
static func make(for arc: Arc, points: [CartesianPoint]) throws -> CartesianFrame {

Sources/GraphPoint/CartesianPlane.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public extension CartesianPlane {
3939
}
4040

4141
/// The length of the shortest axis found in this plane.
42-
var minimumAxis: Float {
42+
var minimumAxis: Double {
4343
return min(midX, midY)
4444
}
4545

4646
/// The length of the shortest axis found in this plane.
47-
var maximumAxis: Float {
47+
var maximumAxis: Double {
4848
return max(midX, midY)
4949
}
5050

@@ -62,7 +62,8 @@ public extension CartesianPlane {
6262
/// // cartesianPoint == CartesianPoint(x: -25, y: 25)
6363
/// ```
6464
///
65-
/// - parameter point: A standard `Point` (which uses top-left as {0, 0}).
65+
/// - parameters:
66+
/// - point: A standard `Point` (which uses top-left as {0, 0}).
6667
/// - returns A `CartesianPoint` which has been translated onto the _plane_.
6768
func cartesianPoint(for point: Point) -> CartesianPoint {
6869
let origin = cartesianOrigin
@@ -107,4 +108,9 @@ public extension CartesianPlane {
107108
let origin = cartesianOrigin
108109
return Rect(origin: Point(x: origin.x + cartesianFrame.origin.x, y: origin.y - cartesianFrame.origin.y), size: cartesianFrame.size)
109110
}
111+
112+
/// A `CartesianPoint` within the bounds of the plane for the given `Degree` and `maximumAxis`.
113+
func cartesianPoint(for degree: Degree, clockwise: Bool = true) throws -> CartesianPoint {
114+
try CartesianPoint.make(for: maximumAxis, degree: degree, clockwise: clockwise)
115+
}
110116
}

Sources/GraphPoint/CartesianPoint.swift

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public typealias CartesianPoint = Point
2121

2222
public extension CartesianPoint {
2323
/// The minimum axis for a `CartesianPlane` that would contain this point.
24-
var minimumAxis: Float {
24+
var minimumAxis: Double {
2525
return max(abs(x), abs(y))
2626
}
2727
}
@@ -31,8 +31,9 @@ public extension CartesianPoint {
3131
///
3232
/// Uses the mathematical **Law of Sines**.
3333
///
34-
/// - parameter radius: The straight line distance from the _origin_.
35-
/// - parameter degree: The angular degree (0-360), clockwise from the x-axis.
34+
/// - parameters:
35+
/// - radius: The straight line distance from the _origin_.
36+
/// - degree: The angular degree (0-360), clockwise from the x-axis.
3637
/// - returns:A `CartesianPoint` with offsets from the _origin_.
3738
static func make(for radius: Radius, degree: Degree, clockwise: Bool = true) throws -> CartesianPoint {
3839
guard degree >= 0.0, degree <= 360.0 else {
@@ -47,10 +48,10 @@ public extension CartesianPoint {
4748
return .zero
4849
}
4950

50-
let rightAngle: Float = 90.0
51+
let rightAngle: Double = 90.0
5152
let sinRight = sin(rightAngle.radians)
52-
var rise: Float = 0.0
53-
var run: Float = 0.0
53+
var rise: Double = 0.0
54+
var run: Double = 0.0
5455
var point: CartesianPoint = .zero
5556

5657
switch clockwise {
@@ -110,9 +111,10 @@ public extension CartesianPoint {
110111
/// * **c**: calculated based on `degree` and `radius`.
111112
/// * **a**: supplied via the `point` (x/y based on closest axis)
112113
///
113-
/// - parameter radius: The straight line distance from the _origin_.
114-
/// - parameter degree: The angular degree (0-360), clockwise from the x-axis.
115-
/// - parameter modifier: The point used to clip or expand the result. The nearest axis value is used.
114+
/// - parameters:
115+
/// - radius: The straight line distance from the _origin_.
116+
/// - degree: The angular degree (0-360), clockwise from the x-axis.
117+
/// - modifier: The point used to clip or expand the result. The nearest axis value is used.
116118
static func make(for radius: Radius, degree: Degree, modifier: CartesianPoint, clockwise: Bool = true) throws -> CartesianPoint {
117119
guard degree >= 0.0, degree <= 360.0 else {
118120
throw GraphPointError.invalidDegree(degree)
@@ -131,28 +133,28 @@ public extension CartesianPoint {
131133
switch clockwise {
132134
case true:
133135
if (degree >= 315) {
134-
point.x = sqrtf(powf(radius, 2) - powf(modifier.y, 2))
136+
point.x = sqrt(pow(radius, 2) - pow(modifier.y, 2))
135137
point.y = modifier.y
136138
} else if (degree >= 270) {
137139
point.x = modifier.x
138-
point.y = sqrtf(powf(radius, 2) - powf(modifier.x, 2))
140+
point.y = sqrt(pow(radius, 2) - pow(modifier.x, 2))
139141
} else if (degree >= 225) {
140142
point.x = modifier.x
141-
point.y = sqrtf(powf(radius, 2) - powf(modifier.x, 2))
143+
point.y = sqrt(pow(radius, 2) - pow(modifier.x, 2))
142144
} else if (degree >= 180) {
143-
point.x = -(sqrtf(powf(radius, 2) - powf(modifier.y, 2)))
145+
point.x = -(sqrt(pow(radius, 2) - pow(modifier.y, 2)))
144146
point.y = modifier.y
145147
} else if (degree >= 135) {
146-
point.x = -(sqrtf(powf(radius, 2) - powf(modifier.y, 2)))
148+
point.x = -(sqrt(pow(radius, 2) - pow(modifier.y, 2)))
147149
point.y = modifier.y
148150
} else if (degree >= 90) {
149151
point.x = modifier.x
150-
point.y = -(sqrtf(powf(radius, 2) - powf(modifier.x, 2)))
152+
point.y = -(sqrt(pow(radius, 2) - pow(modifier.x, 2)))
151153
} else if (degree >= 45) {
152154
point.x = modifier.x
153-
point.y = -(sqrtf(powf(radius, 2) - powf(modifier.x, 2)))
155+
point.y = -(sqrt(pow(radius, 2) - pow(modifier.x, 2)))
154156
} else if (degree >= 0) {
155-
point.x = sqrtf(powf(radius, 2) - powf(modifier.y, 2))
157+
point.x = sqrt(pow(radius, 2) - pow(modifier.y, 2))
156158
point.y = modifier.y
157159
}
158160
case false:

Sources/GraphPoint/Degree.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Swift2D
55
///
66
/// Degree 0 (zero) is the positive x axis and increments clockwise.
77
/// TODO: Rotating clockwise to match CoreGraphics, but should this match the Quadrant flow?
8-
public typealias Degree = Float
8+
public typealias Degree = Double
99

1010
public extension Degree {
1111
/// Converts an angular degree to radians
@@ -17,7 +17,8 @@ public extension Degree {
1717
///
1818
/// Uses the mathematical **Law of Cotangents**.
1919
///
20-
/// - parameter point: A `CartesianPoint` with offsets from the _origin_.
20+
/// - parameters:
21+
/// - point: A `CartesianPoint` with offsets from the _origin_.
2122
/// - returns:The angular degree (0-360), clockwise from the x-axis.
2223
static func make(for cartesianPoint: CartesianPoint, clockwise: Bool = true) throws -> Degree {
2324
guard cartesianPoint != .nan else {

Sources/GraphPoint/Deprecated/CGFloat+GraphPoint.swift

Lines changed: 0 additions & 18 deletions
This file was deleted.

Sources/GraphPoint/Deprecated/CGPoint+GraphPoint.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

Sources/GraphPoint/Deprecated/CGRect+GraphPoint.swift

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)