Skip to content

Commit c172648

Browse files
authored
Merge pull request #69 from RougeWare/feature/negation
-negation
2 parents 1dbfafd + cf5fca4 commit c172648

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

Sources/RectangleTools/Synthesized Conveniences/TwoDimensional Extensions.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,19 @@ public extension TwoDimensional where Length: MultiplicativeArithmetic {
263263
/// Returns the product of multiplying both measurements
264264
var product: Length { measurementX * measurementY }
265265
}
266+
267+
268+
269+
public extension TwoDimensional where Length: SignedNumeric {
270+
271+
/// Negates both the X and Y measurements
272+
///
273+
/// ```swift
274+
/// let point = UIntPoint(3, -4)
275+
/// print(-point) // (-3, 4)
276+
/// ```
277+
static prefix func -(_ lhs: Self) -> Self {
278+
Self.init(measurementX: -lhs.measurementX,
279+
measurementY: -lhs.measurementY)
280+
}
281+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// Test.swift
3+
// RectangleTools
4+
//
5+
// Created by Ky on 2024-08-05.
6+
//
7+
8+
import Testing
9+
10+
import RectangleTools
11+
12+
13+
14+
struct InversionTests {
15+
16+
@Test func twoDimensional() async throws {
17+
#expect(.init(width: -4, height: -8) == -TestSizes.intSize__4_8)
18+
#expect(.init(width: -3, height: -4) == -TestSizes.intSize__3_4)
19+
#expect(.init(width: 3, height: -4) == -TestSizes.intSize__n3_4)
20+
#expect(.init(width: -3, height: 4) == -TestSizes.intSize__3_n4)
21+
22+
// #expect(.init(width: -4, height: -8) == -TestSizes.uIntSize__4_8) 🛑 Cannot compile because UInt can't be negated
23+
// #expect(.init(width: -3, height: -4) == -TestSizes.uIntSize__3_4) 🛑 Cannot compile because UInt can't be negated
24+
25+
#expect(.init(width: -4, height: -8) == -TestSizes.cgSize__4_8)
26+
#expect(.init(width: -3, height: -4) == -TestSizes.cgSize__3_4)
27+
#expect(.init(width: 3, height: -4) == -TestSizes.cgSize__n3_4)
28+
#expect(.init(width: -3, height: 4) == -TestSizes.cgSize__3_n4)
29+
30+
#expect(.init(width: -4, height: -8) == -TestSizes.decimalSize__4_8)
31+
#expect(.init(width: -3, height: -4) == -TestSizes.decimalSize__3_4)
32+
#expect(.init(width: 3, height: -4) == -TestSizes.decimalSize__n3_4)
33+
#expect(.init(width: -3, height: 4) == -TestSizes.decimalSize__3_n4)
34+
35+
36+
#expect(.init(x: -4, y: -8) == -TestPoints.intPoint__4_8)
37+
#expect(.init(x: -3, y: -4) == -TestPoints.intPoint__3_4)
38+
#expect(.init(x: 3, y: -4) == -TestPoints.intPoint__n3_4)
39+
#expect(.init(x: -3, y: 4) == -TestPoints.intPoint__3_n4)
40+
41+
// #expect(.init(x: -4, y: -8) == -TestPoints.uIntPoint__4_8) 🛑 Cannot compile because UInt can't be negated
42+
// #expect(.init(x: -3, y: -4) == -TestPoints.uIntPoint__3_4) 🛑 Cannot compile because UInt can't be negated
43+
44+
#expect(.init(x: -4, y: -8) == -TestPoints.cgPoint__4_8)
45+
#expect(.init(x: -3, y: -4) == -TestPoints.cgPoint__3_4)
46+
#expect(.init(x: 3, y: -4) == -TestPoints.cgPoint__n3_4)
47+
#expect(.init(x: -3, y: 4) == -TestPoints.cgPoint__3_n4)
48+
49+
#expect(.init(x: -4, y: -8) == -TestPoints.decimalPoint__4_8)
50+
#expect(.init(x: -3, y: -4) == -TestPoints.decimalPoint__3_4)
51+
#expect(.init(x: 3, y: -4) == -TestPoints.decimalPoint__n3_4)
52+
#expect(.init(x: -3, y: 4) == -TestPoints.decimalPoint__3_n4)
53+
}
54+
}

0 commit comments

Comments
 (0)