Skip to content

Commit d601b68

Browse files
authored
Merge pull request #50 from RougeWare/develop
Sync develop into master
2 parents 0bc598f + ee6bc50 commit d601b68

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

Sources/RectangleTools/Synthesized Conveniences/Rectangle Extensions.swift

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,79 @@ public extension Rectangle
5252
Length: Comparable,
5353
Length: AdditiveArithmetic
5454
{
55+
// MARK: Edgewise init
56+
57+
/// Creates a new rectangle with its sides at the given positions
58+
///
59+
/// ```swift
60+
/// .init(
61+
/// minX: 0,
62+
/// minY: 2,
63+
/// maxX: 4,
64+
/// maxY: 6
65+
/// )
66+
/// ```
67+
/// ```
68+
/// 6 ┢━━━━━━━┓
69+
/// 5 ┃ ┃
70+
/// 4 ┃ ┃
71+
/// 3 ┃ ┃
72+
/// 2 ┡━━━━━━━┛
73+
/// 1 │
74+
/// 0 ┼────────────
75+
/// 0 1 2 3 4 5 6
76+
///
77+
///
78+
/// 0 1 2 3 4 5 6
79+
/// 0 ┼────────────
80+
/// 1 │
81+
/// 2 ┢━━━━━━━┓
82+
/// 3 ┃ ┃
83+
/// 4 ┃ ┃
84+
/// 5 ┃ ┃
85+
/// 6 ┡━━━━━━━┛
86+
/// ```
87+
///
88+
/// - Parameters:
89+
/// - minX: The lowest X value of the new rectangle
90+
/// - minY: The lowest Y value of the new rectangle
91+
/// - maxX: The greatest X value of the new rectangle
92+
/// - maxY: The greatest Y value of the new rectangle
93+
init(
94+
minX: Length,
95+
minY: Length,
96+
maxX: Length,
97+
maxY: Length
98+
) {
99+
guard minX <= maxX else {
100+
assertionFailure("minX must be less or equal to than maxX")
101+
self.init(
102+
minX: maxX,
103+
minY: minY,
104+
maxX: minX,
105+
maxY: maxY)
106+
return
107+
}
108+
109+
guard minY <= maxY else {
110+
assertionFailure("minY must be less or equal to than maxY")
111+
self.init(
112+
minX: minX,
113+
minY: maxY,
114+
maxX: maxX,
115+
maxY: minY)
116+
return
117+
}
118+
119+
120+
self.init(
121+
x: minX,
122+
y: minY,
123+
width: maxX - minX,
124+
height: maxY - minY)
125+
}
126+
127+
55128
// MARK: Edges
56129

57130
/// The smallest X value in this rectangle

Tests/LinuxMain.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ tests += SizeMeasurementTests.allTests
1818
tests += SizePositionTests.allTests
1919
tests += TwoDimensionalMeasurementTests.allTests
2020
tests += FourSidedTests.allTests
21+
tests += Rectangle_Edgewise_Init_Tests.allTests
2122
XCTMain(tests)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// Rectangle Edgewise Init Tests.swift
3+
// RectangleTools
4+
//
5+
// Created by Ben Leggiero on 2020-08-05.
6+
// Copyright © 2019 Ben Leggiero BH-1-PS.
7+
//
8+
9+
import XCTest
10+
import RectangleTools
11+
12+
13+
14+
final class Rectangle_Edgewise_Init_Tests: XCTestCase {
15+
16+
func test_init_minX_minY_maxX_maxY() {
17+
let rect_2_4_6_8 = DecimalRectangle(minX: 2, minY: 4, maxX: 6, maxY: 8)
18+
19+
XCTAssertEqual(rect_2_4_6_8.minX, 2)
20+
XCTAssertEqual(rect_2_4_6_8.minY, 4)
21+
XCTAssertEqual(rect_2_4_6_8.maxX, 6)
22+
XCTAssertEqual(rect_2_4_6_8.maxY, 8)
23+
}
24+
25+
26+
static let allTests = [
27+
("test_init_minX_maxX_minY_maxY", test_init_minX_minY_maxX_maxY),
28+
]
29+
}
30+
31+

Tests/RectangleToolsTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public func allTests() -> [XCTestCaseEntry] {
1818
testCase(SizePositionTests.allTests),
1919
testCase(TwoDimensionalMeasurementTests.allTests),
2020
testCase(FourSidedTests.allTests),
21+
testCase(Rectangle_Edgewise_Init_Tests.allTests),
2122
]
2223
}
2324
#endif

0 commit comments

Comments
 (0)