microcad_core/geo2d/
circle.rs1use crate::*;
7
8#[derive(Debug, Clone)]
10pub struct Circle {
11 pub radius: Scalar,
13
14 pub offset: Vec2,
16}
17
18impl CalcBounds2D for Circle {
19 fn calc_bounds_2d(&self) -> Bounds2D {
20 use geo::Coord;
21
22 if self.radius > 0.0 {
23 let r = Vec2::new(self.radius, self.radius);
24 let min: (Scalar, Scalar) = (self.offset - r).into();
25 let max: (Scalar, Scalar) = (self.offset + r).into();
26
27 Some(Rect::new(Coord::from(min), Coord::from(max)))
28 } else {
29 None
30 }
31 .into()
32 }
33}
34
35impl FetchPoints2D for Circle {
36 fn fetch_points_2d(&self) -> Vec<Vec2> {
37 vec![self.offset]
38 }
39}
40
41impl Circle {
42 pub fn circle_polygon(radius: Scalar, resolution: &RenderResolution) -> Polygon {
44 let n = resolution.circular_segments(radius);
45 let points = NgonIterator::new(n).map(|p| p * radius).collect();
46 Polygon::new(LineString::new(points), vec![])
47 }
48}