#contour #points #position #line #circle #radius #divide

contourable

A library for differentiable functions

7 releases

new 0.1.7 Feb 21, 2025
0.1.6 Feb 20, 2025

#478 in Algorithms

Download history

243 downloads per month

MIT/Apache

40KB
759 lines

Contour-able

Contour-able is a Rust library for creating and manipulating contour plots. It provides a simple and efficient way to generate contour lines from a set of data points.

Features

  • Generate contour lines from 2D data points
  • Customize contour levels and colors
  • Efficient and easy to use

Installation

Add this to your Cargo.toml:

[dependencies]
contourable = "0.1.0"

Usage

Here is a simple example of how to use Contourable:

extern crate contourable;

use contourable::Contour;

fn main() {
    let data = vec![
        // ...your data points...
    ];
    let contour = Contour::new(data);
    let lines = contour.generate_lines();
    // ...use the generated contour lines...
}

License

This project is licensed under the MIT License or Apache-2.0.

Contribution

Contributions are welcome! Please open an issue or submit a pull request on GitLab.


lib.rs:

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> 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)
    }
}

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.

Dependencies

~3.5MB
~70K SLoC