Skip to content

Commit 5e7afb5

Browse files
committed
Continue new GameMath implementation
1 parent e0e78e1 commit 5e7afb5

File tree

18 files changed

+984
-375
lines changed

18 files changed

+984
-375
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public protocol Vector2n<Scalar> {
1010
associatedtype Scalar: ScalarType
1111
associatedtype Vector2Counterpart: GameMath.Vector2
1212

13-
var x: Scalar {get set}
14-
var y: Scalar {get set}
13+
var x: Scalar {get mutating set}
14+
var y: Scalar {get mutating set}
1515
init(x: Scalar, y: Scalar)
1616
}
1717

Sources/GameMath/2D Types/Rect.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ public extension Rect {
127127

128128
public extension Rect {
129129
@inlinable
130-
func interpolated(to: Self, _ method: InterpolationMethod) -> Self {
130+
func interpolated(to: Self, _ method: InterpolationMethod<Float>) -> Self {
131131
var copy = self
132132
copy.interpolate(to: to, method)
133133
return copy
134134
}
135135
@inlinable
136-
mutating func interpolate(to: Self, _ method: InterpolationMethod) {
136+
mutating func interpolate(to: Self, _ method: InterpolationMethod<Float>) {
137137
self.position.interpolate(to: to.position, method)
138138
self.size.interpolate(to: to.size, method)
139139
}

Sources/GameMath/2D Types/Transform2.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ extension Transform2 {
113113

114114
extension Transform2 {
115115
@inlinable
116-
public func interpolated(to destination: Self, _ method: InterpolationMethod) -> Self {
116+
public func interpolated(to destination: Self, _ method: InterpolationMethod<Float>) -> Self {
117117
var copy = self
118118
copy.interpolate(to: destination, method)
119119
return copy
120120
}
121121

122122
@inlinable
123-
public mutating func interpolate(to: Self, _ method: InterpolationMethod) {
123+
public mutating func interpolate(to: Self, _ method: InterpolationMethod<Float>) {
124124
self.position.interpolate(to: to.position, method)
125125
self.rotation.interpolate(to: to.rotation, method)
126126
self.scale.interpolate(to: to.scale, method)

Sources/GameMath/2D Types/Vector2.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ extension Vector2 {
173173

174174
extension Vector2 {
175175
@inlinable
176-
public func interpolated(to: Self, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) -> Self {
176+
public func interpolated(to: Self, _ method: InterpolationMethod<Float>, options: InterpolationOptions = .shortest) -> Self {
177177
var copy = self
178178
copy.x.interpolate(to: to.x, method, options: options)
179179
copy.y.interpolate(to: to.y, method, options: options)
180180
return copy
181181
}
182182
@inlinable
183-
public mutating func interpolate(to: Self, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) {
183+
public mutating func interpolate(to: Self, _ method: InterpolationMethod<Float>, options: InterpolationOptions = .shortest) {
184184
self.x.interpolate(to: to.x, method, options: options)
185185
self.y.interpolate(to: to.y, method, options: options)
186186
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright © 2025 Dustin Collins (Strega's Gate)
3+
* All Rights Reserved.
4+
*
5+
* http://stregasgate.com
6+
*/
7+
8+
#if GameMathUseSIMD && canImport(Accelerate)
9+
public import Accelerate
10+
11+
/// A structure for tranparently working with the Accelerate framework
12+
@usableFromInline
13+
@frozen
14+
internal struct Vector3nAccelerateBuffer<Scalar: Vector3n.ScalarType>: AccelerateBuffer, AccelerateMutableBuffer {
15+
public typealias Element = Scalar
16+
17+
var x: Scalar
18+
var y: Scalar
19+
var z: Scalar
20+
var _pad: Scalar
21+
22+
init(x: Scalar, y: Scalar, z: Scalar) {
23+
self.x = x
24+
self.y = y
25+
self.z = z
26+
self._pad = 0
27+
}
28+
29+
@inlinable
30+
var count: Int {
31+
return 3
32+
}
33+
34+
@inlinable
35+
func withUnsafeBufferPointer<R>(_ body: (UnsafeBufferPointer<Scalar>) throws -> R) rethrows -> R {
36+
try Swift.withUnsafeBytes(of: self) { buffer in
37+
let buffer = UnsafeBufferPointer(start: buffer.baseAddress!.assumingMemoryBound(to: Scalar.self), count: 3)
38+
return try body(buffer)
39+
}
40+
}
41+
42+
@inlinable
43+
mutating func withUnsafeMutableBufferPointer<R>(_ body: (inout UnsafeMutableBufferPointer<Scalar>) throws -> R) rethrows -> R {
44+
try Swift.withUnsafeMutableBytes(of: &self) { buffer in
45+
var buffer = UnsafeMutableBufferPointer(start: buffer.baseAddress!.assumingMemoryBound(to: Scalar.self), count: 3)
46+
return try body(&buffer)
47+
}
48+
}
49+
}
50+
51+
#endif

0 commit comments

Comments
 (0)