fmath-0.2.0 has been yanked.
fmath
Math Library for my personal Rust Projects
About
This is not a general-purpose math library. It is specifically written for my purposes only.
Feel free to use it in your projects if it fits your needs, don't even worry about accreditation :)
Example
use ;
// General
let x = 5.0;
let x_clamped = clamp; // 1.0
let number_list: = ;
let max_from_list = max; // 80.0
let min_from_list = min; // -2.0
let another_number_list: = ;
let max_from_another_list = max; // 4
let min_from_another_list = min; // 1
let mut angle = 730.2;
angle = degrees_overflow; // 10.2
let angle_radians = degrees_to_radians; // 0.1780236
let mut number:u8 = 254;
number = u8_add_overflow_max_clamp; // 255
number = u8_sub_overflow_max_clamp; // 0
// Vector math
let v1 = new;
let v2 = new;
let v3 = v1 + v2; // ( 1.0, 1.0 )
let v1_mag = v1.magnitude; // 1.0
// Matrix math
let m1 = MATRIX4X4_ZERO.clone; // creates empty Matrix array
let translate = new;
let rotate = new;
let scale = new;
let m2 = new_trs;
let point1 = new;
let point1_transformed:Vector3 = m2.mul_vector3; // apply transformation Matrix to Vector3
let point2 = new;
let point2_transformed:Vector4 = m2.mul_vector4; // apply transformation Matrix to Vector4
// Colors
let mut rgb = new; // creates RGB with given f32's
let rgb8 = new; // creates RGB8 with given u8's
let rgba = from_hex; // creates RGBA from hex, sets alpha to 1.0
rgb = rgb8.into; // convert RGB8 to RGB
rgb = 0.25; // address each component with index
let hsv = new; // creates HSV with given hue, saturation and value f32's
rgb = hsv.as_rgb; // convert HSV to RGB
hsv = rgb.into; // convert RGB8 to HSV
// All types (except Angle enum) implement fmt::Display
println!;
How to use
Include
in Cargo.toml file...
fmath = "0.1.0"
Documentation
build documentation with cargo doc in the command line
cargo doc
Library Contains...
Functions
- Clamp ( Partial Ord )
- Min and Max ( Partial Ord )
- Degrees to Radians ( f32 )
- Radians to Degrees ( f32 )
- Degrees Overflow ( keeps f32 within 0.0-360.0 range )
- u8 overflow-safe operations ( clamps within 0 and u8_max (255) )
- Hexadecimal Encoder ( String ) /Decoder ( Vec<u8> )
Types
- Colors
- RGB (struct) ( f32;3 )
- RGBA (struct) ( f32;4 )
- RGB8 (struct) ( u8;3 )
- RGBA8 (struct) ( u8;4 )
- HSV (struct) ( hue: f32, saturation: f32, value: f32 )
- Angle (enum)
- Degrees
- Radians
- Vectors
- Vector2 (struct) ( f32;2 )
- Vector3 (struct) ( f32;3 )
- Vector4 (struct) ( f32;4 )
- Matrix4x4 (struct) ( f32;16 )