### 1 stable release

1.0.0 | Feb 7, 2024 |
---|

#**162** in Visualization

**Custom license**

19KB

265 lines

# cubic-bezier

This crate provides functionality for working with cubic Bezier curves, such as creating, manipulating, and calculating points along cubic Bezier curves.

## Features

- Create cubic Bezier curves with control handles.
- Manipulate curves by adding, removing, or modifying control handles.
- Add control handles without modifying the curve.
- Calculate points along the curve with customizable detail.
- Caches calculated points.

## Example

`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``(``)``;`

## Usage

Creating a new Bezier curve is done with the

method. You specify the level of detail and an estimation of the number of handles that will be added.`new`

`let` `mut` bezier `=` `Bezier``::`new`(``10``,` `2``)``;`

After creating the curve, you can add control handles using the

method.`push`

`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

method.`calculate`

`let` points `=` bezier`.``calculate``(``)``;`

This will return a vector of points representing the curve.

### Inserting a Handle

You can insert a handle without changing the appearance of the curve using the

method.`knot_insert`

`bezier``.``knot_insert``(``0.``5``)``;`

### Debugging

You can access all control points for debugging purposes using the

method.`all_part_point`

`let` control_points `=` bezier`.``all_part_point``(``)``;`

## License

This library is licensed under the MIT license. See the LICENSE file for details.

#### Dependencies

~490KB