MCPcopy Create free account
hub / github.com/Logicalshift/flo_draw / draw_circle

Function draw_circle

canvas/src/primitives.rs:117–135  ·  view source on GitHub ↗

Returns the drawing commands for a circle

(center_x: f32, center_y: f32, radius: f32)

Source from the content-addressed store, hash-verified

115/// Returns the drawing commands for a circle
116///
117pub 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
137impl<'a, Curve: BezierCurve> From<&'a Curve> for Draw
138where Curve::Point: Coordinate2D {

Callers 1

circleMethod · 0.85

Calls 1

mapMethod · 0.80

Tested by

no test coverage detected