Skip to content

Commit e2445b6

Browse files
committed
Use init for Position2 cast
Position2 can be backed by SIMD, and is not guaranteed to have the same memory layout. So unsafeBitCast is, unsafe.
1 parent ada0ab1 commit e2445b6

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Sources/GameMath/3D Types/TextureCoordinate.swift

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,23 @@ public struct TextureCoordinate: Vector2, Equatable, Hashable, Codable, Sendable
1010
public var y: Float
1111

1212
@inlinable
13-
public var u: Float {get{x}set{x = newValue}}
13+
public var u: Float {
14+
get {
15+
return x
16+
}
17+
set {
18+
x = newValue
19+
}
20+
}
1421
@inlinable
15-
public var v: Float {get{y}set{y = newValue}}
22+
public var v: Float {
23+
get {
24+
return y
25+
}
26+
set {
27+
y = newValue
28+
}
29+
}
1630

1731
public init(x: Float, y: Float) {
1832
self.x = x
@@ -23,8 +37,8 @@ public struct TextureCoordinate: Vector2, Equatable, Hashable, Codable, Sendable
2337
public extension TextureCoordinate {
2438
@inlinable
2539
func distance(from: Self) -> Float {
26-
let p1 = unsafeBitCast(self, to: Position2.self)
27-
let p2 = unsafeBitCast(from, to: Position2.self)
40+
let p1 = Position2(self.x, self.y)
41+
let p2 = Position2(from.x, from.y)
2842
return p1.distance(from: p2)
2943
}
3044
}

0 commit comments

Comments
 (0)