simple-bezier-easing

Crates.iosimple-bezier-easing
lib.rssimple-bezier-easing
version0.1.1
created_at2024-12-04 22:22:17.728446+00
updated_at2024-12-14 22:53:47.519592+00
descriptionA library for calculating cubic Bézier curves using De Casteljau's algorithm.
homepagehttps://github.com/0xJWLabs/simple-bezier-easing
repositoryhttps://github.com/0xJWLabs/simple-bezier-easing
max_upload_size
id1472592
size19,011
(0xJWLabs)

documentation

README

simple-bezier-easing

A Rust library for calculating cubic Bézier curves using De Casteljau's algorithm, with error handling and binary subdivision support for finding curve parameters. This library is ideal for applications like animations, easing functions, and graphics rendering.

Features

  • Cubic Bézier Curves: Easily calculate Bézier curves with customizable control points.
  • De Casteljau's Algorithm: Accurate and efficient curve evaluation.
  • Error Handling: Handles invalid control points gracefully.
  • Binary Subdivision: Finds parameters for given x values with high precision.

Installation

To add this library to your project, include it in your Cargo.toml file:

[dependencies]
simple-bezier-easing = "0.1.0"

Example Usage

use simple_bezier_easing::bezier;

fn main() {
    // Define a Bézier curve with control points
    let bez = bezier(0.2, 0.4, 0.6, 0.8).unwrap();

    // Calculate the y-coordinate for x = 0.5
    let y_at_0_5 = bez(0.5).unwrap();
    println!("y at x = 0.5: {}", y_at_0_5);
}

Error Handling

The library returns an error for invalid control points, for example:

let invalid_bez = bezier(1.2, 0.4, 0.6, 0.8); // Invalid control point
assert!(invalid_bez.is_err(), "Expected error for invalid control points");

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Commit count: 2

cargo fmt