Skip to content

Commit 2903946

Browse files
committed
Enable web support
1 parent 034d901 commit 2903946

File tree

9 files changed

+63
-21
lines changed

9 files changed

+63
-21
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,5 @@ fastlane/screenshots
6767
fastlane/test_output
6868

6969
SwiftMath.xcodeproj/
70+
71+
.vscode

.swift-format

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": 1,
3+
"lineLength": 100,
4+
"indentation": {
5+
"spaces": 4
6+
},
7+
"maximumBlankLines": 1,
8+
"respectsExistingLineBreaks": true,
9+
"lineBreakBeforeControlFlowKeywords": false,
10+
"lineBreakBeforeEachArgument": true
11+
}

Sources/Matrix3x3+nosimd.swift

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#if NOSIMD
1010
@frozen
11-
public struct Matrix3x3f {
11+
public struct Matrix3x3f: Hashable {
1212
public var m11: Float = 0.0
1313
public var m12: Float = 0.0
1414
public var m13: Float = 0.0
@@ -203,19 +203,4 @@ public struct Matrix3x3f {
203203
}
204204

205205
}
206-
207-
extension Matrix3x3f: Equatable {
208-
public static func ==(lhs: Matrix3x3f, rhs: Matrix3x3f) -> Bool {
209-
if lhs.m11 != rhs.m11 { return false }
210-
if lhs.m12 != rhs.m12 { return false }
211-
if lhs.m13 != rhs.m13 { return false }
212-
if lhs.m21 != rhs.m21 { return false }
213-
if lhs.m22 != rhs.m22 { return false }
214-
if lhs.m23 != rhs.m23 { return false }
215-
if lhs.m31 != rhs.m31 { return false }
216-
if lhs.m32 != rhs.m32 { return false }
217-
if lhs.m33 != rhs.m33 { return false }
218-
return true
219-
}
220-
}
221206
#endif

Sources/Vector2+nosimd.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
import Darwin
1313
#elseif os(Linux) || os(Android)
1414
import Glibc
15+
#elseif canImport(WASILibc)
16+
import WASILibc
1517
#endif
1618

1719
@frozen
18-
public struct Vector2f {
20+
public struct Vector2f: Hashable {
1921
public var x: Float = 0.0
2022
public var y: Float = 0.0
2123

Sources/Vector3+nosimd.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
#if NOSIMD
1010

1111
#if (os(OSX) || os(iOS) || os(tvOS) || os(watchOS))
12-
import Darwin
12+
import Darwin
1313
#elseif os(Linux) || os(Android)
14-
import Glibc
14+
import Glibc
15+
#elseif canImport(WASILibc)
16+
import WASILibc
1517
#endif
1618

1719
@frozen
18-
public struct Vector3f {
20+
public struct Vector3f: Hashable {
1921
public var x: Float = 0.0
2022
public var y: Float = 0.0
2123
public var z: Float = 0.0

Sources/Vector4+nosimd.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import Darwin
1212
#elseif os(Linux) || os(Android)
1313
import Glibc
14+
#elseif canImport(WASILibc)
15+
import WASILibc
1416
#endif
1517

1618
@frozen
17-
public struct Vector4f {
19+
public struct Vector4f: Hashable {
1820
public var x: Float = 0.0
1921
public var y: Float = 0.0
2022
public var z: Float = 0.0

Sources/easing.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import Darwin
1111
#elseif os(Linux) || os(Android)
1212
import Glibc
13+
#elseif canImport(WASILibc)
14+
import WASILibc
1315
#endif
1416

1517
// MARK: Linear

Sources/platform.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,31 @@ internal func __tanpif(_ a: Float) -> Float {
8989

9090
import Darwin
9191

92+
#elseif canImport(WASILibc)
93+
94+
import WASILibc
95+
96+
@inline(__always)
97+
internal func __sincospif(_ a: Float, _ sina: inout Float, _ cosa: inout Float) {
98+
sina = sin(a * Float.pi)
99+
cosa = cos(a * Float.pi)
100+
}
101+
102+
@inline(__always)
103+
internal func __sinpif(_ a: Float) -> Float {
104+
return sin(a * Float.pi)
105+
}
106+
107+
@inline(__always)
108+
internal func __cospif(_ a: Float) -> Float {
109+
return cos(a * Float.pi)
110+
}
111+
112+
@inline(__always)
113+
internal func __tanpif(_ a: Float) -> Float {
114+
return tan(a * Float.pi)
115+
}
116+
92117
#endif
93118

94119
public func sincos(_ a: Angle, _ sina: inout Float, _ cosa: inout Float) {

Sources/random.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ internal func arc4random() -> UInt32 {
3131
internal func arc4random_uniform(_ val: UInt32) -> UInt32 {
3232
return UInt32.random(in: 0...val)
3333
}
34+
35+
#elseif canImport(WASILibc)
36+
import WASILibc
37+
38+
internal func arc4random() -> UInt32 {
39+
return UInt32(random())
40+
}
41+
42+
internal func arc4random_uniform(_ val: UInt32) -> UInt32 {
43+
return UInt32(random()) % val
44+
}
3445
#endif
3546

3647
// each type has its own random

0 commit comments

Comments
 (0)