diff --git a/Examples/SwiftGraphicsDemosApp/SwiftGraphicsDemosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Examples/SwiftGraphicsDemosApp/SwiftGraphicsDemosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 3d38307..57e785a 100644 --- a/Examples/SwiftGraphicsDemosApp/SwiftGraphicsDemosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Examples/SwiftGraphicsDemosApp/SwiftGraphicsDemosApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,6 +1,15 @@ { - "originHash" : "f54c244080f307f895a67831835efdd7ea3298ad7e0c77a1cbe6f7f2f7312d58", + "originHash" : "8a583861abe86c8b50abccbc3ecadda206025716fb79d8b673b69fbc125fae4a", "pins" : [ + { + "identity" : "approximateequality", + "kind" : "remoteSourceControl", + "location" : "https://github.com/schwa/ApproximateEquality", + "state" : { + "revision" : "552f716baabbb06250f6b598a88dd0a401c72857", + "version" : "0.4.0" + } + }, { "identity" : "everything", "kind" : "remoteSourceControl", diff --git a/Package.resolved b/Package.resolved index af833fc..9035b2f 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,6 +1,15 @@ { - "originHash" : "a4acf933b9a4f484f884225cce0313985ae1be8694da81440840f9820f35c766", + "originHash" : "e332d68911c15106ee5fd69a03c0cc0832ad5830cc986a521e4b5e650b8f4f4d", "pins" : [ + { + "identity" : "approximateequality", + "kind" : "remoteSourceControl", + "location" : "https://github.com/schwa/ApproximateEquality", + "state" : { + "revision" : "552f716baabbb06250f6b598a88dd0a401c72857", + "version" : "0.4.0" + } + }, { "identity" : "everything", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 3445dd6..6d15748 100644 --- a/Package.swift +++ b/Package.swift @@ -51,6 +51,7 @@ let package = Package( .package(url: "https://github.com/schwa/swiftfields", from: "0.0.1"), .package(url: "https://github.com/schwa/swiftformats", from: "0.3.5"), .package(url: "https://github.com/schwa/SwiftGLTF", branch: "main"), + .package(url: "https://github.com/schwa/ApproximateEquality", from: "0.4.0"), ], targets: [ @@ -157,6 +158,7 @@ let package = Package( "GaussianSplatShaders", "GaussianSplatSupport", "Projection", + "ApproximateEquality" ], resources: [ .copy("Resources/lastchance.splat"), diff --git a/Tests/GaussianSplatTests/SplatXConversionTests.swift b/Tests/GaussianSplatTests/SplatXConversionTests.swift new file mode 100644 index 0000000..1ce6083 --- /dev/null +++ b/Tests/GaussianSplatTests/SplatXConversionTests.swift @@ -0,0 +1,35 @@ +import Testing +import GaussianSplatSupport +import GaussianSplatShaders +import ApproximateEquality + +@Test(arguments: [ + ( + SplatB(position: [0, 0, 0], scale: [1, 1, 1], color: [255, 255, 255, 255], rotation: [128, 128, 128, 255]), + SplatX(position: [0, 0, 0], u1: [3.7539063, 0.0], u2: [0.0, 3.7539063], u3: [0.0, 4.0], color: [255, 255, 255, 255]), + 0.000_000_1 + ), + ( + SplatB(position: [5.1992097, 14.8973675, -1.0287564], scale: [0.3719001, 0.41435486, 0.22165838], color: [22, 39, 53, 255], rotation: [67, 96, 211, 59]), + SplatX(position: [5.1992097, 14.8973675, -1.0287564], u1: [0.6044922, -0.14904785], u2: [0.05557251, 0.25170898], u3: [-0.0061683655, 0.58154297], color: [22, 39, 53, 255]), + 0.001 + ), + ( + SplatB(position: [0, 0, 0], scale: [1, 0.5, 0.25], color: [255, 0, 255, 255], rotation: [128, 128, 128, 255]), + SplatX(position: [0.0, 0.0, 0.0], u1: [3.7539063, 0.0], u2: [0.0, 0.93847656], u3: [0.0, 0.25], color: [255, 0, 255, 255]), + 0.0001 + ), +]) +func testSplatXConversion(splatB: SplatB, splatX: SplatX, absoluteTolerance: Double) { + #expect(SplatX(splatB).isApproximatelyEqual(to: splatX, absoluteTolerance: absoluteTolerance)) +} + +extension SplatX: @retroactive ApproximateEquality { + public func isApproximatelyEqual(to other: Self, absoluteTolerance: Double.Magnitude) -> Bool { + return position.isApproximatelyEqual(to: other.position, absoluteTolerance: Float(absoluteTolerance)) && + u1.isApproximatelyEqual(to: other.u1, absoluteTolerance: Float16(absoluteTolerance)) && + u2.isApproximatelyEqual(to: other.u2, absoluteTolerance: Float16(absoluteTolerance)) && + u3.isApproximatelyEqual(to: other.u3, absoluteTolerance: Float16(absoluteTolerance)) && + color == other.color + } +}