Skip to content

Commit a19d6bb

Browse files
committed
scaling(dimensionsBy:) tests
1 parent 48d1fad commit a19d6bb

4 files changed

Lines changed: 1414 additions & 199 deletions

File tree

Sources/RectangleTools/Synthesized Conveniences/scaled.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ public enum ScaleMethod {
308308

309309

310310
/// Discard the aspect ratio, and simply set the size to be the same as the parent's
311+
///
312+
/// - When scaling direction is `.down`, then this might result in zero, two, or all four sides touching or passing parent sides.
313+
/// - When scaling direction is `.upOrDown`, then all four sides will **always** touch parent sides.
311314
case stretch
312315
}
313316

@@ -441,7 +444,7 @@ where Length: MultiplicativeArithmetic,
441444
/// - direction: _optional_ - Which direction to scale this rectangle. Defaults to `.down`
442445
///
443446
/// - Returns: A scaled version of this rectangle, relative to the given parent
444-
func scalingEdges(by multiplier: Length, direction: ScaleDirection = .down) -> Self {
447+
func scaling(dimensionsBy multiplier: Length, direction: ScaleDirection = .down) -> Self {
445448
scaled(
446449
within: self * multiplier,
447450
method: .stretch,
@@ -490,7 +493,7 @@ where Length: MultiplicativeArithmetic,
490493
/// - direction: _optional_ - Which direction to scale this rectangle. Defaults to `.down`
491494
///
492495
/// - Returns: A scaled version of this rectangle, relative to the given parent
493-
func scalingEdges(by multiplier: Length, direction: ScaleDirection = .down) -> Self {
496+
func scaling(dimensionsBy multiplier: Length, direction: ScaleDirection = .down) -> Self {
494497
scaled(
495498
within: Self(origin: .zero, size: size * multiplier)
496499
.centered(within: self),

Tests/RectangleToolsTests/Testing convenience functions.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import RectangleTools
1010

1111

1212

13+
// MARK: - Semi-equality
14+
1315
infix operator &&= : AssignmentPrecedence
1416
infix operator ≈≈ : ComparisonPrecedence
1517

@@ -57,3 +59,32 @@ where Value: DualTwoDimensional,
5759
lhs.firstDimensionPair ≈≈ rhs.firstDimensionPair
5860
&& lhs.secondDimensionPair ≈≈ rhs.secondDimensionPair
5961
}
62+
63+
64+
65+
// MARK: - Randomization
66+
67+
68+
69+
extension CGFloat {
70+
static func random() -> Self {
71+
random(in: -1024...1024)
72+
}
73+
}
74+
75+
76+
77+
extension CGPoint {
78+
static func random() -> Self {
79+
.init(x: .random(), y: .random())
80+
}
81+
}
82+
83+
84+
85+
// MARK: - Enumerations
86+
87+
enum AspectRatioExpectation {
88+
case sameAsOriginal
89+
case sameAsParent
90+
}

0 commit comments

Comments
 (0)