Please review my game maths library crate

โš“ Rust    ๐Ÿ“… 2025-07-31    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 13      

surdeus

Warning

This post was published 125 days ago. The information described in this article may have changed.

Hello!

I am very new to Rust (around 1-2 months). I am a recently graduated Games Programmer who specialises in C++, and wanted to learn Rust before it takes over the games industry.

I decided the best way to begin learning was to make a maths lib. I wanted it to have some focus on games, so I chose to focus on graphic and physics calculations mainly. Methods that can be used to make a renderer and physics engine. I will continue to develop this, and I need to set up GitHub actions, however I was wondering if anybody could comment on the code in itโ€™s current state to help me become more comfortable with Rust?

Thank you for your time!

Iโ€™ll put the readMe below so you can see what the project is about, and a link to the project on crates.io here.

:egg: Omelet - A Simple Math Library in Rust

Omelet is a lightweight and extensible Rust math library focused on game development. Designed for both clarity and performance, Omelet provides essential vector and matrix math utilities with an emphasis on clean API design, strong documentation, and comprehensive test coverage.

Features

  • :abacus: Vec2, Vec3, Vec4 - Fully featured vector types
  • :ice: Mat2, Mat3, Mat4 - Matrix types for transformations
  • :hollow_red_circle: Quat - Quaternions for 3D rotation
  • :memo: Thorough unit tests across all components
  • :page_with_curl: In-depth documentation with examples (cargo doc)
  • :triangular_ruler: Utilities for projection, reflection, barycentric coordinates, SLERP, and more
  • :counterclockwise_arrows_button: Operator overloading for intuitive syntax
  • :gear: (planned) SIMD acceleration for performance-critical operations

:rocket: Getting Started

Add Omelet to your Cargo.toml:

[dependencies]
omelet = {git = "https://github.com/ethantl28/omelet", tag = "v0.1.2"}

*Note: Omelet is now published on crates.io

Once Omelet is added to crates.io:

[dependencies]
omelet = "0.1.2"

Note: Please check most recent version for the updated library

Import the types you need:

use omelet::vec::vec2::Vec2;
use omelet::matrices::mat4::Mat4;

:robot: Examples

  • Vector addition, dot product, and normalization
use omelet::vec::Vec2;

fn main() {
    let a = Vec2::new(1.0, 2.0);
    let b = Vec2::new(3.0, 4.0);

    let sum = a + b;
    let dot = a.dot(b);
    let normalized = a.normalize();

    println!("{}, dot: {}, normalized: {}", sum, dot, normalized);
}

Output:

Vec2(4, 6), dot: 11, normalized: Vec2(0.4472136, 0.8944272)
  • Vector cross product and reflection
use omelet::vec::Vec3;

fn main() {
    let a = Vec3::new(1.0, 0.0, 0.0);
    let b = Vec3::new(0.0, 1.0, 0.0);

    let cross = a.cross(b);
    let reflected = a.reflect(b);

    println!("Cross: {}", cross);
    println!("Reflected: {}", reflected);
}

Output:

Cross: Vec3(0, 0, 1)
Reflected: Vec3(1, 0, 0)
  • Vector rotation using rotation matrix
use omelet::matrices::Mat2;

fn main() {
    let rot = Mat2::from_rotation(std::f32::consts::FRAC_2_PI);
    let v = omelet::vec::Vec2::new(1.0, 0.0);
    let rotated = rot * v;

    println!("Rotated vector: {}", rotated);
    println!("Rotation matrix: \n{}", rot);
}

Output:

Rotated vector: Vec2(0.8041099, 0.59448075)
Rotation matrix:
[[0.8041, -0.5945],
[0.5945, 0.8041]]
  • Vector rotation using a quaternion
use omelet::quaternion::Quat;
use omelet::vec::Vec3;

fn main() {
    let axis = Vec3::new(0.0, 1.0, 0.0);
    let angle = std::f32::consts::FRAC_PI_2;
    let rotation = Quat::from_axis_angle(axis, angle);

    let v = Vec3::new(1.0, 0.0, 0.0);
    let rotated = rotation.rotate_vec3(v);

    println!("Rotated Vec3: {}", rotated);
}

