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::Uuid;
30use crate::{
31    algebra::Scalar,
32    math::{aabb::AxisAlignedBoundingBox, frustum::Frustum, plane::Plane},
33    num_traits::NumAssign,
34    reflect::prelude::*,
35    visitor::prelude::*,
36};
37use fyrox_core_derive::{impl_reflect, impl_visit};
38use std::fmt::Debug;
39
40impl_reflect!(
41    pub struct Rect<T: Debug> {}
42);
43
44impl<T> Visit for Rect<T>
45where
46    T: NumAssign + Scalar + Visit + PartialOrd + Copy + 'static,
47{
48    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
49        let mut region = visitor.enter_region(name)?;
50
51        self.position.x.visit("X", &mut region)?;
52        self.position.y.visit("Y", &mut region)?;
53        self.size.x.visit("W", &mut region)?;
54        self.size.y.visit("H", &mut region)?;
55
56        Ok(())
57    }
58}
59
60impl Visit for TriangleDefinition {
61    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
62        let mut region = visitor.enter_region(name)?;
63
64        self.0[0].visit("A", &mut region)?;
65        self.0[1].visit("B", &mut region)?;
66        self.0[2].visit("C", &mut region)?;
67
68        Ok(())
69    }
70}
71
72impl Visit for AxisAlignedBoundingBox {
73    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
74        let mut region = visitor.enter_region(name)?;
75
76        self.min.visit("Min", &mut region)?;
77        self.max.visit("Max", &mut region)?;
78
79        Ok(())
80    }
81}
82
83impl Visit for Frustum {
84    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
85        let mut region = visitor.enter_region(name)?;
86
87        self.planes[0].visit("Left", &mut region)?;
88        self.planes[1].visit("Right", &mut region)?;
89        self.planes[2].visit("Top", &mut region)?;
90        self.planes[3].visit("Bottom", &mut region)?;
91        self.planes[4].visit("Far", &mut region)?;
92        self.planes[5].visit("Near", &mut region)?;
93
94        Ok(())
95    }
96}
97
98impl Visit for Plane {
99    fn visit(&mut self, name: &str, visitor: &mut Visitor) -> VisitResult {
100        let mut region = visitor.enter_region(name)?;
101
102        self.normal.visit("Normal", &mut region)?;
103        self.d.visit("D", &mut region)?;
104
105        Ok(())
106    }
107}
108
109impl_reflect!(
110    pub struct TriangleDefinition(pub [u32; 3]);
111);
112
113impl_visit!(
114    pub struct SmoothAngle {
115        angle: f32,
116        target: f32,
117        speed: f32,
118    }
119);
120
121impl_reflect!(
122    pub struct SmoothAngle {
123        angle: f32,
124        target: f32,
125        speed: f32,
126    }
127);
128
129impl_reflect!(
130    pub enum CurveKeyKind {
131        Constant,
132        Linear,
133        Cubic {
134            left_tangent: f32,
135            right_tangent: f32,
136        },
137    }
138);
139
140impl_visit!(
141    pub enum CurveKeyKind {
142        Constant,
143        Linear,
144        Cubic {
145            left_tangent: f32,
146            right_tangent: f32,
147        },
148    }
149);
150
151impl_visit!(
152    pub struct CurveKey {
153        pub id: Uuid,
154        location: f32,
155        pub value: f32,
156        pub kind: CurveKeyKind,
157    }
158);
159
160impl_reflect!(
161    #[reflect(hide_all)]
162    pub struct Curve {
163        pub id: Uuid,
164        pub name: String,
165        pub keys: Vec<CurveKey>,
166    }
167);
168
169impl_visit!(
170    pub struct Curve {
171        #[visit(optional)] // Backward compatibility
172        pub id: Uuid,
173        #[visit(optional)] // Backward compatibility
174        pub name: String,
175        pub keys: Vec<CurveKey>,
176    }
177);