Skip to main content

fyrox_core/math/
mod.rs

1// Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in all
11// copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19// SOFTWARE.
20
21// Clippy complains about normal mathematical symbols like A, B, C for quadratic equation.
22#![allow(clippy::many_single_char_names)]
23
24pub use fyrox_math::*;
25
26use crate::math::curve::Curve;
27use crate::math::curve::CurveKey;
28use crate::math::curve::CurveKeyKind;
29use crate::{
30    algebra::Scalar,
31    math::{aabb::AxisAlignedBoundingBox, frustum::Frustum, plane::Plane},
32    num_traits::NumAssign,
33    reflect::prelude::*,
34    visitor::prelude::*,
35};
36use fyrox_core_derive::{impl_reflect, impl_visit};
37use std::fmt::Debug;
38
39impl_reflect!(
40    pub struct Rect<T: Debug + Copy> {}
41);
42
43impl<T> Visit for Rect<T>
44where
45    T: NumAssign + Scalar + Visit + PartialOrd + Copy + 'static,
46{
47    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
48        let mut region = visitor.enter_region(name)?;
49
50        self.position.x.visit("X", &mut region)?;
51        self.position.y.visit("Y", &mut region)?;
52        self.size.x.visit("W", &mut region)?;
53        self.size.y.visit("H", &mut region)?;
54
55        Ok(())
56    }
57}
58
59impl Visit for TriangleDefinition {
60    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
61        let mut region = visitor.enter_region(name)?;
62
63        self.0[0].visit("A", &mut region)?;
64        self.0[1].visit("B", &mut region)?;
65        self.0[2].visit("C", &mut region)?;
66
67        Ok(())
68    }
69}
70
71impl Visit for AxisAlignedBoundingBox {
72    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
73        let mut region = visitor.enter_region(name)?;
74
75        self.min.visit("Min", &mut region)?;
76        self.max.visit("Max", &mut region)?;
77
78        Ok(())
79    }
80}
81
82impl Visit for Frustum {
83    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
84        let mut region = visitor.enter_region(name)?;
85
86        self.planes[0].visit("Left", &mut region)?;
87        self.planes[1].visit("Right", &mut region)?;
88        self.planes[2].visit("Top", &mut region)?;
89        self.planes[3].visit("Bottom", &mut region)?;
90        self.planes[4].visit("Far", &mut region)?;
91        self.planes[5].visit("Near", &mut region)?;
92
93        Ok(())
94    }
95}
96
97impl Visit for Plane {
98    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
99        let mut region = visitor.enter_region(name)?;
100
101        self.normal.visit("Normal", &mut region)?;
102        self.d.visit("D", &mut region)?;
103
104        Ok(())
105    }
106}
107
108impl_reflect!(
109    pub struct TriangleDefinition(pub [u32; 3]);
110);
111
112impl_visit!(
113    pub struct SmoothAngle {
114        angle: f32,
115        target: f32,
116        speed: f32,
117    }
118);
119
120impl_reflect!(
121    pub struct SmoothAngle {
122        angle: f32,
123        target: f32,
124        speed: f32,
125    }
126);
127
128impl_reflect!(
129    pub enum CurveKeyKind {
130        Constant,
131        Linear,
132        Cubic {
133            left_tangent: f32,
134            right_tangent: f32,
135        },
136    }
137);
138
139impl_visit!(
140    pub enum CurveKeyKind {
141        Constant,
142        Linear,
143        Cubic {
144            left_tangent: f32,
145            right_tangent: f32,
146        },
147    }
148);
149
150impl_visit!(
151    pub struct CurveKey {
152        pub id: Uuid,
153        location: f32,
154        pub value: f32,
155        pub kind: CurveKeyKind,
156    }
157);
158
159impl_reflect!(
160    #[reflect(hide_all)]
161    pub struct Curve {
162        pub id: Uuid,
163        pub name: String,
164        pub keys: Vec<CurveKey>,
165    }
166);
167
168impl_visit!(
169    pub struct Curve {
170        pub id: Uuid,
171        pub name: String,
172        pub keys: Vec<CurveKey>,
173    }
174);