1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! A Rust library for compressed unit vectors.
//!
//! It can be used to efficiently store and transfer things like normal vectors used in computer graphics.
//! You can use it lower the memory footsprint or reduce the size of files on disk.
//! Intead of three 32 bit floats you can represent the unit vector with a single 16 bit unsigned integer.
//!
//! The compression itself is **lossy**, so most input values will be mapped to something slighty different when being unpacked.
//! For many use cases this loss is acceptable. Please make sure this applies to your case as well.
//!
//! ### Getting Started
//!
//! The following example shows how to create and read a compressed unit vector:
//!
//! ```
//! use cuv::CompUnitVec;
//!
//! let input = [1.0, 0.0, 0.0];
//! let packed = CompUnitVec::from_slice(&input);
//! let unpacked = packed.get();
//! assert_eq!(unpacked, input);
//! ```
//! There is also a low level interface which requires the manual creation of a lookup-table for unpacking:
//!
//! ```
//! let packed: u16 = cuv::pack(1.0, 0.0, 0.0);
//! let lut = cuv::create_lut();
//! let unpacked = cuv::unpack(packed, &lut);
//! assert_eq!(unpacked, [1.0, 0.0, 0.0]);
//! ```
//!
//! ### Invalid Input
//!
//! If the input is not a unit vector, it will still work because the input is internally normalized.
//! The unpacked output vectors will be always normalized and true unit vectors.
//!
//! The algorithm can handle invalid inputs and will map them to a valid compressed unit vector.
//! For example, using `[0, 0, 0]` as input will unpack as `[0, 0, 1]`.
//! The same applies for `NaN` or infinity values.
// Low level interface
pub use create_lut;
pub use pack;
pub use unpack;
// High level rustified interface
pub use CompUnitVec;