Skip to content

Commit

Permalink
Unit test conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
schwa committed Dec 9, 2024
1 parent 40b2ce5 commit 6ae8e6f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 10 additions & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -157,6 +158,7 @@ let package = Package(
"GaussianSplatShaders",
"GaussianSplatSupport",
"Projection",
"ApproximateEquality"
],
resources: [
.copy("Resources/lastchance.splat"),
Expand Down
35 changes: 35 additions & 0 deletions Tests/GaussianSplatTests/SplatXConversionTests.swift
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 6ae8e6f

Please sign in to comment.