shape_core/elements/polygons/
regular.rs1use super::*;
2
3impl<T> RegularPolygon<T>
4where
5 T: Real,
6{
7 pub fn unit(sides: usize) -> Self {
8 Self { sides, center: Point { x: T::zero(), y: T::zero() }, radius: T::one(), rotate: T::zero() }
9 }
10 pub fn new<P>(sides: usize, center: P, radius: T, rotate: T) -> Self
11 where
12 Point<T>: From<P>,
13 {
14 Self { sides, center: center.into(), radius, rotate }
15 }
16
17 pub fn vertexes(&self) -> Vec<Point<T>> {
18 let mut out = Vec::with_capacity(self.sides);
19 for i in 0..self.sides {
20 let mut vertex = self.original_vertexes(i);
21 vertex.rotate(&self.rotate);
22 vertex.translate(&self.center.x, &self.center.y);
23 out.push(vertex)
24 }
25 out
26 }
27 fn original_vertexes(&self, _index: usize) -> Point<T> {
28 todo!()
29 }
30 pub fn height(&self) -> T {
31 todo!()
32 }
33 pub fn perimeter(&self) -> T {
34 self.side_length() * T::from(self.sides).unwrap()
35 }
36 pub fn central_angle(&self) -> T {
38 todo!()
39 }
40 pub fn side_length(&self) -> T {
42 todo!()
43 }
44 pub fn area(&self) -> T {
46 T::from(self.sides).unwrap() * self.radius.powi(2) * self.central_angle().tan() / two()
47 }
48}
49
50impl<T> Projective<T> for RegularPolygon<T>
51where
52 T: Real + AddAssign,
53{
54 #[track_caller]
55 #[allow(unused_variables)]
56 fn transform(&mut self, matrix: &[&T; 9]) {
57 panic!("Can't keep shape after projective transform");
58 }
59 fn translate(&mut self, x: &T, y: &T) {
60 self.center.x += *x;
61 self.center.y += *y;
62 }
63 fn rotate(&mut self, angle: &T) {
64 self.rotate += *angle
65 }
66}