-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
918 additions
and
203 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,39 @@ | ||
package unitpacking | ||
|
||
import "github.com/EliCDavis/vector" | ||
|
||
// PackOctQuad16 maps a unit vector to a 2D UV of a octahedron, and then | ||
// encodes the 2D coordinates inside a quad tree. | ||
func PackOctQuad16(v vector.Vector3) []byte { | ||
return Vec2ToTwoByteQuad(MapToOctUV(v)) | ||
} | ||
|
||
// UnpackOctQuad16 builds a 2D coordinate from the encoded quadtree and then | ||
// converts the 2D octahedron UV to 3D unit sphere coordinates. | ||
func UnpackOctQuad16(b []byte) vector.Vector3 { | ||
return FromOctUV(TwoByteQuadToVec2(b)) | ||
} | ||
|
||
// PackOctQuad24 maps a unit vector to a 2D UV of a octahedron, and then | ||
// encodes the 2D coordinates inside a quad tree. | ||
func PackOctQuad24(v vector.Vector3) []byte { | ||
return Vec2ToThreeByteQuad(MapToOctUV(v)) | ||
} | ||
|
||
// UnpackOctQuad24 builds a 2D coordinate from the encoded quadtree and then | ||
// converts the 2D octahedron UV to 3D unit sphere coordinates. | ||
func UnpackOctQuad24(b []byte) vector.Vector3 { | ||
return FromOctUV(ThreeByteQuadToVec2(b)) | ||
} | ||
|
||
// PackOctQuad32 maps a unit vector to a 2D UV of a octahedron, and then | ||
// encodes the 2D coordinates inside a quad tree. | ||
func PackOctQuad32(v vector.Vector3) []byte { | ||
return Vec2ToFourByteQuad(MapToOctUV(v)) | ||
} | ||
|
||
// UnpackOctQuad32 builds a 2D coordinate from the encoded quadtree and then | ||
// converts the 2D octahedron UV to 3D unit sphere coordinates. | ||
func UnpackOctQuad32(b []byte) vector.Vector3 { | ||
return FromOctUV(FourByteQuadToVec2(b)) | ||
} |
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,60 @@ | ||
package unitpacking_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/recolude/unitpacking/unitpacking" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOctQuad16(t *testing.T) { | ||
for _, tc := range testVectors { | ||
unit := tc.Normalized() | ||
name := fmt.Sprintf("%.2f,%.2f,%.2f", unit.X(), unit.Y(), unit.Z()) | ||
|
||
t.Run(name, func(t *testing.T) { | ||
packed := unitpacking.PackOctQuad16(unit) | ||
assert.Len(t, packed, 2) | ||
unpacked := unitpacking.UnpackOctQuad16(packed) | ||
|
||
assert.InDelta(t, unit.X(), unpacked.X(), 0.02, "X components not equal: %.2f != %.2f", unit.X(), unpacked.X()) | ||
assert.InDelta(t, unit.Y(), unpacked.Y(), 0.02, "Y components not equal: %.2f != %.2f", unit.Y(), unpacked.Y()) | ||
assert.InDelta(t, unit.Z(), unpacked.Z(), 0.02, "Z components not equal: %.2f != %.2f", unit.Z(), unpacked.Z()) | ||
}) | ||
} | ||
} | ||
|
||
func TestOctQuad24(t *testing.T) { | ||
for _, tc := range testVectors { | ||
unit := tc.Normalized() | ||
name := fmt.Sprintf("%.2f,%.2f,%.2f", unit.X(), unit.Y(), unit.Z()) | ||
|
||
t.Run(name, func(t *testing.T) { | ||
packed := unitpacking.PackOctQuad24(unit) | ||
assert.Len(t, packed, 3) | ||
unpacked := unitpacking.UnpackOctQuad24(packed) | ||
|
||
assert.InDelta(t, unit.X(), unpacked.X(), 0.02, "X components not equal: %.2f != %.2f", unit.X(), unpacked.X()) | ||
assert.InDelta(t, unit.Y(), unpacked.Y(), 0.02, "Y components not equal: %.2f != %.2f", unit.Y(), unpacked.Y()) | ||
assert.InDelta(t, unit.Z(), unpacked.Z(), 0.02, "Z components not equal: %.2f != %.2f", unit.Z(), unpacked.Z()) | ||
}) | ||
} | ||
} | ||
|
||
func TestOctQuad32(t *testing.T) { | ||
for _, tc := range testVectors { | ||
unit := tc.Normalized() | ||
name := fmt.Sprintf("%.2f,%.2f,%.2f", unit.X(), unit.Y(), unit.Z()) | ||
|
||
t.Run(name, func(t *testing.T) { | ||
packed := unitpacking.PackOctQuad32(unit) | ||
assert.Len(t, packed, 4) | ||
unpacked := unitpacking.UnpackOctQuad32(packed) | ||
|
||
assert.InDelta(t, unit.X(), unpacked.X(), 0.00005, "X components not equal: %.2f != %.2f", unit.X(), unpacked.X()) | ||
assert.InDelta(t, unit.Y(), unpacked.Y(), 0.00005, "Y components not equal: %.2f != %.2f", unit.Y(), unpacked.Y()) | ||
assert.InDelta(t, unit.Z(), unpacked.Z(), 0.00005, "Z components not equal: %.2f != %.2f", unit.Z(), unpacked.Z()) | ||
}) | ||
} | ||
} |
Oops, something went wrong.