-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Also added `CIVector` default conformance to `DualTwoDimensional` - Also added `magnitude` to `DualTwoDimensional`s where the `Length`s match and the distance can be determined. This was done for `CIVector` as sugar for its `.distance` between its two points - Improved description of how `Rectangle`'s `DualTwoDimensional` conformance needs both `Length`s to be the same. Thankfully didn't need to remove the `associatedtype Length` - Added an "Easy To Adopt" section to the README, inspired by this new `.distance` API
- Loading branch information
1 parent
e5c0195
commit b7ab155
Showing
6 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Sources/RectangleTools/Default Conformances/CIVector + DualTwoDimensional.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// CIVector + DualTwoDimensional.swift | ||
// | ||
// | ||
// Created by The Northstar✨ System on 2023-11-16. | ||
// | ||
|
||
import CoreImage | ||
|
||
|
||
|
||
extension CIVector: DualTwoDimensional { | ||
|
||
public var firstDimensionPair: FirstDimensionPair { | ||
.init(x: x, y: y) | ||
} | ||
|
||
|
||
public var secondDimensionPair: SecondDimensionPair { | ||
.init(x: z, y: w) | ||
} | ||
|
||
|
||
|
||
public typealias FirstDimensionPair = CGPoint | ||
public typealias SecondDimensionPair = CGPoint | ||
} | ||
|
||
|
||
|
||
public extension DualTwoDimensional where Self: CIVector { | ||
|
||
init(firstDimensionPair: FirstDimensionPair, | ||
secondDimensionPair: SecondDimensionPair) { | ||
self.init(x: firstDimensionPair.x, | ||
y: firstDimensionPair.y, | ||
z: secondDimensionPair.x, | ||
w: secondDimensionPair.y) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Point Tests.swift | ||
// | ||
// | ||
// Created by The Northstar✨ System on 2023-10-26. | ||
// | ||
|
||
import XCTest | ||
import RectangleTools | ||
|
||
|
||
|
||
final class Point_Tests: XCTestCase { | ||
|
||
func testDistance() { | ||
XCTAssertEqual(CGPoint(x: 0, y: 0).distance(to: CGPoint(x: 1, y: 1)), sqrt(2)) | ||
XCTAssertEqual(CGPoint(x: 0, y: 0).distance(to: CGPoint(x: -1, y: -1)), sqrt(2)) | ||
} | ||
|
||
|
||
func testMagnitude() { | ||
// https://www.wolframalpha.com/input?i=distance+from+%28-2%2C-1%29+to+%285%2C6%29 | ||
XCTAssertEqual(CIVector(x: -2, y: -1, z: 5, w: 6).magnitude, 7 * sqrt(2)) | ||
} | ||
} |