Skip to content

Commit 1168614

Browse files
committed
WIP: TwoDimensional operators
1 parent c172648 commit 1168614

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Sources/RectangleTools/Synthesized Conveniences/TwoDimensional Extensions.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,37 @@ public extension TwoDimensional where Length: SignedNumeric {
279279
measurementY: -lhs.measurementY)
280280
}
281281
}
282+
283+
284+
285+
// MARK: - Operators
286+
287+
public extension TwoDimensional where Length: AdditiveArithmetic {
288+
static func + (multiplier: Length, value: Self) -> Self {
289+
.init(
290+
measurementX: multiplier + value.measurementX,
291+
measurementY: multiplier + value.measurementY
292+
)
293+
}
294+
295+
296+
static func + (value: Self, multiplier: Length) -> Self {
297+
multiplier + value
298+
}
299+
}
300+
301+
302+
303+
public extension TwoDimensional where Length: MultiplicativeArithmetic {
304+
static func * (multiplier: Length, value: Self) -> Self {
305+
.init(
306+
measurementX: multiplier * value.measurementX,
307+
measurementY: multiplier * value.measurementY
308+
)
309+
}
310+
311+
312+
static func * (value: Self, multiplier: Length) -> Self {
313+
multiplier * value
314+
}
315+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// TwoDimensional operator tests.swift
3+
// RectangleTools
4+
//
5+
// Created by Ky on 2025-03-22.
6+
//
7+
8+
import Testing
9+
10+
11+
12+
struct TwoDimensional_operatorTests {
13+
@Test
14+
func testMultiply() async throws {
15+
<#body#>
16+
}
17+
}

0 commit comments

Comments
 (0)