| Crates.io | cubic-bezier |
| lib.rs | cubic-bezier |
| version | 1.0.0 |
| created_at | 2024-02-07 14:57:34.067473+00 |
| updated_at | 2024-02-07 14:57:34.067473+00 |
| description | Create and modify cubic bezier curves |
| homepage | |
| repository | https://github.com/thintheranks/cubic-bezier |
| max_upload_size | |
| id | 1130598 |
| size | 24,587 |
This crate provides functionality for working with cubic Bezier curves, such as creating, manipulating, and calculating points along cubic Bezier curves.
use cubic_bezier::{point, Bezier, Handle};
let mut bezier = Bezier::new(10, 2);
bezier.push(Handle::mirrored(point!(-1.0, 1.0), point!(0.0, 0.0)));
bezier.push(Handle::mirrored(point!(1.0, 1.0), point!(2.0, 0.0)));
let points = bezier.calculate();
Creating a new Bezier curve is done with the new method. You specify the level of detail and an estimation of the number of handles that will be added.
let mut bezier = Bezier::new(10, 2);
After creating the curve, you can add control handles using the push method.
bezier.push(Handle::mirrored(point!(-1.0, 1.0), point!(0.0, 0.0)));
bezier.push(Handle::mirrored(point!(1.0, 1.0), point!(2.0, 0.0)));
To calculate points along the curve, call the calculate method.
let points = bezier.calculate();
This will return a vector of points representing the curve.
You can insert a handle without changing the appearance of the curve using the knot_insert method.
bezier.knot_insert(0.5);
You can access all control points for debugging purposes using the all_part_point method.
let control_points = bezier.all_part_point();
This library is licensed under the MIT license. See the LICENSE file for details.