Returns the drawing commands for a circle
(center_x: f32, center_y: f32, radius: f32)
| 115 | /// Returns the drawing commands for a circle |
| 116 | /// |
| 117 | pub fn draw_circle(center_x: f32, center_y: f32, radius: f32) -> Vec<Draw> { |
| 118 | use self::Draw::*; |
| 119 | use self::PathOp::*; |
| 120 | |
| 121 | // Generate the circle and turn it into bezier curves |
| 122 | let circle = arc::Circle::new(Coord2(center_x as f64, center_y as f64), radius as f64); |
| 123 | let curves: Vec<bezier::Curve<_>> = circle.to_curves(); |
| 124 | let start_point = curves[0].start_point(); |
| 125 | |
| 126 | // Draw the curves |
| 127 | let curves = curves.into_iter().map(|curve| Draw::from(&curve)); |
| 128 | |
| 129 | // Complete the path |
| 130 | let path = iter::once(Path(Move(start_point.x() as f32, start_point.y() as f32))) |
| 131 | .chain(curves) |
| 132 | .chain(iter::once(Path(ClosePath))); |
| 133 | |
| 134 | path.collect() |
| 135 | } |
| 136 | |
| 137 | impl<'a, Curve: BezierCurve> From<&'a Curve> for Draw |
| 138 | where Curve::Point: Coordinate2D { |