bevy_math/primitives/mod.rs
1//! This module defines primitive shapes.
2//! The origin is (0, 0) for 2D primitives and (0, 0, 0) for 3D primitives,
3//! unless stated otherwise.
4
5mod dim2;
6pub use dim2::*;
7mod dim3;
8pub use dim3::*;
9mod polygon;
10#[cfg(feature = "serialize")]
11mod serde;
12
13/// A marker trait for 2D primitives
14pub trait Primitive2d {}
15
16/// A marker trait for 3D primitives
17pub trait Primitive3d {}
18
19/// The winding order for a set of points
20#[derive(Clone, Copy, Debug, PartialEq, Eq)]
21#[doc(alias = "Orientation")]
22pub enum WindingOrder {
23 /// A clockwise winding order
24 Clockwise,
25 /// A counterclockwise winding order
26 #[doc(alias = "AntiClockwise")]
27 CounterClockwise,
28 /// An invalid winding order indicating that it could not be computed reliably.
29 /// This often happens in *degenerate cases* where the points lie on the same line
30 #[doc(alias("Degenerate", "Collinear"))]
31 Invalid,
32}
33
34/// A trait for getting measurements of 2D shapes
35pub trait Measured2d {
36 /// Get the perimeter of the shape
37 fn perimeter(&self) -> f32;
38
39 /// Get the area of the shape
40 fn area(&self) -> f32;
41}
42
43/// A trait for getting measurements of 3D shapes
44pub trait Measured3d {
45 /// Get the surface area of the shape
46 fn area(&self) -> f32;
47
48 /// Get the volume of the shape
49 fn volume(&self) -> f32;
50}