-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add codable conformance to matrix3x3 * add equatable extension * add float4x4 extension * fix equatable
- Loading branch information
1 parent
5e5001c
commit d81238a
Showing
5 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// float3x3+Extensions.swift | ||
// org.SwiftGFX.SwiftMath | ||
// | ||
// Created by Eugene Bokhan on 28.02.20. | ||
// | ||
// | ||
|
||
#if !NOSIMD | ||
|
||
import Foundation | ||
import simd | ||
|
||
extension float3x3: Codable { | ||
public init(from decoder: Decoder) throws { | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
let c1 = try values.decode(SIMD3<Float>.self, forKey: .column1) | ||
let c2 = try values.decode(SIMD3<Float>.self, forKey: .column2) | ||
let c3 = try values.decode(SIMD3<Float>.self, forKey: .column3) | ||
|
||
self.init(c1, c2, c3) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(self.columns.0, forKey: .column1) | ||
try container.encode(self.columns.1, forKey: .column2) | ||
try container.encode(self.columns.2, forKey: .column3) | ||
} | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case column1, column2, column3 | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// float4x4+Extensions.swift | ||
// org.SwiftGFX.SwiftMath | ||
// | ||
// Created by Eugene Bokhan on 28.02.20. | ||
// | ||
// | ||
|
||
#if !NOSIMD | ||
|
||
import Foundation | ||
import simd | ||
|
||
extension float4x4: Codable { | ||
public init(from decoder: Decoder) throws { | ||
let values = try decoder.container(keyedBy: CodingKeys.self) | ||
let c1 = try values.decode(SIMD4<Float>.self, forKey: .column1) | ||
let c2 = try values.decode(SIMD4<Float>.self, forKey: .column2) | ||
let c3 = try values.decode(SIMD4<Float>.self, forKey: .column3) | ||
let c4 = try values.decode(SIMD4<Float>.self, forKey: .column4) | ||
|
||
self.init(c1, c2, c3, c4) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode(self.columns.0, forKey: .column1) | ||
try container.encode(self.columns.1, forKey: .column2) | ||
try container.encode(self.columns.2, forKey: .column3) | ||
try container.encode(self.columns.3, forKey: .column4) | ||
} | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case column1, column2, column3, column4 | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters