Skip to content

Commit 6008d56

Browse files
authored
Merge pull request #3 from fireblade-engine/feature/size-extensions
Size & Point extensions
2 parents caa8125 + b03808c commit 6008d56

File tree

7 files changed

+125
-73
lines changed

7 files changed

+125
-73
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: macOS-latest
1212
strategy:
1313
matrix:
14-
xcode: ["11.7", "12"]
14+
xcode: ["11.7", "12.1"]
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@master
@@ -52,14 +52,14 @@ jobs:
5252
run: swift build -c release
5353

5454

55-
webAssembly:
56-
runs-on: ubuntu-20.04
57-
steps:
58-
- name: Checkout
59-
uses: actions/checkout@master
60-
- name: Swift version
61-
run: swift --version
62-
- name: Build
63-
uses: swiftwasm/swiftwasm-action@v5.3
64-
with:
65-
shell-action: carton test
55+
# webAssembly:
56+
# runs-on: ubuntu-20.04
57+
# steps:
58+
# - name: Checkout
59+
# uses: actions/checkout@master
60+
# - name: Swift version
61+
# run: swift --version
62+
# - name: Build
63+
# uses: swiftwasm/swiftwasm-action@main
64+
# with:
65+
# shell-action: carton test

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![github CI](https://github.com/fireblade-engine/math/workflows/CI/badge.svg)](https://github.com/fireblade-engine/math/actions?query=workflow%3ACI)
55
[![swift-version-compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ffireblade-engine%2Fmath%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/fireblade-engine/math)
66
[![platform-compatilibilty](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ffireblade-engine%2Fmath%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/fireblade-engine/math)
7-
[![platform-webassembly](https://img.shields.io/badge/Platform-WebAssembly-blue.svg)](https://github.com/swiftwasm/swift#swiftwasm)
7+
<!--[![platform-webassembly](https://img.shields.io/badge/Platform-WebAssembly-blue.svg)](https://github.com/swiftwasm/swift#swiftwasm)-->
88

99

1010
A dependency free, lightweight, fast math library for 2D and 3D vectors, quaternions and matrices in Swift with (optional) SIMD support. It is developed and maintained as part of the [Fireblade Game Engine project](https://github.com/fireblade-engine).

Sources/FirebladeMath/Functions/determinant.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ public func determinant(_ mat: Mat4x4f) -> Float {
1313
#if FRB_MATH_USE_SIMD
1414
return simd.simd_determinant(mat.storage)
1515
#else
16-
return mat[0, 0]*mat[1, 1]*mat[2, 2]*mat[3, 3] - mat[1, 0]*mat[0, 1]*mat[2, 2]*mat[3, 3] + mat[0, 2]*mat[0, 1]*mat[1, 2]*mat[3, 3]
17-
- mat[0, 0]*mat[2, 1]*mat[1, 2]*mat[3, 3] + mat[1, 0]*mat[2, 1]*mat[0, 2]*mat[3, 3] - mat[0, 2]*mat[1, 1]*mat[0, 2]*mat[3, 3]
18-
+ mat[0, 2]*mat[1, 1]*mat[3, 2]*mat[0, 3] - mat[1, 0]*mat[2, 1]*mat[3, 2]*mat[0, 3] + mat[3, 0]*mat[2, 1]*mat[1, 2]*mat[0, 3]
19-
- mat[0, 2]*mat[3, 1]*mat[1, 2]*mat[0, 3] + mat[1, 0]*mat[3, 1]*mat[2, 2]*mat[0, 3] - mat[3, 0]*mat[1, 1]*mat[2, 2]*mat[0, 3]
20-
+ mat[3, 0]*mat[0, 1]*mat[2, 2]*mat[1, 3] - mat[0, 0]*mat[3, 1]*mat[2, 2]*mat[1, 3] + mat[0, 2]*mat[3, 1]*mat[0, 2]*mat[1, 3]
21-
- mat[3, 0]*mat[2, 1]*mat[0, 2]*mat[1, 3] + mat[0, 0]*mat[2, 1]*mat[3, 2]*mat[1, 3] - mat[0, 2]*mat[0, 1]*mat[3, 2]*mat[1, 3]
22-
+ mat[1, 0]*mat[0, 1]*mat[3, 2]*mat[2, 3] - mat[0, 0]*mat[1, 1]*mat[3, 2]*mat[2, 3] + mat[3, 0]*mat[1, 1]*mat[0, 2]*mat[2, 3]
23-
- mat[1, 0]*mat[3, 1]*mat[0, 2]*mat[2, 3] + mat[0, 0]*mat[3, 1]*mat[1, 2]*mat[2, 3] - mat[3, 0]*mat[0, 1]*mat[1, 2]*mat[2, 3]
16+
return mat[0, 0] * mat[1, 1] * mat[2, 2] * mat[3, 3] - mat[1, 0] * mat[0, 1] * mat[2, 2] * mat[3, 3] + mat[0, 2] * mat[0, 1] * mat[1, 2] * mat[3, 3]
17+
- mat[0, 0] * mat[2, 1] * mat[1, 2] * mat[3, 3] + mat[1, 0] * mat[2, 1] * mat[0, 2] * mat[3, 3] - mat[0, 2] * mat[1, 1] * mat[0, 2] * mat[3, 3]
18+
+ mat[0, 2] * mat[1, 1] * mat[3, 2] * mat[0, 3] - mat[1, 0] * mat[2, 1] * mat[3, 2] * mat[0, 3] + mat[3, 0] * mat[2, 1] * mat[1, 2] * mat[0, 3]
19+
- mat[0, 2] * mat[3, 1] * mat[1, 2] * mat[0, 3] + mat[1, 0] * mat[3, 1] * mat[2, 2] * mat[0, 3] - mat[3, 0] * mat[1, 1] * mat[2, 2] * mat[0, 3]
20+
+ mat[3, 0] * mat[0, 1] * mat[2, 2] * mat[1, 3] - mat[0, 0] * mat[3, 1] * mat[2, 2] * mat[1, 3] + mat[0, 2] * mat[3, 1] * mat[0, 2] * mat[1, 3]
21+
- mat[3, 0] * mat[2, 1] * mat[0, 2] * mat[1, 3] + mat[0, 0] * mat[2, 1] * mat[3, 2] * mat[1, 3] - mat[0, 2] * mat[0, 1] * mat[3, 2] * mat[1, 3]
22+
+ mat[1, 0] * mat[0, 1] * mat[3, 2] * mat[2, 3] - mat[0, 0] * mat[1, 1] * mat[3, 2] * mat[2, 3] + mat[3, 0] * mat[1, 1] * mat[0, 2] * mat[2, 3]
23+
- mat[1, 0] * mat[3, 1] * mat[0, 2] * mat[2, 3] + mat[0, 0] * mat[3, 1] * mat[1, 2] * mat[2, 3] - mat[3, 0] * mat[0, 1] * mat[1, 2] * mat[2, 3]
2424
#endif
2525
}
2626

@@ -37,14 +37,14 @@ public func determinant(_ mat: Mat4x4d) -> Double {
3737
#if FRB_MATH_USE_SIMD
3838
return simd.simd_determinant(mat.storage)
3939
#else
40-
return mat[0, 0]*mat[1, 1]*mat[2, 2]*mat[3, 3] - mat[1, 0]*mat[0, 1]*mat[2, 2]*mat[3, 3] + mat[0, 2]*mat[0, 1]*mat[1, 2]*mat[3, 3]
41-
- mat[0, 0]*mat[2, 1]*mat[1, 2]*mat[3, 3] + mat[1, 0]*mat[2, 1]*mat[0, 2]*mat[3, 3] - mat[0, 2]*mat[1, 1]*mat[0, 2]*mat[3, 3]
42-
+ mat[0, 2]*mat[1, 1]*mat[3, 2]*mat[0, 3] - mat[1, 0]*mat[2, 1]*mat[3, 2]*mat[0, 3] + mat[3, 0]*mat[2, 1]*mat[1, 2]*mat[0, 3]
43-
- mat[0, 2]*mat[3, 1]*mat[1, 2]*mat[0, 3] + mat[1, 0]*mat[3, 1]*mat[2, 2]*mat[0, 3] - mat[3, 0]*mat[1, 1]*mat[2, 2]*mat[0, 3]
44-
+ mat[3, 0]*mat[0, 1]*mat[2, 2]*mat[1, 3] - mat[0, 0]*mat[3, 1]*mat[2, 2]*mat[1, 3] + mat[0, 2]*mat[3, 1]*mat[0, 2]*mat[1, 3]
45-
- mat[3, 0]*mat[2, 1]*mat[0, 2]*mat[1, 3] + mat[0, 0]*mat[2, 1]*mat[3, 2]*mat[1, 3] - mat[0, 2]*mat[0, 1]*mat[3, 2]*mat[1, 3]
46-
+ mat[1, 0]*mat[0, 1]*mat[3, 2]*mat[2, 3] - mat[0, 0]*mat[1, 1]*mat[3, 2]*mat[2, 3] + mat[3, 0]*mat[1, 1]*mat[0, 2]*mat[2, 3]
47-
- mat[1, 0]*mat[3, 1]*mat[0, 2]*mat[2, 3] + mat[0, 0]*mat[3, 1]*mat[1, 2]*mat[2, 3] - mat[3, 0]*mat[0, 1]*mat[1, 2]*mat[2, 3]
40+
return mat[0, 0] * mat[1, 1] * mat[2, 2] * mat[3, 3] - mat[1, 0] * mat[0, 1] * mat[2, 2] * mat[3, 3] + mat[0, 2] * mat[0, 1] * mat[1, 2] * mat[3, 3]
41+
- mat[0, 0] * mat[2, 1] * mat[1, 2] * mat[3, 3] + mat[1, 0] * mat[2, 1] * mat[0, 2] * mat[3, 3] - mat[0, 2] * mat[1, 1] * mat[0, 2] * mat[3, 3]
42+
+ mat[0, 2] * mat[1, 1] * mat[3, 2] * mat[0, 3] - mat[1, 0] * mat[2, 1] * mat[3, 2] * mat[0, 3] + mat[3, 0] * mat[2, 1] * mat[1, 2] * mat[0, 3]
43+
- mat[0, 2] * mat[3, 1] * mat[1, 2] * mat[0, 3] + mat[1, 0] * mat[3, 1] * mat[2, 2] * mat[0, 3] - mat[3, 0] * mat[1, 1] * mat[2, 2] * mat[0, 3]
44+
+ mat[3, 0] * mat[0, 1] * mat[2, 2] * mat[1, 3] - mat[0, 0] * mat[3, 1] * mat[2, 2] * mat[1, 3] + mat[0, 2] * mat[3, 1] * mat[0, 2] * mat[1, 3]
45+
- mat[3, 0] * mat[2, 1] * mat[0, 2] * mat[1, 3] + mat[0, 0] * mat[2, 1] * mat[3, 2] * mat[1, 3] - mat[0, 2] * mat[0, 1] * mat[3, 2] * mat[1, 3]
46+
+ mat[1, 0] * mat[0, 1] * mat[3, 2] * mat[2, 3] - mat[0, 0] * mat[1, 1] * mat[3, 2] * mat[2, 3] + mat[3, 0] * mat[1, 1] * mat[0, 2] * mat[2, 3]
47+
- mat[1, 0] * mat[3, 1] * mat[0, 2] * mat[2, 3] + mat[0, 0] * mat[3, 1] * mat[1, 2] * mat[2, 3] - mat[3, 0] * mat[0, 1] * mat[1, 2] * mat[2, 3]
4848
#endif
4949
}
5050

Sources/FirebladeMath/Matrix/Matrix+Multiplication.swift

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@ public func multiply(_ lhs: Mat4x4d, _ rhs: Mat4x4d) -> Mat4x4d {
1717
#else
1818
return Mat4x4d(
1919
Vec4d(
20-
lhs[0] * rhs[0] + lhs[4] * rhs[1] + lhs[8] * rhs[2] + lhs[12] * rhs[3],
21-
lhs[1] * rhs[0] + lhs[5] * rhs[1] + lhs[9] * rhs[2] + lhs[13] * rhs[3],
22-
lhs[2] * rhs[0] + lhs[6] * rhs[1] + lhs[10] * rhs[2] + lhs[14] * rhs[3],
23-
lhs[3] * rhs[0] + lhs[7] * rhs[1] + lhs[11] * rhs[2] + lhs[15] * rhs[3]
20+
lhs[0] * rhs[0] + lhs[4] * rhs[1] + lhs[8] * rhs[2] + lhs[12] * rhs[3],
21+
lhs[1] * rhs[0] + lhs[5] * rhs[1] + lhs[9] * rhs[2] + lhs[13] * rhs[3],
22+
lhs[2] * rhs[0] + lhs[6] * rhs[1] + lhs[10] * rhs[2] + lhs[14] * rhs[3],
23+
lhs[3] * rhs[0] + lhs[7] * rhs[1] + lhs[11] * rhs[2] + lhs[15] * rhs[3]
2424
),
2525
Vec4d(
26-
lhs[0] * rhs[4] + lhs[4] * rhs[5] + lhs[8] * rhs[6] + lhs[12] * rhs[7],
27-
lhs[1] * rhs[4] + lhs[5] * rhs[5] + lhs[9] * rhs[6] + lhs[13] * rhs[7],
28-
lhs[2] * rhs[4] + lhs[6] * rhs[5] + lhs[10] * rhs[6] + lhs[14] * rhs[7],
29-
lhs[3] * rhs[4] + lhs[7] * rhs[5] + lhs[11] * rhs[6] + lhs[15] * rhs[7]
26+
lhs[0] * rhs[4] + lhs[4] * rhs[5] + lhs[8] * rhs[6] + lhs[12] * rhs[7],
27+
lhs[1] * rhs[4] + lhs[5] * rhs[5] + lhs[9] * rhs[6] + lhs[13] * rhs[7],
28+
lhs[2] * rhs[4] + lhs[6] * rhs[5] + lhs[10] * rhs[6] + lhs[14] * rhs[7],
29+
lhs[3] * rhs[4] + lhs[7] * rhs[5] + lhs[11] * rhs[6] + lhs[15] * rhs[7]
3030
),
3131
Vec4d(
32-
lhs[0] * rhs[8] + lhs[4] * rhs[9] + lhs[8] * rhs[10] + lhs[12] * rhs[11],
33-
lhs[1] * rhs[8] + lhs[5] * rhs[9] + lhs[9] * rhs[10] + lhs[13] * rhs[11],
34-
lhs[2] * rhs[8] + lhs[6] * rhs[9] + lhs[10] * rhs[10] + lhs[14] * rhs[11],
35-
lhs[3] * rhs[8] + lhs[7] * rhs[9] + lhs[11] * rhs[10] + lhs[15] * rhs[11]
32+
lhs[0] * rhs[8] + lhs[4] * rhs[9] + lhs[8] * rhs[10] + lhs[12] * rhs[11],
33+
lhs[1] * rhs[8] + lhs[5] * rhs[9] + lhs[9] * rhs[10] + lhs[13] * rhs[11],
34+
lhs[2] * rhs[8] + lhs[6] * rhs[9] + lhs[10] * rhs[10] + lhs[14] * rhs[11],
35+
lhs[3] * rhs[8] + lhs[7] * rhs[9] + lhs[11] * rhs[10] + lhs[15] * rhs[11]
3636
),
3737
Vec4d(
38-
lhs[0] * rhs[12] + lhs[4] * rhs[13] + lhs[8] * rhs[14] + lhs[12] * rhs[15],
39-
lhs[1] * rhs[12] + lhs[5] * rhs[13] + lhs[9] * rhs[14] + lhs[13] * rhs[15],
38+
lhs[0] * rhs[12] + lhs[4] * rhs[13] + lhs[8] * rhs[14] + lhs[12] * rhs[15],
39+
lhs[1] * rhs[12] + lhs[5] * rhs[13] + lhs[9] * rhs[14] + lhs[13] * rhs[15],
4040
lhs[2] * rhs[12] + lhs[6] * rhs[13] + lhs[10] * rhs[14] + lhs[14] * rhs[15],
4141
lhs[3] * rhs[12] + lhs[7] * rhs[13] + lhs[11] * rhs[14] + lhs[15] * rhs[15]
4242
)
@@ -87,26 +87,26 @@ public func multiply(_ lhs: Mat4x4f, _ rhs: Mat4x4f) -> Mat4x4f {
8787
#else
8888
return Mat4x4f(
8989
Vec4f(
90-
lhs[0] * rhs[0] + lhs[4] * rhs[1] + lhs[8] * rhs[2] + lhs[12] * rhs[3],
91-
lhs[1] * rhs[0] + lhs[5] * rhs[1] + lhs[9] * rhs[2] + lhs[13] * rhs[3],
92-
lhs[2] * rhs[0] + lhs[6] * rhs[1] + lhs[10] * rhs[2] + lhs[14] * rhs[3],
93-
lhs[3] * rhs[0] + lhs[7] * rhs[1] + lhs[11] * rhs[2] + lhs[15] * rhs[3]
90+
lhs[0] * rhs[0] + lhs[4] * rhs[1] + lhs[8] * rhs[2] + lhs[12] * rhs[3],
91+
lhs[1] * rhs[0] + lhs[5] * rhs[1] + lhs[9] * rhs[2] + lhs[13] * rhs[3],
92+
lhs[2] * rhs[0] + lhs[6] * rhs[1] + lhs[10] * rhs[2] + lhs[14] * rhs[3],
93+
lhs[3] * rhs[0] + lhs[7] * rhs[1] + lhs[11] * rhs[2] + lhs[15] * rhs[3]
9494
),
9595
Vec4f(
96-
lhs[0] * rhs[4] + lhs[4] * rhs[5] + lhs[8] * rhs[6] + lhs[12] * rhs[7],
97-
lhs[1] * rhs[4] + lhs[5] * rhs[5] + lhs[9] * rhs[6] + lhs[13] * rhs[7],
98-
lhs[2] * rhs[4] + lhs[6] * rhs[5] + lhs[10] * rhs[6] + lhs[14] * rhs[7],
99-
lhs[3] * rhs[4] + lhs[7] * rhs[5] + lhs[11] * rhs[6] + lhs[15] * rhs[7]
96+
lhs[0] * rhs[4] + lhs[4] * rhs[5] + lhs[8] * rhs[6] + lhs[12] * rhs[7],
97+
lhs[1] * rhs[4] + lhs[5] * rhs[5] + lhs[9] * rhs[6] + lhs[13] * rhs[7],
98+
lhs[2] * rhs[4] + lhs[6] * rhs[5] + lhs[10] * rhs[6] + lhs[14] * rhs[7],
99+
lhs[3] * rhs[4] + lhs[7] * rhs[5] + lhs[11] * rhs[6] + lhs[15] * rhs[7]
100100
),
101101
Vec4f(
102-
lhs[0] * rhs[8] + lhs[4] * rhs[9] + lhs[8] * rhs[10] + lhs[12] * rhs[11],
103-
lhs[1] * rhs[8] + lhs[5] * rhs[9] + lhs[9] * rhs[10] + lhs[13] * rhs[11],
104-
lhs[2] * rhs[8] + lhs[6] * rhs[9] + lhs[10] * rhs[10] + lhs[14] * rhs[11],
105-
lhs[3] * rhs[8] + lhs[7] * rhs[9] + lhs[11] * rhs[10] + lhs[15] * rhs[11]
102+
lhs[0] * rhs[8] + lhs[4] * rhs[9] + lhs[8] * rhs[10] + lhs[12] * rhs[11],
103+
lhs[1] * rhs[8] + lhs[5] * rhs[9] + lhs[9] * rhs[10] + lhs[13] * rhs[11],
104+
lhs[2] * rhs[8] + lhs[6] * rhs[9] + lhs[10] * rhs[10] + lhs[14] * rhs[11],
105+
lhs[3] * rhs[8] + lhs[7] * rhs[9] + lhs[11] * rhs[10] + lhs[15] * rhs[11]
106106
),
107107
Vec4f(
108-
lhs[0] * rhs[12] + lhs[4] * rhs[13] + lhs[8] * rhs[14] + lhs[12] * rhs[15],
109-
lhs[1] * rhs[12] + lhs[5] * rhs[13] + lhs[9] * rhs[14] + lhs[13] * rhs[15],
108+
lhs[0] * rhs[12] + lhs[4] * rhs[13] + lhs[8] * rhs[14] + lhs[12] * rhs[15],
109+
lhs[1] * rhs[12] + lhs[5] * rhs[13] + lhs[9] * rhs[14] + lhs[13] * rhs[15],
110110
lhs[2] * rhs[12] + lhs[6] * rhs[13] + lhs[10] * rhs[14] + lhs[14] * rhs[15],
111111
lhs[3] * rhs[12] + lhs[7] * rhs[13] + lhs[11] * rhs[14] + lhs[15] * rhs[15]
112112
)

Sources/FirebladeMath/Point.swift

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,53 @@ extension Point {
2222
}
2323
}
2424

25+
extension Point: Equatable where Value: Equatable { }
26+
extension Point: Hashable where Value: Hashable { }
27+
extension Point: Codable where Value: Codable { }
28+
2529
extension Point where Value == Float {
2630
public init(_ vector: Vec2f) {
2731
self.init(x: vector.x, y: vector.y)
2832
}
2933
}
3034

35+
extension Vec2f {
36+
public init(_ point: Point<Float>) {
37+
self.init(x: point.x, y: point.y)
38+
}
39+
}
40+
3141
extension Point where Value == Int {
3242
public init(_ vector: Vec2i) {
3343
self.init(x: vector.x, y: vector.y)
3444
}
3545
}
3646

47+
extension Vec2i {
48+
public init(_ point: Point<Int>) {
49+
self.init(x: point.x, y: point.y)
50+
}
51+
}
52+
3753
extension Point where Value == Double {
3854
public init(_ vector: Vec2d) {
3955
self.init(x: vector.x, y: vector.y)
4056
}
4157
}
58+
extension Vec2d {
59+
public init(_ point: Point<Double>) {
60+
self.init(x: point.x, y: point.y)
61+
}
62+
}
4263

4364
extension Point where Value == UInt {
4465
public init(_ vector: Vec2u) {
4566
self.init(x: vector.x, y: vector.y)
4667
}
4768
}
4869

49-
extension Point: Equatable where Value: Equatable { }
50-
extension Point: Hashable where Value: Hashable { }
51-
extension Point: Codable where Value: Codable { }
52-
53-
extension Vec2f {
54-
public init(_ point: Point<Float>) {
70+
extension Vec2u {
71+
public init(_ point: Point<UInt>) {
5572
self.init(x: point.x, y: point.y)
5673
}
5774
}

Sources/FirebladeMath/Size.swift

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@
99
public struct Size<Value> where Value: Numeric {
1010
public var width: Value
1111
public var height: Value
12+
13+
public init(width: Value, height: Value) {
14+
self.width = width
15+
self.height = height
16+
}
17+
}
18+
19+
extension Size {
20+
public init(_ width: Value, _ height: Value) {
21+
self.init(width: width, height: height)
22+
}
23+
}
24+
25+
extension Size: Equatable where Value: Equatable { }
26+
extension Size: Hashable where Value: Hashable { }
27+
extension Size: Codable where Value: Codable { }
28+
29+
extension Size where Value: FloatingPoint & ExpressibleByFloatLiteral {
30+
public var center: Point<Value> {
31+
Point(x: width * 0.5, y: height * 0.5)
32+
}
1233
}
1334

1435
extension Size where Value == Float {
@@ -17,30 +38,44 @@ extension Size where Value == Float {
1738
}
1839
}
1940

41+
extension Vec2f {
42+
public init(_ size: Size<Float>) {
43+
self.init(x: size.width, y: size.height)
44+
}
45+
}
46+
2047
extension Size where Value == Int {
2148
public init(_ vector: Vec2i) {
2249
self.init(width: vector.x, height: vector.y)
2350
}
2451
}
2552

53+
extension Vec2i {
54+
public init(_ size: Size<Int>) {
55+
self.init(x: size.width, y: size.height)
56+
}
57+
}
58+
2659
extension Size where Value == Double {
2760
public init(_ vector: Vec2d) {
2861
self.init(width: vector.x, height: vector.y)
2962
}
3063
}
3164

65+
extension Vec2d {
66+
public init(_ size: Size<Double>) {
67+
self.init(x: size.width, y: size.height)
68+
}
69+
}
70+
3271
extension Size where Value == UInt {
3372
public init(_ vector: Vec2u) {
3473
self.init(width: vector.x, height: vector.y)
3574
}
3675
}
3776

38-
extension Size: Equatable where Value: Equatable { }
39-
extension Size: Hashable where Value: Hashable { }
40-
extension Size: Codable where Value: Codable { }
41-
42-
extension Vec2f {
43-
public init(_ size: Size<Float>) {
77+
extension Vec2u {
78+
public init(_ size: Size<UInt>) {
4479
self.init(x: size.width, y: size.height)
4580
}
4681
}

Tests/FirebladeMathTests/XCTestManifests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ extension FunctionTests {
5454
("test_sqrt", test_sqrt),
5555
("test_step", test_step),
5656
("test_tan", test_tan),
57-
("test_tanh", test_tanh)
57+
("test_tanh", test_tanh),
5858
]
5959
}
6060

@@ -88,7 +88,7 @@ extension Mat4x4fTests {
8888
("testTranslateMatrixByVector", testTranslateMatrixByVector),
8989
("testTranslation", testTranslation),
9090
("testTranslationInit", testTranslationInit),
91-
("testUpperLeft", testUpperLeft)
91+
("testUpperLeft", testUpperLeft),
9292
]
9393
}
9494

@@ -120,15 +120,15 @@ extension Quat4fTests {
120120
("testRotMat3x3", testRotMat3x3),
121121
("testRotMat4x4", testRotMat4x4),
122122
("testSubtract", testSubtract),
123-
("testVectorInit", testVectorInit)
123+
("testVectorInit", testVectorInit),
124124
]
125125
}
126126

127127
public func __allTests() -> [XCTestCaseEntry] {
128128
return [
129129
testCase(FunctionTests.__allTests__FunctionTests),
130130
testCase(Mat4x4fTests.__allTests__Mat4x4fTests),
131-
testCase(Quat4fTests.__allTests__Quat4fTests)
131+
testCase(Quat4fTests.__allTests__Quat4fTests),
132132
]
133133
}
134134
#endif

0 commit comments

Comments
 (0)