use super::{
Path,
PathSegment,
};
#[allow(missing_debug_implementations)]
pub struct PathBuilder {
path: Path,
}
impl PathBuilder {
pub fn new() -> PathBuilder {
PathBuilder { path: Path::new() }
}
pub fn with_capacity(capacity: usize) -> PathBuilder {
PathBuilder { path: Path::with_capacity(capacity) }
}
pub fn move_to(mut self, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::MoveTo { abs: true, x, y });
self
}
pub fn rel_move_to(mut self, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::MoveTo { abs: false, x, y });
self
}
pub fn close_path(mut self) -> PathBuilder {
self.path.push(PathSegment::ClosePath { abs: true });
self
}
pub fn rel_close_path(mut self) -> PathBuilder {
self.path.push(PathSegment::ClosePath { abs: false });
self
}
pub fn line_to(mut self, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::LineTo { abs: true, x, y });
self
}
pub fn rel_line_to(mut self, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::LineTo { abs: false, x, y });
self
}
pub fn hline_to(mut self, x: f64) -> PathBuilder {
self.path.push(PathSegment::HorizontalLineTo { abs: true, x });
self
}
pub fn rel_hline_to(mut self, x: f64) -> PathBuilder {
self.path.push(PathSegment::HorizontalLineTo { abs: false, x });
self
}
pub fn vline_to(mut self, y: f64) -> PathBuilder {
self.path.push(PathSegment::VerticalLineTo { abs: true, y });
self
}
pub fn rel_vline_to(mut self, y: f64) -> PathBuilder {
self.path.push(PathSegment::VerticalLineTo { abs: false, y });
self
}
pub fn curve_to(mut self, x1: f64, y1: f64, x2: f64, y2: f64, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::CurveTo { abs: true, x1, y1, x2, y2, x, y });
self
}
pub fn rel_curve_to(mut self, x1: f64, y1: f64, x2: f64, y2: f64, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::CurveTo { abs: false, x1, y1, x2, y2, x, y });
self
}
pub fn smooth_curve_to(mut self, x2: f64, y2: f64, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::SmoothCurveTo { abs: true, x2, y2, x, y });
self
}
pub fn rel_smooth_curve_to(mut self, x2: f64, y2: f64, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::SmoothCurveTo { abs: false, x2, y2, x, y });
self
}
pub fn quad_to(mut self, x1: f64, y1: f64, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::Quadratic { abs: true, x1, y1, x, y });
self
}
pub fn rel_quad_to(mut self, x1: f64, y1: f64, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::Quadratic { abs: false, x1, y1, x, y });
self
}
pub fn smooth_quad_to(mut self, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::SmoothQuadratic { abs: true, x, y });
self
}
pub fn rel_smooth_quad_to(mut self, x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::SmoothQuadratic { abs: false, x, y });
self
}
pub fn arc_to(mut self, rx: f64, ry: f64, x_axis_rotation: f64, large_arc: bool, sweep: bool,
x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::EllipticalArc { abs: true, rx, ry, x_axis_rotation,
large_arc, sweep, x, y });
self
}
pub fn rel_arc_to(mut self, rx: f64, ry: f64, x_axis_rotation: f64, large_arc: bool, sweep: bool,
x: f64, y: f64) -> PathBuilder {
self.path.push(PathSegment::EllipticalArc { abs: false, rx, ry, x_axis_rotation,
large_arc, sweep, x, y });
self
}
pub fn finalize(self) -> Path {
self.path
}
}