Output:

Rotated Vec3: Vec3(0.000, 0.000, -1.000)
  • Epsilon comparison
use omelet::vec::Vec2;
fn main() {
    let a = Vec2::new(1.000001, 2.000001);
    let b = Vec2::new(1.000002, 2.000002);

    assert!(a.approx_eq_eps(b, 1e-5));
    println!("a is approximately equal to b within given epsilon: {}", a.approx_eq_eps(b, 1e-5));
}

Output:

a is approximately equal to b within given epsilon: true

:page_with_curl: Documentation

Run locally:

cargo doc --open

Once published, visit: docs.rs/omelet

Vectors

  • Vec2, Vec3, Vec4 types
    • Extensive unit testing
    • Supports standard operations (addition, subtraction, dot/cross product, normalization, projections, angle calculations, etc.)

Matrices

  • Mat2, Mat3, Mat4 fully implemented
  • Tested against edge cases
  • Clean, consistent API
  • Mat4 documentation is ongoing

Quaternions

  • Full quaternion implementation for 3D rotation
  • Includes SLERP, normalization, conversion to/from Euler angles
  • Heavily tested and documented

How to run the documentation

To view the full documentation, run:

cargo doc --open

:memo: Running Tests

Omelet uses Rust's built-in test framework:

cargo test

All modules are tested thoroughly, including edge cases and floating-point comparisons.

:world_map: Roadmap

  • :white_check_mark: Matrix functionality parity (Mat2, Mat3, Mat4)
  • :white_check_mark: Quaternion support with full docs and tests
  • :yellow_square: SIMD acceleration for vector and matrix math
  • :yellow_square: More geometry utilities (plane intersection, AABB, etc.)

:file_folder: Project Structure

omelet/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ vec/
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ”œโ”€โ”€ list_of_methods.txt
โ”‚   โ”‚   โ”œโ”€โ”€ vec2.rs   
โ”‚   โ”‚   โ”œโ”€โ”€ vec2_tests.rs
โ”‚   โ”‚   โ”œโ”€โ”€ vec3.rs
โ”‚   โ”‚   โ”œโ”€โ”€ vec3_tests.rs
โ”‚   โ”‚   โ”œโ”€โ”€ vec4.rs
โ”‚   โ”‚   โ””โ”€โ”€ vec4_tests.rs
โ”‚   โ”œโ”€โ”€ matrices/
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ”œโ”€โ”€ list_of_methods.txt
โ”‚   โ”‚   โ”œโ”€โ”€ mat2.rs   
โ”‚   โ”‚   โ”œโ”€โ”€ mat2_tests.rs
โ”‚   โ”‚   โ”œโ”€โ”€ mat3.rs
โ”‚   โ”‚   โ”œโ”€โ”€ mat3_tests.rs
โ”‚   โ”‚   โ”œโ”€โ”€ mat4.rs
โ”‚   โ”‚   โ””โ”€โ”€ mat4_tests.rs
โ”‚   โ”œโ”€โ”€ quat/
โ”‚   โ”‚   โ”œโ”€โ”€ mod.rs
โ”‚   โ”‚   โ”œโ”€โ”€ list_of_methods.txt
โ”‚   โ”‚   โ”œโ”€โ”€ quat.rs   
โ”‚   โ”‚   โ””โ”€โ”€ quat_tests.rs
โ”‚   โ”œโ”€โ”€ lib.rs
โ”‚   โ””โ”€โ”€ utils.rs
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ Cargo.toml
โ”œโ”€โ”€ Cargo.lock
โ””โ”€โ”€ README.md

:hammer_and_wrench: Contributing

Want to help improve Omelet? Contributions are welcome!

  • Please use pull requests
  • Code should be formatted using cargo fmt
  • Ensure tests pass via cargo tests
  • For major changes, please open an issue first
    Fork the repo and open a pull request with your improvements.

:thought_balloon: Feedback

Have ideas, suggestions, or found a bug? Open an issue or start a discussion.

:paperclip: License

This project is licensed under the MIT license. See LICENSE for more information.

1 post - 1 participant

Read full topic

๐Ÿท๏ธ Rust_feed