Skip to content

Commit 14f0325

Browse files
committed
Add convenience members
1 parent 80aa226 commit 14f0325

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

Sources/GameMath/2D Types (New)/Rectn.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,42 @@ public struct Rect2n<Scalar: Vector2n.ScalarType> {
2424
self.size = size
2525
}
2626
}
27+
28+
extension Rect2n {
29+
@_transparent
30+
public var x: Scalar {
31+
get {
32+
return position.x
33+
}
34+
mutating set {
35+
position.x = newValue
36+
}
37+
}
38+
@_transparent
39+
public var y: Scalar {
40+
get {
41+
return position.y
42+
}
43+
mutating set {
44+
position.y = newValue
45+
}
46+
}
47+
@_transparent
48+
public var width: Scalar {
49+
get {
50+
return size.width
51+
}
52+
mutating set {
53+
size.width = newValue
54+
}
55+
}
56+
@_transparent
57+
public var height: Scalar {
58+
get {
59+
return size.height
60+
}
61+
mutating set {
62+
size.height = newValue
63+
}
64+
}
65+
}

Sources/GameMath/2D Types (New)/Vector2n.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ public extension Vector2n where Scalar: FloatingPoint {
164164
static func /= (lhs: inout Self, rhs: some Vector2n<Scalar>) {
165165
lhs = lhs / rhs
166166
}
167+
168+
@inlinable
169+
static var nan: Self {Self(x: .nan, y: .nan)}
170+
171+
@inlinable
172+
static var infinity: Self {Self(x: .infinity, y: .infinity)}
167173
}
168174

169175
public extension Vector2n where Scalar: FixedWidthInteger {
@@ -179,6 +185,16 @@ public extension Vector2n where Scalar: FixedWidthInteger {
179185
}
180186

181187
public extension Vector2n where Scalar: Comparable {
188+
@inlinable
189+
var min: Scalar {
190+
return Swift.min(x, y)
191+
}
192+
193+
@inlinable
194+
var max: Scalar {
195+
return Swift.max(x, y)
196+
}
197+
182198
@inlinable
183199
static func < (lhs: Self, rhs: some Vector2n<Scalar>) -> Bool {
184200
return lhs.x < rhs.x && lhs.y < rhs.y

Sources/GameMath/3D Types (New)/Vector3n.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ public extension Vector3n where Scalar: FloatingPoint {
154154
static func /= (lhs: inout Self, rhs: Self) {
155155
lhs = lhs / rhs
156156
}
157+
158+
159+
@inlinable
160+
static var nan: Self {Self(x: .nan, y: .nan, z: .nan)}
161+
162+
@inlinable
163+
static var infinity: Self {Self(x: .infinity, y: .infinity, z: .infinity)}
157164
}
158165

159166
public extension Vector3n where Scalar: FixedWidthInteger {
@@ -169,6 +176,16 @@ public extension Vector3n where Scalar: FixedWidthInteger {
169176
}
170177

171178
public extension Vector3n where Scalar: Comparable {
179+
@inlinable
180+
var min: Scalar {
181+
return Swift.min(x, Swift.min(y, z))
182+
}
183+
184+
@inlinable
185+
var max: Scalar {
186+
return Swift.max(x, Swift.max(y, z))
187+
}
188+
172189
static func < (lhs: Self, rhs: Self) -> Bool {
173190
return lhs.x < rhs.x && lhs.y < rhs.y && lhs.z < rhs.z
174191
}

Sources/GameMath/3D Types/3D Physics/Line3D.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public extension Line3D {
2323
return Direction3(from: p1, to: p2)
2424
}
2525

26+
@inlinable
27+
var center: Position3 {
28+
return (p1 + p2) / 2
29+
}
30+
2631
@inlinable
2732
func pointNear(_ p: Position3) -> Position3 {
2833
let ab = p2 - p1

0 commit comments

Comments
 (0)