Crate contourable

Source
Expand description

§Contour-able

contourable is a Rust crate that provides traits and implementations for working with contours. It allows you to define contours and calculate positions on them based on input values.

§Usage

To use this crate, you need to implement the Contour trait for your contour type. The trait requires you to define the position method, which calculates the position on the contour for a given input value. Additionally, the trait provides a default implementation for the divide method, which divides the contour into a specified number of points between the start and end values.

§Example

use nalgebra as na;
use contourable::Contour;

struct Circle {
    radius: f64,
}

impl Contour<f64,f64> for Circle {
    fn position(&self, lap: &f64) -> na::Point2<f64> {
        let angle = lap * 2.0 * std::f64::consts::PI;
        let x = self.radius * angle.cos();
        let y = self.radius * angle.sin();
        na::Point2::new(x, y)
    }
   fn s_interval(&self) -> (f64, f64) {
       (0.0, 1.0)
   }
}

let circle = Circle { radius: 2.0 };
let points = circle.divide(0.0, 1.0, 5);
for point in points {
    println!("Point: ({}, {})", point.x, point.y);
}

§Testing

The crate includes tests for both f64 and DualVec64 types to ensure the correctness of the Contour trait implementation. The tests cover the position and divide methods for a Circle contour.

Modules§

chain
This module contains the implementation of the chain contour.
closed
This module contains the implementation of the closed contour.
line
mixed_chain
This module contains the implementation of the mixed chain contour.

Structs§

Aabb
A structure representing an axis-aligned bounding box (AABB) in 2D space.

Traits§

Contour
A trait representing a contour that can provide a position based on a given input.