Skip to content

Commit b12eed5

Browse files
committed
Continue new GameMath implementation
1 parent f25d443 commit b12eed5

File tree

8 files changed

+102
-63
lines changed

8 files changed

+102
-63
lines changed

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

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public extension Position2n where Scalar: FloatingPoint {
4747
}
4848
}
4949
extension Position2n: AdditiveArithmetic where Scalar: AdditiveArithmetic { }
50-
extension Position2n: ExpressibleByIntegerLiteral where Scalar: FixedWidthInteger & _ExpressibleByBuiltinIntegerLiteral & ExpressibleByIntegerLiteral { }
51-
extension Position2n: ExpressibleByFloatLiteral where Scalar: FloatingPoint & _ExpressibleByBuiltinFloatLiteral & ExpressibleByFloatLiteral { }
5250
extension Position2n: Equatable where Scalar: Equatable { }
5351
extension Position2n: Hashable where Scalar: Hashable { }
5452
extension Position2n: Comparable where Scalar: Comparable { }
@@ -78,8 +76,6 @@ public extension Direction2n where Scalar: FloatingPoint {
7876
}
7977
}
8078
extension Direction2n: AdditiveArithmetic where Scalar: AdditiveArithmetic { }
81-
extension Direction2n: ExpressibleByIntegerLiteral where Scalar: FixedWidthInteger & _ExpressibleByBuiltinIntegerLiteral & ExpressibleByIntegerLiteral { }
82-
extension Direction2n: ExpressibleByFloatLiteral where Scalar: FloatingPoint & _ExpressibleByBuiltinFloatLiteral & ExpressibleByFloatLiteral { }
8379
extension Direction2n: Equatable where Scalar: Equatable { }
8480
extension Direction2n: Hashable where Scalar: Hashable { }
8581
extension Direction2n: Comparable where Scalar: Comparable { }
@@ -103,8 +99,6 @@ public struct Size2n<Scalar: Vector2n.ScalarType>: Vector2n {
10399
public static var one: Self { .init(x: 1, y: 1) }
104100
}
105101
extension Size2n: AdditiveArithmetic where Scalar: AdditiveArithmetic { }
106-
extension Size2n: ExpressibleByIntegerLiteral where Scalar: FixedWidthInteger & _ExpressibleByBuiltinIntegerLiteral & ExpressibleByIntegerLiteral { }
107-
extension Size2n: ExpressibleByFloatLiteral where Scalar: FloatingPoint & _ExpressibleByBuiltinFloatLiteral & ExpressibleByFloatLiteral { }
108102
extension Size2n: Equatable where Scalar: Equatable { }
109103
extension Size2n: Hashable where Scalar: Hashable { }
110104
extension Size2n: Comparable where Scalar: Comparable { }
@@ -242,20 +236,6 @@ extension Vector2n where Scalar: BinaryFloatingPoint {
242236
}
243237
}
244238

245-
public extension Vector2n where Scalar: FixedWidthInteger & _ExpressibleByBuiltinIntegerLiteral & ExpressibleByIntegerLiteral {
246-
typealias IntegerLiteralType = Scalar
247-
init(integerLiteral value: IntegerLiteralType) {
248-
self.init(x: value, y: value)
249-
}
250-
}
251-
252-
public extension Vector2n where Scalar: FloatingPoint & _ExpressibleByBuiltinFloatLiteral & ExpressibleByFloatLiteral {
253-
typealias FloatLiteralType = Scalar
254-
init(floatLiteral value: FloatLiteralType) {
255-
self.init(x: value, y: value)
256-
}
257-
}
258-
259239
public extension Vector2n where Scalar: AdditiveArithmetic {
260240
@inlinable
261241
static func + (lhs: Self, rhs: some Vector2n<Scalar>) -> Self {
@@ -277,9 +257,8 @@ public extension Vector2n where Scalar: AdditiveArithmetic {
277257
return Self(x: lhs.x - rhs, y: lhs.y - rhs)
278258
}
279259

280-
@_disfavoredOverload // <- Tell the compiler to prefer using integer literals to avoid ambiguilty
281260
@inlinable
282-
static var zero: Self {Self(x: Scalar.zero, y: Scalar.zero)}
261+
static var zero: Self {Self(x: .zero, y: .zero)}
283262
}
284263

285264
public extension Vector2n where Scalar: Numeric {
@@ -356,6 +335,13 @@ public extension Vector2n where Scalar: FloatingPoint {
356335
)
357336
}
358337

338+
@inlinable
339+
var isFinite: Bool {
340+
nonmutating get {
341+
return x.isFinite && y.isFinite
342+
}
343+
}
344+
359345
@inlinable
360346
static var nan: Self {Self(x: .nan, y: .nan)}
361347

@@ -479,7 +465,7 @@ public extension Vector2n {
479465
}
480466
}
481467

