use crate::Point;
#[derive(Debug, Clone)]
pub enum Shape {
Rectangle {
width: u32,
height: u32,
},
Circle {
radius: u32,
},
Line {
start: Point,
points: Vec<LinePoint>,
},
}
pub enum ShapeBuilder {}
#[derive(Debug, Copy, Clone)]
pub enum LinePoint {
Straight { point: Point },
QuadraticBezierCurve { point: Point, curve: Point },
CubicBezierCurve {
point: Point,
curve_a: Point,
curve_b: Point,
},
}
pub struct Line {
start: Point,
points: Vec<LinePoint>,
}
impl Line {
pub fn new(start: Point) -> Line {
Line {
start,
points: vec![],
}
}
pub fn line_to(&mut self, point: Point) {
self.points.push(LinePoint::Straight { point });
}
pub fn curve_to(&mut self, point: Point, curve: Point) {
self.points
.push(LinePoint::QuadraticBezierCurve { point, curve })
}
pub fn to_shape(self) -> Shape {
Shape::Line {
start: self.start,
points: self.points,
}
}
}
pub struct LineBuilder {
line: Line,
}
impl LineBuilder {
pub fn new(x: f32, y: f32) -> LineBuilder {
LineBuilder {
line: Line::new(Point::new(x, y)),
}
}
pub fn line_to(mut self, x: f32, y: f32) -> LineBuilder {
self.line.line_to(Point::new(x, y));
self
}
pub fn curve_to(mut self, x: f32, y: f32, curve_x: f32, curve_y: f32) -> LineBuilder {
self.line
.curve_to(Point::new(x, y), Point::new(curve_x, curve_y));
self
}
pub fn build(self) -> Shape {
self.line.to_shape()
}
}
impl From<Line> for Shape {
fn from(line: Line) -> Shape {
line.to_shape()
}
}