6 releases

0.4.0 Nov 26, 2024
0.2.8 Dec 26, 2021
0.2.7 Sep 18, 2021
0.2.5 Jul 24, 2021

#192 in Rendering

Download history 3/week @ 2024-11-04 652/week @ 2024-11-25 9/week @ 2024-12-09

661 downloads per month
Used in todo-tui

MIT license

19KB
305 lines

Coord2d

Crate Status docs.rs License

A Rust library for working with 2D coordinates and vectors.

Overview

Coord2D provides a robust and flexible way to manage and manipulate 2D coordinates and vectors in Rust. It supports various mathematical operations, type conversions, and vector properties like magnitude and midpoint, making it ideal for 2D geometry computations.

Features

  • Coordinate Management: Define and manipulate 2D coordinates with ease.
  • Mathematical Operations: Perform addition, subtraction, multiplication, and division on coordinates.
  • Type Flexibility: Supports multiple integer and floating-point types, such as i32, f32, usize, and more.
  • Vector Utilities: Calculate magnitude, midpoint, and more.
  • Conversions: Convert coordinates to vectors, tuples, or Vec formats.
  • Debugging Tools: Simplified debugging utilities.
  • Extensible: Designed with modularity to support future enhancements like shapes.

Getting Started

Add coord2d to your Cargo.toml:

[dependencies]
coord2d = "*"

Examples

Working with Coordinates

use coord2d::*;

fn main() {
    let a: coord::Coord = new_coord!(1, 2.0);
    let b: coord::Coord = new_coord!(3, 4.5);
}

Working with Vectors

use coord2d::*;

fn main() {
    let a: coord::Coord = new_coord!(2.5, 3.3);
    let b: coord::Coord = new_coord!(1.0, 1.5);

    let vector: vector::Vector = new_vector!(a, b);

    let magnitude = vector.get_magnitude(); // Calculate magnitude
    let midpoint = vector.get_midpoint(); // Get midpoint

    println!("Magnitude: {}", magnitude);
    println!("Midpoint: {:?}", midpoint);
}

Debugging

use coord2d::*;

fn main() {
    let coord: coord::Coord = new_coord!(1, 2.0);
    let vector: vector::Vector = new_vector!(coord);

    debug::debug(coord); // Debug a coordinate
    debug::debug(vector); // Debug a vector
}

Planned Features

  • 2D Shapes: Add support for shape creation and manipulation.
  • Code Cleanup: Refactor and clean up the codebase.

Contributing

We welcome contributions to improve coord2d. If you have ideas or spot issues:

  1. Open an issue on GitHub.
  2. Submit a pull request with your changes.

License

This project is licensed under the GPL License.

Enjoy using coord2d for your projects? Give us a star! 🌟

No runtime deps