hexga_math

Crates.iohexga_math
lib.rshexga_math
version0.0.11-beta.3
created_at2025-03-28 17:48:20.227197+00
updated_at2025-08-12 19:08:22.624833+00
descriptionMath related crate that support multi dimensionnal vector, matrix, rectangle...
homepagehttps://github.com/Thomas-Mewily/hexga
repositoryhttps://github.com/Thomas-Mewily/hexga
max_upload_size
id1609921
size336,983
Mewily (Thomas-Mewily)

documentation

README

🚧 Warning: Experimental Crate! 🚧

This crate is currently in beta and experimental. It is subject to breaking changes in future releases. Use it at your own risk, and keep in mind that the API may change in future versions.

HexGa Math

Check the documentation to find some examples in the doc.

A Math library that contains :

N Dimension stuff

This crate define N dimensionnal math stuff (2d, 3d, 4d, ... nd) like vector/point of any type (float, int, uint, or even user defined):

Useful type like

use hexga_math::prelude::*;

assert_eq!([1,2].degree(), [1.degree(),2.degree()]);
assert_eq!(1.kilo(), 1000);

Generic Casting trait

The crate also provide generic traits for casting with the same behavior as the as keyword :

use hexga_math::prelude::*;

assert_eq!(i32::cast_from(255u8), 255i32);
assert_eq!(i32::cast_from(12.3f32), 12);

let vec_f32 = Vector2::<f32>::new(0.5, 0.5);
let vec_f64 = Vector2::<f64>::new(0.5, 0.5);
let vec_f32_to_f64 = <Vector2::<f32> as CastIntoComposite<f64>>::cast_into_composite(vec_f32);
assert_eq!(vec_f32_to_f64, vec_f64);

Generic Remapping trait

Similar traits for casting remapping the range of an primitive to another primitive range also exist :

use hexga_math::prelude::*;

assert_eq!(u8::cast_range_from(1f32), 255u8);
assert_eq!(u8::cast_range_from(127i8), 254u8);
assert_eq!(i8::cast_range_from(255u8), 127i8);

Quick start with the prelude

There are some quick typedef in the prelude :

  • int, uint and float : The default primitive precision used in the typedef. (can be change with the feature flags)

  • Point2, Point3, Point4 for Vector of int,

  • Vec2, Vec3, Vec4 for Vector of float,

  • Rect2, Rect3, Rect4 for Rectangle of float,

  • Rect2P, Rect3P, Rect4P for Rectangle of int (P for point),

  • Mat2, Mat3, Mat4 for Matrix of float, and Mat2P, Mat3P, Mat4P use int,

  • Grid2, Grid3, Grid3 can only be indexed by Point by default.

More advanced type

If you need more control about the precision, each type have another more generic base type:

  • Grid type uses a Point for the indexing precision, but that can be changed by using with the GridBase type.
  • Angle and Time use a float precision that can be changed using AngleOf and TimeOf

Main Hexga crate

Check hexga : https://crates.io/crates/hexga if you are interested in a quick start, it regroup multiple hexga crates.

Commit count: 338

cargo fmt