Struct vec_2_10_10_10::Vector [] [src]

#[repr(C, packed)]
pub struct Vector { /* fields omitted */ }

Four dimensional 2-10-10-10 vector.

The binary data is mapped into floating point values from 0.0 to 1.0. The values outside this range are clamped.

The w dimension takes 2 bits, and can have values 0.0, 0.3(3), 0.6(6) and 1.0. The x, y and z dimensions take 10 bits, each.

The internal format is equivalent to GL_UNSIGNED_INT_2_10_10_10_REV OpenGL vertex attribute type.

Methods

impl Vector
[src]

[src]

Creates a new Vector.

First x, y, z values are stored in 10-bits, each. The w value is stored in 2 bits.

Everything is packed internally into 4 bytes.

The stored values are a bit wonky precisely because of low stored precision.

let value = vec_2_10_10_10::Vector::new(0.444, 0.555, 0.666, 0.2);

assert!(approx_equal(value.x(), 0.444));
assert!(approx_equal(value.y(), 0.555));
assert!(approx_equal(value.z(), 0.666));

// 2 bits means only possible values are 0, 0.3(3), 0.6(6) and 1.
assert!(approx_equal(value.w(), 0.333));

fn approx_equal(a: f32, b: f32) -> bool {
    const DELTA: f32 = 0.001;
    a > b - DELTA && a < b + DELTA
}

[src]

Creates a vector from raw 4-byte data.

The vector can be used to inspect such data if it was created by other means.

let other_value = *vec_2_10_10_10::Vector::new(0.444, 0.555, 0.666, 0.333).raw_value();
let value = vec_2_10_10_10::Vector::from_raw(other_value);

assert!(approx_equal(value.x(), 0.444));
assert!(approx_equal(value.y(), 0.555));
assert!(approx_equal(value.z(), 0.666));
assert!(approx_equal(value.w(), 0.333));

fn approx_equal(a: f32, b: f32) -> bool {
    const DELTA: f32 = 0.001;
    a > b - DELTA && a < b + DELTA
}

[src]

Get x value.

[src]

Get y value.

[src]

Get z value.

[src]

Get w value.

[src]

Update x value.

This changes internal 4-byte representation.

let mut value = vec_2_10_10_10::Vector::new(0.0, 0.0, 0.0, 0.0);
value.set_x(0.333);

assert!(approx_equal(value.x(), 0.333));
assert!(approx_equal(value.y(), 0.0));
assert!(approx_equal(value.z(), 0.0));
assert!(approx_equal(value.w(), 0.0));

[src]

Update y value.

This changes internal 4-byte representation.

let mut value = vec_2_10_10_10::Vector::new(0.0, 0.0, 0.0, 0.0);
value.set_y(0.333);

assert!(approx_equal(value.x(), 0.0));
assert!(approx_equal(value.y(), 0.333));
assert!(approx_equal(value.z(), 0.0));
assert!(approx_equal(value.w(), 0.0));

[src]

Update z value.

This changes internal 4-byte representation.

let mut value = vec_2_10_10_10::Vector::new(0.0, 0.0, 0.0, 0.0);
value.set_z(0.333);

assert!(approx_equal(value.x(), 0.0));
assert!(approx_equal(value.y(), 0.0));
assert!(approx_equal(value.z(), 0.333));
assert!(approx_equal(value.w(), 0.0));

[src]

Update x, y and z.

This changes internal 4-byte representation.

let mut value = vec_2_10_10_10::Vector::new(0.0, 0.0, 0.0, 0.0);
value.set_xyz(0.333, 0.444, 0.555);

assert!(approx_equal(value.x(), 0.333));
assert!(approx_equal(value.y(), 0.444));
assert!(approx_equal(value.z(), 0.555));
assert!(approx_equal(value.w(), 0.0));

[src]

Update w.

This changes internal 4-byte representation.

let mut value = vec_2_10_10_10::Vector::new(0.0, 0.0, 0.0, 0.0);
value.set_w(0.333);

assert!(approx_equal(value.x(), 0.0));
assert!(approx_equal(value.y(), 0.0));
assert!(approx_equal(value.z(), 0.0));
assert!(approx_equal(value.w(), 0.333));

[src]

Return raw internal value.

Trait Implementations

impl Copy for Vector
[src]

impl Clone for Vector
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Vector
[src]

[src]

Formats the value using the given formatter.