lib_jsl_geometry/
dim_2.rs1use lib_jsl_core::ErrorsJSL;
4pub mod line2d;
6pub mod free_vector2d;
8pub(crate) mod coordinate_conversions;
10pub mod mesh2d;
12pub mod coordinate_vector2d;
14pub mod plane2d;
16pub mod polygon_face2d;
18pub(crate) mod transform_support;
20pub mod triangle2d;
22pub mod unit_vector2d;
24
25use crate::common::{
26 GeometricPrimitive, GeometryMeasure, HasCentroid, HasCenter, HasEdges, HasMeasure,
27 HasVertices, IsPlane, PointId,
28};
29use crate::common::IsUnitVector;
30use crate::transformation_traits::{CanMirror, CanRotate, CanShear, CanTranslate};
31use crate::zero_d::IsPoint;
32pub use line2d::Line2D;
33pub use free_vector2d::FreeVector2D;
34pub use mesh2d::Mesh2D;
35pub use plane2d::Plane2D;
36pub use coordinate_vector2d::CoordinateVector2D;
37pub use polygon_face2d::PolygonFace2D;
38pub use triangle2d::Triangle2D;
39pub use unit_vector2d::UnitVector2D;
40
41#[derive(Debug, Clone, Copy, PartialEq, Eq)]
43
44pub enum Orientation2D {
45 Clockwise,
47 CounterClockwise,
49 Collinear,
51}
52
53pub trait HasOrientation {
55 fn orientation(&self) -> Orientation2D;
57}
58
59pub trait IsTriangle<'a, T: IsPoint, N: IsUnitVector>: IsPolygon<'a, T, N> {
61 fn a_id(&self) -> PointId;
63 fn set_a_id(&mut self, point_id: PointId) -> Result<(), ErrorsJSL>;
65 fn b_id(&self) -> PointId;
67 fn set_b_id(&mut self, point_id: PointId) -> Result<(), ErrorsJSL>;
69 fn c_id(&self) -> PointId;
71 fn set_c_id(&mut self, point_id: PointId) -> Result<(), ErrorsJSL>;
73
74 fn a(&self) -> Option<T> {
76 self.get_vertex(&self.a_id())
77 }
78
79 fn b(&self) -> Option<T> {
81 self.get_vertex(&self.b_id())
82 }
83
84 fn c(&self) -> Option<T> {
86 self.get_vertex(&self.c_id())
87 }
88
89 fn edge_ab(&self) -> Option<<Self as HasEdges>::Edge> {
91 self.edge(0)
92 }
93 fn edge_bc(&self) -> Option<<Self as HasEdges>::Edge> {
95 self.edge(1)
96 }
97 fn edge_ca(&self) -> Option<<Self as HasEdges>::Edge> {
99 self.edge(2)
100 }
101}
102
103pub trait IsPolygon<'a, T: IsPoint, N: IsUnitVector>:
105 GeometricPrimitive
106 + HasVertices<'a, Vertex = T>
107 + HasEdges
108 + CanTranslate<Point = T>
109 + CanRotate<Point = T>
110 + CanShear<Point = T>
111 + CanMirror<Point = T, Normal = N>
112 + HasCentroid<Point = T>
113 + HasMeasure
114 + HasOrientation
115{
116 fn vertex_ids(&self) -> Box<dyn Iterator<Item = PointId> + '_>;
118 fn set_vertex_id(&mut self, index: usize, point_id: PointId) -> Result<(), ErrorsJSL>;
120
121 fn normal(&self) -> N;
123 fn perimeter(&self) -> GeometryMeasure;
125 fn area(&self) -> GeometryMeasure;
127 fn plane(&self) -> impl IsPlane<Point = T, Normal = N>;
129}
130
131pub trait IsRectangle<'a, T: IsPoint, N: IsUnitVector>: IsPolygon<'a, T, N> {
133 fn width(&self) -> GeometryMeasure;
135 fn height(&self) -> GeometryMeasure;
137 fn diagonal(&self) -> GeometryMeasure;
139}
140
141pub trait IsCircle<T: IsPoint>: GeometricPrimitive + HasCenter<Point = T> + HasMeasure {
143 fn radius(&self) -> GeometryMeasure;
145 fn diameter(&self) -> GeometryMeasure;
147 fn circumference(&self) -> GeometryMeasure;
149 fn area(&self) -> GeometryMeasure;
151}