Skip to content

Commit eae79b5

Browse files
committed
Move interpolation options into the function call
1 parent 14149cf commit eae79b5

File tree

8 files changed

+68
-91
lines changed

8 files changed

+68
-91
lines changed

Sources/GameMath/2D Types/Vector2.swift

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

174174
extension Vector2 {
175175
@inlinable
176-
public func interpolated<V: Vector2>(to: V, _ method: InterpolationMethod) -> Self {
176+
public func interpolated<V: Vector2>(to: V, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) -> Self {
177177
var copy = self
178-
copy.x.interpolate(to: to.x, method)
179-
copy.y.interpolate(to: to.y, method)
178+
copy.x.interpolate(to: to.x, method, options: options)
179+
copy.y.interpolate(to: to.y, method, options: options)
180180
return copy
181181
}
182182
@inlinable
183-
public mutating func interpolate<V: Vector2>(to: V, _ method: InterpolationMethod) {
184-
self.x.interpolate(to: to.x, method)
185-
self.y.interpolate(to: to.y, method)
183+
public mutating func interpolate<V: Vector2>(to: V, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) {
184+
self.x.interpolate(to: to.x, method, options: options)
185+
self.y.interpolate(to: to.y, method, options: options)
186186
}
187187
}
188188

Sources/GameMath/3D Types/Quaternion.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -419,29 +419,29 @@ public extension Quaternion {
419419

420420
public extension Quaternion {
421421
@inlinable
422-
func interpolated(to: Self, _ method: InterpolationMethod) -> Self {
422+
func interpolated(to: Self, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) -> Self {
423423
switch method {
424-
case let .linear(factor, options):
424+
case .linear(let factor):
425425
if options.contains(.shortest) {
426426
return self.slerped(to: to, factor: factor)
427427
}else{
428428
return self.lerped(to: to, factor: factor)
429429
}
430-
case let .easeIn(factor, options):
430+
case .easeIn(let factor):
431431
let easeInFactor = 1 - cos((factor * .pi) / 2)
432432
if options.contains(.shortest) {
433433
return self.slerped(to: to, factor: easeInFactor)
434434
}else{
435435
return self.lerped(to: to, factor: easeInFactor)
436436
}
437-
case let .easeOut(factor, options):
437+
case .easeOut(let factor):
438438
let easeOutFactor = sin((factor * .pi) / 2)
439439
if options.contains(.shortest) {
440440
return self.slerped(to: to, factor: easeOutFactor)
441441
}else{
442442
return self.lerped(to: to, factor: easeOutFactor)
443443
}
444-
case let .easeInOut(factor, options):
444+
case .easeInOut(let factor):
445445
let easeInOutFactor = -(cos(.pi * factor) - 1) / 2
446446
if options.contains(.shortest) {
447447
return self.slerped(to: to, factor: easeInOutFactor)
@@ -451,12 +451,9 @@ public extension Quaternion {
451451
}
452452
}
453453

454-
455-
//let easeInOutFactor = -(cos(.pi * factor) - 1) / 2
456-
457454
@inlinable
458-
mutating func interpolate(to: Self, _ method: InterpolationMethod) {
459-
self = self.interpolated(to: to, method)
455+
mutating func interpolate(to: Self, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) {
456+
self = self.interpolated(to: to, method, options: options)
460457
}
461458
}
462459

Sources/GameMath/3D Types/Transform3.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,17 @@ public extension Transform3 {
128128

129129
extension Transform3 {
130130
@inlinable
131-
public func interpolated(to destination: Self, _ method: InterpolationMethod) -> Self {
131+
public func interpolated(to destination: Self, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) -> Self {
132132
var copy = self
133-
copy.interpolate(to: destination, method)
133+
copy.interpolate(to: destination, method, options: options)
134134
return copy
135135
}
136136

137137
@inlinable
138-
public mutating func interpolate(to: Self, _ method: InterpolationMethod) {
139-
self.position.interpolate(to: to.position, method)
140-
self.rotation.interpolate(to: to.rotation, method)
141-
self.scale.interpolate(to: to.scale, method)
138+
public mutating func interpolate(to: Self, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) {
139+
self.position.interpolate(to: to.position, method, options: options)
140+
self.rotation.interpolate(to: to.rotation, method, options: options)
141+
self.scale.interpolate(to: to.scale, method, options: options)
142142
}
143143
}
144144

Sources/GameMath/3D Types/Vector3.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,18 +285,18 @@ extension Vector3 {
285285

286286
extension Vector3 {
287287
@inlinable
288-
public func interpolated<V: Vector3>(to: V, _ method: InterpolationMethod) -> Self {
288+
public func interpolated<V: Vector3>(to: V, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) -> Self {
289289
var copy = self
290-
copy.x.interpolate(to: to.x, method)
291-
copy.y.interpolate(to: to.y, method)
292-
copy.z.interpolate(to: to.z, method)
290+
copy.x.interpolate(to: to.x, method, options: options)
291+
copy.y.interpolate(to: to.y, method, options: options)
292+
copy.z.interpolate(to: to.z, method, options: options)
293293
return copy
294294
}
295295
@inlinable
296-
public mutating func interpolate<V: Vector3>(to: V, _ method: InterpolationMethod) {
297-
self.x.interpolate(to: to.x, method)
298-
self.y.interpolate(to: to.y, method)
299-
self.z.interpolate(to: to.z, method)
296+
public mutating func interpolate<V: Vector3>(to: V, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) {
297+
self.x.interpolate(to: to.x, method, options: options)
298+
self.y.interpolate(to: to.y, method, options: options)
299+
self.z.interpolate(to: to.z, method, options: options)
300300
}
301301
}
302302

Sources/GameMath/Degrees & Radians.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,13 @@ public struct Degrees: Angle, Hashable, Codable, Sendable {
601601

602602
public extension Degrees {
603603
@inlinable
604-
mutating func interpolate(to: Self, _ method: InterpolationMethod) {
604+
mutating func interpolate(to: Self, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) {
605605
self = self.interpolated(to: to, method)
606606
}
607607

608608
@inlinable
609-
func interpolated(to: Self, _ method: InterpolationMethod) -> Self {
610-
if case .linear(_, let options) = method, options.contains(.shortest) {
609+
func interpolated(to: Self, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) -> Self {
610+
if options.contains(.shortest) {
611611
// Shortest distance
612612
let shortest = self.shortestAngle(to: to)
613613
return Self(self.rawValue.interpolated(to: (self + shortest).rawValue, method))
@@ -616,13 +616,13 @@ public extension Degrees {
616616
}
617617

618618
@inlinable
619-
mutating func interpolate(to: Radians, _ method: InterpolationMethod) {
620-
self.interpolate(to: Self(to), method)
619+
mutating func interpolate(to: Radians, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) {
620+
self.interpolate(to: Self(to), method, options: options)
621621
}
622622

623623
@inlinable
624-
func interpolated(to: Radians, _ method: InterpolationMethod) -> Self {
625-
return self.interpolated(to: Self(to), method)
624+
func interpolated(to: Radians, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) -> Self {
625+
return self.interpolated(to: Self(to), method, options: options)
626626
}
627627

628628
@inlinable

Sources/GameMath/Interpolation.swift

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,62 +25,58 @@ public enum InterpolationMethod {
2525
Interpolates at a constant rate
2626

2727
- parameter factor: The progress of interpolation. 0 being the source and 1 being destination.
28-
- parameter options: Options for processing the interpolation.
2928
*/
30-
case linear(_ factor: Float, options: InterpolationOptions = [.shortest])
29+
case linear(_ factor: Float)
3130

3231
/**
3332
Interpolates with acceleration increasing near the destinartion
3433

3534
- parameter factor: The progress of interpolation. 0 being the source and 1 being destination.
36-
- parameter options: Options for processing the interpolation.
3735
*/
38-
case easeIn(_ factor: Float, options: InterpolationOptions = [.shortest])
36+
case easeIn(_ factor: Float)
3937

4038
/**
4139
Interpolates with acceleration increasing near the beginning
4240

4341
- parameter factor: The progress of interpolation. 0 being the source and 1 being destination.
44-
- parameter options: Options for processing the interpolation.
4542
*/
46-
case easeOut(_ factor: Float, options: InterpolationOptions = [.shortest])
43+
case easeOut(_ factor: Float)
4744

4845
/**
4946
Interpolates with acceleration increasing near the beginning, and then again at the end
5047

5148
- parameter factor: The progress of interpolation. 0 being the source and 1 being destination.
52-
- parameter options: Options for processing the interpolation.
5349
*/
54-
case easeInOut(_ factor: Float, options: InterpolationOptions = [.shortest])
50+
case easeInOut(_ factor: Float)
5551
}
5652

5753
public extension Float {
5854
/// Interpolates toward `to` by using `method `
5955
@inlinable
60-
func interpolated(to: Float, _ method: InterpolationMethod) -> Float {
56+
func interpolated(to: Float, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) -> Float {
6157
switch method {
62-
case let .linear(factor, _):
58+
case .linear(let factor):
6359
return self.lerped(to: to, factor: factor)
64-
case let .easeIn(factor, _):
60+
case .easeIn(let factor):
6561
return self.easedIn(to: to, factor: factor)
66-
case let .easeOut(factor, _):
62+
case .easeOut(let factor):
6763
return self.easedOut(to: to, factor: factor)
68-
case let .easeInOut(factor, _):
64+
case .easeInOut(let factor):
6965
return self.easedInOut(to: to, factor: factor)
7066
}
7167
}
7268

7369
/// Interpolates toward `to` by using `method `
7470
@inlinable
75-
mutating func interpolate(to: Float, _ method: InterpolationMethod) {
71+
mutating func interpolate(to: Float, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) {
7672
switch method {
77-
case let .linear(factor, _):
73+
case .linear(let factor):
7874
return self.lerp(to: to, factor: factor)
79-
case let .easeIn(factor, _):
75+
case .easeIn(let factor):
8076
return self.easeIn(to: to, factor: factor)
81-
case let .easeOut(factor, _):
77+
case .easeOut(let factor):
8278
return self.easeOut(to: to, factor: factor)
83-
case let .easeInOut(factor, _):
79+
case .easeInOut(let factor):
8480
return self.easeInOut(to: to, factor: factor)
8581
}
8682
}

Sources/GameMath/Vector4.swift

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,20 @@ extension Vector4 {
279279

280280
extension Vector4 {
281281
@inlinable
282-
public func interpolated(to: Self, _ method: InterpolationMethod) -> Self {
283-
return Self(self.x.interpolated(to: to.x, method),
284-
self.y.interpolated(to: to.y, method),
285-
self.z.interpolated(to: to.z, method),
286-
self.w.interpolated(to: to.w, method))
287-
}
288-
@inlinable
289-
public mutating func interpolate(to: Self, _ method: InterpolationMethod) {
290-
self.x.interpolate(to: to.x, method)
291-
self.y.interpolate(to: to.y, method)
292-
self.z.interpolate(to: to.z, method)
293-
self.w.interpolate(to: to.w, method)
282+
public func interpolated(to: Self, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) -> Self {
283+
return Self(
284+
self.x.interpolated(to: to.x, method, options: options),
285+
self.y.interpolated(to: to.y, method, options: options),
286+
self.z.interpolated(to: to.z, method, options: options),
287+
self.w.interpolated(to: to.w, method, options: options),
288+
)
289+
}
290+
@inlinable
291+
public mutating func interpolate(to: Self, _ method: InterpolationMethod, options: InterpolationOptions = .shortest) {
292+
self.x.interpolate(to: to.x, method, options: options)
293+
self.y.interpolate(to: to.y, method, options: options)
294+
self.z.interpolate(to: to.z, method, options: options)
295+
self.w.interpolate(to: to.w, method, options: options)
294296
}
295297
}
296298

Sources/GateEngine/Resources/Animation/ObjectAnimation3D.swift

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,7 @@ extension ObjectAnimation3D {
215215

216216
switch interpolation {
217217
case .linear:
218-
return position1.interpolated(
219-
to: position2,
220-
.linear(factor, options: [.shortest])
221-
)
218+
return position1.interpolated(to: position2, .linear(factor))
222219
case .step:
223220
if factor < 0.5 {
224221
return position1
@@ -243,10 +240,7 @@ extension ObjectAnimation3D {
243240

244241
switch interpolation {
245242
case .linear:
246-
return position1.interpolated(
247-
to: position2,
248-
.linear(factor, options: [.shortest])
249-
)
243+
return position1.interpolated(to: position2, .linear(factor))
250244
case .step:
251245
if factor < 0.5 {
252246
return position1
@@ -293,10 +287,7 @@ extension ObjectAnimation3D {
293287

294288
switch interpolation {
295289
case .linear:
296-
return rotation1.interpolated(
297-
to: rotation2,
298-
.linear(factor, options: [.shortest])
299-
)
290+
return rotation1.interpolated(to: rotation2, .linear(factor))
300291
case .step:
301292
if factor < 0.5 {
302293
return rotation1
@@ -321,10 +312,7 @@ extension ObjectAnimation3D {
321312

322313
switch interpolation {
323314
case .linear:
324-
return rotation1.interpolated(
325-
to: rotation2,
326-
.linear(factor, options: [.shortest])
327-
)
315+
return rotation1.interpolated(to: rotation2, .linear(factor))
328316
case .step:
329317
if factor < 0.5 {
330318
return rotation1
@@ -368,10 +356,7 @@ extension ObjectAnimation3D {
368356

369357
switch interpolation {
370358
case .linear:
371-
return scale1.interpolated(
372-
to: scale2,
373-
.linear(factor, options: [.shortest])
374-
)
359+
return scale1.interpolated(to: scale2, .linear(factor))
375360
case .step:
376361
if factor < 0.5 {
377362
return scale1
@@ -396,10 +381,7 @@ extension ObjectAnimation3D {
396381

397382
switch interpolation {
398383
case .linear:
399-
return scale1.interpolated(
400-
to: scale2,
401-
.linear(factor, options: [.shortest])
402-
)
384+
return scale1.interpolated(to: scale2, .linear(factor))
403385
case .step:
404386
if factor < 0.5 {
405387
return scale1

0 commit comments

Comments
 (0)