482-
public extension Vector2n where Scalar: FloatingPoint {
468+
public extension Vector2n where Scalar: FloatingPoint, Self: Equatable {
483469
@inlinable
484470
var magnitude: Scalar {
485471
nonmutating get {
@@ -494,7 +480,7 @@ public extension Vector2n where Scalar: FloatingPoint {
494480

495481
@inlinable
496482
mutating func normalize() {
497-
guard self != 0 else { return }
483+
guard self != Self.zero else { return }
498484
let magnitude = self.magnitude
499485
let factor = 1 / magnitude
500486
self *= factor
@@ -510,8 +496,6 @@ public extension Vector2n where Scalar: FloatingPoint {
510496
}
511497
}
512498

513-
514-
515499
extension Vector2n where Scalar: BinaryCodable {
516500
public func encode(into data: inout ContiguousArray<UInt8>, version: BinaryCodableVersion) throws {
517501
try self.x.encode(into: &data, version: version)

Sources/GameMath/3D Types (New)/Apple SIMD/Vector3n+AppleSIMD.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public extension Vector3n where Scalar == Float16 {
9191
}
9292

9393
@inlinable @_transparent
94-
mutating func normalize() {
95-
guard self != .zero else { return }
94+
mutating func normalize() where Self: Equatable {
95+
guard self != Self.zero else { return }
9696
self = unsafeBitCast(simd_normalize(self.simd()), to: Self.self)
9797
}
9898

@@ -206,8 +206,8 @@ public extension Vector3n where Scalar == Float32 {
206206
}
207207

208208
@inlinable @_transparent
209-
mutating func normalize() {
210-
guard self != .zero else { return }
209+
mutating func normalize() where Self: Equatable {
210+
guard self != Self.zero else { return }
211211
self = unsafeBitCast(simd_normalize(self.simd()), to: Self.self)
212212
}
213213

@@ -337,8 +337,8 @@ public extension Vector3n where Scalar == Float64 {
337337
}
338338

339339
@inlinable @_transparent
340-
mutating func normalize() {
341-
guard self != .zero else { return }
340+
mutating func normalize() where Self: Equatable {
341+
guard self != Self.zero else { return }
342342
self = unsafeBitCast(simd_normalize(self.simd()), to: Self.self)
343343
}
344344

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,41 @@ public struct Direction3n<Scalar: Vector3n.ScalarType>: Vector3n {
2828
}
2929
}
3030

31+
public extension Direction3n {
32+
@inlinable
33+
var xy: Direction2n<Scalar> {
34+
nonmutating get {
35+
return Direction2n(x: x, y: y)
36+
}
37+
mutating set {
38+
self.x = newValue.x
39+
self.y = newValue.y
40+
}
41+
}
42+
43+
@inlinable
44+
var xz: Direction2n<Scalar> {
45+
nonmutating get {
46+
return Direction2n(x: x, y: z)
47+
}
48+
mutating set {
49+
self.x = newValue.x
50+
self.z = newValue.y
51+
}
52+
}
53+
54+
@inlinable
55+
var yz: Direction2n<Scalar> {
56+
nonmutating get {
57+
return Direction2n(x: y, y: z)
58+
}
59+
mutating set {
60+
self.y = newValue.x
61+
self.z = newValue.y
62+
}
63+
}
64+
}
65+
3166
public extension Direction3n where Scalar: FloatingPoint {
3267
@inlinable
3368
func rotated(by rotation: Rotation3n<Scalar>) -> Self {
@@ -130,8 +165,6 @@ public extension Direction3n where Scalar: FloatingPoint {
130165
}
131166

132167
extension Direction3n: AdditiveArithmetic where Scalar: AdditiveArithmetic { }
133-
extension Direction3n: ExpressibleByIntegerLiteral where Scalar: _ExpressibleByBuiltinIntegerLiteral & ExpressibleByIntegerLiteral { }
134-
extension Direction3n: ExpressibleByFloatLiteral where Scalar: FloatingPoint & _ExpressibleByBuiltinFloatLiteral & ExpressibleByFloatLiteral { }
135168
extension Direction3n: Equatable where Scalar: Equatable { }
136169
extension Direction3n: Hashable where Scalar: Hashable { }
137170
extension Direction3n: Comparable where Scalar: Comparable { }

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ public extension Position3n where Scalar: FloatingPoint {
136136
}
137137

138138
extension Position3n: AdditiveArithmetic where Scalar: AdditiveArithmetic { }
139-
extension Position3n: ExpressibleByIntegerLiteral where Scalar: _ExpressibleByBuiltinIntegerLiteral & ExpressibleByIntegerLiteral { }
140-
extension Position3n: ExpressibleByFloatLiteral where Scalar: FloatingPoint & _ExpressibleByBuiltinFloatLiteral & ExpressibleByFloatLiteral { }
141139
extension Position3n: Equatable where Scalar: Equatable { }
142140
extension Position3n: Hashable where Scalar: Hashable { }
143141
extension Position3n: Comparable where Scalar: Comparable { }

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ extension Rotation3n {
153153
var conjugate: Self {
154154
return Self(x: -x, y: -y, z: -z, w: w)
155155
}
156+
157+
@inlinable
158+
var isFinite: Bool {
159+
return self.x.isFinite && self.y.isFinite && self.z.isFinite && self.w.isFinite
160+
}
156161
}
157162

158163
extension Rotation3n: AdditiveArithmetic where Scalar: AdditiveArithmetic {

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

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,41 @@ public struct Size3n<Scalar: Vector3n.ScalarType>: Vector3n {
3131
}
3232
}
3333

34+
public extension Size3n {
35+
@inlinable
36+
var xy: Size2n<Scalar> {
37+
nonmutating get {
38+
return Size2n(x: x, y: y)
39+
}
40+
mutating set {
41+
self.x = newValue.x
42+
self.y = newValue.y
43+
}
44+
}
45+
46+
@inlinable
47+
var xz: Size2n<Scalar> {
48+
nonmutating get {
49+
return Size2n(x: x, y: z)
50+
}
51+
mutating set {
52+
self.x = newValue.x
53+
self.z = newValue.y
54+
}
55+
}
56+
57+
@inlinable
58+
var yz: Size2n<Scalar> {
59+
nonmutating get {
60+
return Size2n(x: y, y: z)
61+
}
62+
mutating set {
63+
self.y = newValue.x
64+
self.z = newValue.y
65+
}
66+
}
67+
}
68+
3469
public extension Size3n {
3570
@inlinable
3671
var width: Scalar {
@@ -63,8 +98,6 @@ public extension Size3n {
6398
}
6499

65100
extension Size3n: AdditiveArithmetic where Scalar: AdditiveArithmetic { }
66-
extension Size3n: ExpressibleByIntegerLiteral where Scalar: _ExpressibleByBuiltinIntegerLiteral & ExpressibleByIntegerLiteral { }
67-
extension Size3n: ExpressibleByFloatLiteral where Scalar: FloatingPoint & _ExpressibleByBuiltinFloatLiteral & ExpressibleByFloatLiteral { }
68101
extension Size3n: Equatable where Scalar: Equatable { }
69102
extension Size3n: Hashable where Scalar: Hashable { }
70103
extension Size3n: Comparable where Scalar: Comparable { }

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

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,6 @@ public extension Vector3n where Scalar: BinaryFloatingPoint {
112112
}
113113
}
114114

115-
public extension Vector3n where Scalar: _ExpressibleByBuiltinIntegerLiteral & ExpressibleByIntegerLiteral {
116-
typealias IntegerLiteralType = Scalar
117-
118-
@inlinable
119-
@_transparent
120-
init(integerLiteral value: IntegerLiteralType) {
121-
self.init(x: value, y: value, z: value)
122-
}
123-
}
124-
125-
public extension Vector3n where Scalar: FloatingPoint & _ExpressibleByBuiltinFloatLiteral & ExpressibleByFloatLiteral {
126-
typealias FloatLiteralType = Scalar
127-
128-
@inlinable
129-
@_transparent
130-
init(floatLiteral value: FloatLiteralType) {
131-
self.init(x: value, y: value, z: value)
132-
}
133-
}
134-
135115
public extension Vector3n {
136116
typealias Element = Scalar
137117

@@ -220,7 +200,6 @@ public extension Vector3n where Scalar: AdditiveArithmetic {
220200
return Self(x: lhs - rhs.x, y: lhs - rhs.y, z: lhs - rhs.z)
221201
}
222202

223-
@_disfavoredOverload // <- Tell the compiler to prefer using integer literals to avoid ambiguilty
224203
@inlinable
225204
static var zero: Self {Self(x: .zero, y: .zero, z: .zero)}
226205
}
@@ -304,6 +283,13 @@ public extension Vector3n where Scalar: FloatingPoint {
304283
)
305284
}
306285

286+
@inlinable
287+
var isFinite: Bool {
288+
nonmutating get {
289+
return x.isFinite && y.isFinite && z.isFinite
290+
}
291+
}
292+
307293
@inlinable
308294
static var nan: Self {Self(x: .nan, y: .nan, z: .nan)}
309295

@@ -488,7 +474,7 @@ public extension Vector3n {
488474
}
489475
}
490476

491-
public extension Vector3n where Scalar: FloatingPoint {
477+
public extension Vector3n where Scalar: FloatingPoint, Self: Equatable {
492478
@inlinable
493479
var magnitude: Scalar {
494480
nonmutating get {
@@ -503,7 +489,7 @@ public extension Vector3n where Scalar: FloatingPoint {
503489

504490
@inlinable
505491
mutating func normalize() {
506-
guard self != 0 else { return }
492+
guard self != Self.zero else { return }
507493
let magnitude = self.magnitude
508494
let factor = 1 / magnitude
509495
self *= factor

Sources/GateEngine/Resources/Lights/Baking/LightMapBaker.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ public extension LightMapBaker {
227227
public init(
228228
radiosity: Radiosity = .fullyRadiant,
229229
occlusion: Occlusion = .fullyOccluding,
230-
minimumTexels: Size2i = 4,
230+
minimumTexels: Size2i = Size2i(4),
231231
packing: LightMapPacker.Options = .none
232232
) {
233233
self.radiosity = radiosity
234234
self.occlusion = occlusion
235235
self.packing = packing
236-
self.minimumTexels = max(minimumTexels, 4)
236+
self.minimumTexels = max(minimumTexels, Size2i(4))
237237
}
238238
}
239239

0 commit comments

Comments
 (0)