A Rust crate for converting a geo_types::LineString<T: CoordFloat> into a piecewise cubic Bezier spline, and vice versa.
The conversion is controlled by a maximum allowed error, ensuring the Bezier approximation stays within a specified distance from the original line string.
- LineString to Bezier: Approximate a polyline as a sequence of cubic Bezier segments (
BezierString). - Bezier to LineString: Approximate a Bezier spline as a polyline within a given error.
- Error control: Specify the maximum deviation allowed between the original and the approximation.
- Handles straight lines: Segments with no curvature are represented as straight lines.
BezierSegment<T: CoordFloat>: Either a cubic Bezier or a straight line.- For Bezier:
start,handle1,handle2,end(geo_types::Coord<T>) - For Line:
start,end(geo_types::Coord<T>)
- For Bezier:
BezierString<T: CoordFloat>: A vector ofBezierSegment<T>.
use geo_types::{Coord, LineString};
use linestring2bezier::{BezierString};
let line = LineString(vec![
Coord { x: 0.0, y: 0.0 },
Coord { x: 1.0, y: 2.0 },
Coord { x: 2.0, y: 0.0 },
]);
let bezier = BezierString::from_line_string(line, 0.1).unwrap();
let approx_line = bezier.to_line_string(0.1).unwrap();- Returns errors if the error margin is too small or if the input is empty.
Licensed under the MIT license (LICENSE.md).