hexga_math

Crates.iohexga_math
lib.rshexga_math
version0.0.11-beta.47
created_at2025-03-28 17:48:20.227197+00
updated_at2026-01-09 20:51:39.020294+00
descriptionMath related crate that define number and casting, and support array programming...
homepagehttps://github.com/Thomas-Mewily/hexga
repositoryhttps://github.com/Thomas-Mewily/hexga
max_upload_size
id1609921
size319,140
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, a Math library that contains

N Dimension stuff and Array Programming

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

  • [Vector] (fixed size array wrapper)
  • [Rectangle]
  • [Grid]
  • [Matrix]

The same common functions such as [min], [max], [mix], [abs], and [clamp] work for

  • primitive values(u32, i32, f32, bool, ...)
  • and on composite types (Array, Vector, Color, Rectangle, Matrix, Grid, ...) that implement the [Map] / [MapWith] / [MapIntern] / [MapInternWith] traits.

Any external type implementing these traits automatically gains support for these common functions.

Useful type like

  • [Angle]
  • [Time],

Generic Casting trait

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

  • [CastInto], [CastFrom],

Generic Remapping trait

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

  • [CastRangeInto], [CastRangeFrom]

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)
  • [Vec2i], [Vec3i], [Vec4i] for Vector of [int],
  • [Vec2], [Vec3], [Vec4] for Vector of [float],
  • [Rect2], [Rect3], [Rect4] for Rectangle of [float],
  • [Rect2i], [Rect3i], [Rect4i] for Rectangle of [int] (P for point),
  • [Mat2], [Mat3], [Mat4] for Matrix of [float], and [Mat2i], [Mat3i], [Mat4i] use [int],
  • [Grid2], [Grid3], [Grid3] can only be indexed by VecXi 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 VecXi for the indexing precision, but that can be changed by using with the [hexga_math::grid::GridBase] type.
  • [Angle] and [Time] use a [float] precision that can be changed using [AngleOf] and [TimeOf]
Commit count: 710

cargo fmt