unitpacking

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteQuadToVec2

func ByteQuadToVec2(b byte) vector.Vector2

ByteToVec2 calculates a Vector2 based on the encoded quadtree inside the byte.

func Clamp

func Clamp(num float64, min float64, max float64) float64

Clamp clamps the given value between the given minimum float and maximum float values. Returns the given value if it is within the min and max range.

func FourByteQuadToVec2

func FourByteQuadToVec2(b []byte) vector.Vector2

FourByteQuadToVec2 calculates a Vector2 based on the encoded quadtree inside the 4 bytes

func FromOctUV

func FromOctUV(e vector.Vector2) vector.Vector3

FromOctUV converts a 2D octahedron UV coordinate to a point on a 3D sphere.

func MapToOctUV

func MapToOctUV(v vector.Vector3) vector.Vector2

MapToOctUV converts a 3D sphere's coordinates to a 2D octahedron UV.

func MapToOctUVPrecise

func MapToOctUVPrecise(v vector.Vector3, n int) vector.Vector2

MapToOctUVPrecise brute force finds an optimal UV coordinate that minimizes rounding error.

func PackAlg24

func PackAlg24(v vector.Vector3) []byte

PackAlg24 converts the x y z components of a normalized vector into a 3 bytes for efficient transport. Uses trig to pack X into 12 bytes, Y into 11 bytes, and 1 to denote sign of Z.

func PackCoarse24

func PackCoarse24(v vector.Vector3) []byte

PackCoarse24 will convert each component of the vector into a single byte, and will return those bytes in an array where x is at index 0, and z is at index 2

func PackOct16

func PackOct16(v vector.Vector3) []byte

PackOct16 maps a unit vector to a 2D UV of a octahedron, and then writes the 2D coordinates to 2 bytes, 8bits per coordinate.

func PackOct24

func PackOct24(v vector.Vector3) []byte

PackOct24 maps a unit vector to a 2D UV of a octahedron, and then writes the 2D coordinates to 3 bytes, 12bits per coordinate.

func PackOct32

func PackOct32(v vector.Vector3) []byte

PackOct32 maps a unit vector to a 2D UV of a octahedron, and then writes the 2D coordinates to 4 bytes, 2 bytes per coordinate.

func PackOctQuad16

func PackOctQuad16(v vector.Vector3) []byte

PackOctQuad16 maps a unit vector to a 2D UV of a octahedron, and then encodes the 2D coordinates inside a quad tree.

func PackOctQuad24

func PackOctQuad24(v vector.Vector3) []byte

PackOctQuad24 maps a unit vector to a 2D UV of a octahedron, and then encodes the 2D coordinates inside a quad tree.

func PackOctQuad32

func PackOctQuad32(v vector.Vector3) []byte

PackOctQuad32 maps a unit vector to a 2D UV of a octahedron, and then encodes the 2D coordinates inside a quad tree.

func ThreeByteQuadToVec2

func ThreeByteQuadToVec2(b []byte) vector.Vector2

ThreeByteQuadToVec2 calculates a Vector2 based on the encoded quadtree inside the 3 bytes

func TwoByteQuadToVec2

func TwoByteQuadToVec2(b []byte) vector.Vector2

TwoByteQuadToVec2 calculates a Vector2 based on the encoded quadtree inside the 2 bytes

func UnpackAlg24

func UnpackAlg24(b []byte) vector.Vector3

UnpackAlg24 will take a previously packed vector and extract it out of 3 bytes

func UnpackCoarse24

func UnpackCoarse24(in []byte) vector.Vector3

UnpackCoarse24 will take a previously packed vector and extract it out of 3 bytes

func UnpackOct16

func UnpackOct16(b []byte) vector.Vector3

UnpackOct16 reads in two 8bit numbers and converts from 2D octahedron UV to 3D unit sphere coordinates.

func UnpackOct24

func UnpackOct24(b []byte) vector.Vector3

UnpackOct24 reads in two 12bit numbers and converts from 2D octahedron UV to 3D unit sphere coordinates.

func UnpackOct32

func UnpackOct32(b []byte) vector.Vector3

UnpackOct32 reads in two 16bit numbers and converts from 2D octahedron UV to 3D unit sphere coordinates.

func UnpackOctQuad16

func UnpackOctQuad16(b []byte) vector.Vector3

UnpackOctQuad16 builds a 2D coordinate from the encoded quadtree and then converts the 2D octahedron UV to 3D unit sphere coordinates.

func UnpackOctQuad24

func UnpackOctQuad24(b []byte) vector.Vector3

UnpackOctQuad24 builds a 2D coordinate from the encoded quadtree and then converts the 2D octahedron UV to 3D unit sphere coordinates.

func UnpackOctQuad32

func UnpackOctQuad32(b []byte) vector.Vector3

UnpackOctQuad32 builds a 2D coordinate from the encoded quadtree and then converts the 2D octahedron UV to 3D unit sphere coordinates.

func Vec2ToByteQuad

func Vec2ToByteQuad(v vector.Vector2) byte

Vec2ToByteQuad creates a quadtree of depth 4 and encodes itself into a single byte

func Vec2ToFourByteQuad

func Vec2ToFourByteQuad(v vector.Vector2) []byte

Vec2ToFourByteQuad creates a quadtree of depth 16 and encodes itself in 4 bytes

func Vec2ToThreeByteQuad

func Vec2ToThreeByteQuad(v vector.Vector2) []byte

Vec2ToThreeByteQuad creates a quadtree of depth 12 and encodes itself in three bytes

func Vec2ToTwoByteQuad

func Vec2ToTwoByteQuad(v vector.Vector2) []byte

Vec2ToTwoByteQuad creates a quadtree of depth 8 and encodes itself in two bytes

Types

type Quadrant2D

type Quadrant2D int

Quadrant2D represents a quadrant in a 2D space.

const (
	TopLeft Quadrant2D = iota
	TopRight
	BottomLeft
	BottomRight
)

func QuadRecurse

func QuadRecurse(in, min, max vector.Vector2, levels int) []Quadrant2D

QuadRecurse recursively builds a quad tree based on the given Vector2. The tree's depth is determined by the number of levels passed in.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL