Skip to content

Commit feab0c8

Browse files
committed
Suggested review changes
1 parent 45ba723 commit feab0c8

File tree

1 file changed

+27
-30
lines changed
  • crates/bevy_geometry/src

1 file changed

+27
-30
lines changed

crates/bevy_geometry/src/lib.rs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ pub struct Sphere {
3939

4040
impl Sphere {
4141
/// Get a reference to the sphere's origin.
42-
pub fn origin(&self) -> &Vec3 {
43-
&self.origin
42+
pub fn origin(&self) -> Vec3 {
43+
self.origin
4444
}
4545

4646
/// Get a reference to the sphere's radius.
47-
pub fn radius(&self) -> &f32 {
48-
&self.radius
47+
pub fn radius(&self) -> f32 {
48+
self.radius
4949
}
5050

5151
/// Set the sphere's origin.
@@ -62,29 +62,29 @@ impl Primitive3d for Sphere {
6262
/// Use the sphere's position and radius to determin eif it is entirely on the outside of the
6363
/// the supplied plane.
6464
fn outside_plane(&self, plane: Plane) -> bool {
65-
plane.distance_to_point(&self.origin) > self.radius
65+
plane.distance_to_point(self.origin) > self.radius
6666
}
6767
}
6868

6969
/// An oriented box, unlike an axis aligned box, can be rotated and is not constrained to match the
7070
/// orientation of the coordinate system it is defined in. Internally, this is represented as an
7171
/// axis aligned box with some rotation ([Quat]) applied.
7272
#[derive(Copy, Clone, PartialEq, Debug, Reflect)]
73-
pub struct OrientedBox {
74-
aab: AxisAlignedBox,
73+
pub struct OBB {
74+
aab: AABB,
7575
transform: Mat4,
7676
}
77-
impl Primitive3d for OrientedBox {
77+
impl Primitive3d for OBB {
7878
fn outside_plane(&self, plane: Plane) -> bool {
7979
for vertex in self.vertices().iter() {
80-
if plane.distance_to_point(vertex) <= 0.0 {
80+
if plane.distance_to_point(*vertex) <= 0.0 {
8181
return false;
8282
}
8383
}
8484
true
8585
}
8686
}
87-
impl OrientedBox {
87+
impl OBB {
8888
/// An ordered list of the vertices that form the 8 corners of the [AxisAlignedBox].
8989
/// ```none
9090
/// (5)------(1)
@@ -105,15 +105,15 @@ impl OrientedBox {
105105
}
106106

107107
/// Set the oriented box's aab.
108-
pub fn set_aab(&mut self, aab: AxisAlignedBox) {
108+
pub fn set_aabb(&mut self, aab: AABB) {
109109
self.aab = aab;
110110
}
111111

112112
/// Set the oriented box's transform.
113113
pub fn set_transform(&mut self, transform: Mat4) {
114114
self.transform = transform;
115115
}
116-
pub fn fast_aabb(&self) -> AxisAlignedBox {
116+
pub fn fast_aabb(&self) -> AABB {
117117
let vertices = self.vertices();
118118
let mut max = Vec3::splat(f32::MIN);
119119
let mut min = Vec3::splat(f32::MAX);
@@ -122,18 +122,18 @@ impl OrientedBox {
122122
min = vertex.min(min);
123123
}
124124
// Unwrap is okay here because min < max
125-
AxisAlignedBox::from_min_max(min, max).unwrap()
125+
AABB::from_min_max(min, max).unwrap()
126126
}
127127
}
128128

129129
/// An axis aligned box is a box whose axes lie in the x/y/z directions of the coordinate system
130130
/// the box is defined in.
131131
#[derive(Copy, Clone, PartialEq, Debug, Reflect)]
132-
pub struct AxisAlignedBox {
132+
pub struct AABB {
133133
min: Vec3,
134134
max: Vec3,
135135
}
136-
impl Primitive3d for AxisAlignedBox {
136+
impl Primitive3d for AABB {
137137
fn outside_plane(&self, plane: Plane) -> bool {
138138
for vertex in self.vertices().iter() {
139139
if plane.distance_to_point(vertex) <= 0.0 {
@@ -143,7 +143,7 @@ impl Primitive3d for AxisAlignedBox {
143143
true
144144
}
145145
}
146-
impl AxisAlignedBox {
146+
impl AABB {
147147
/// An ordered list of the vertices that form the 8 corners of the [AxisAlignedBox].
148148
/// ```none
149149
/// (5)------(1) Y
@@ -169,21 +169,18 @@ impl AxisAlignedBox {
169169
]
170170
}
171171
/// Construct an [AxisAlignedBox] given the coordinates of the minimum and maximum corners.
172-
pub fn from_min_max(min: Vec3, max: Vec3) -> Result<AxisAlignedBox, PrimitiveError> {
172+
pub fn from_min_max(min: Vec3, max: Vec3) -> Result<AABB, PrimitiveError> {
173173
if (max - min).min_element() >= 0.0 {
174-
Ok(AxisAlignedBox { min, max })
174+
Ok(AABB { min, max })
175175
} else {
176176
Err(PrimitiveError::MinGreaterThanMax)
177177
}
178178
}
179179
/// Construct an [AxisALignedBox] from the origin at the minimum corner, and the extents - the
180180
/// dimensions of the box in each axis.
181-
pub fn from_extents_origin(
182-
extents: Vec3,
183-
origin: Vec3,
184-
) -> Result<AxisAlignedBox, PrimitiveError> {
181+
pub fn from_extents_origin(extents: Vec3, origin: Vec3) -> Result<AABB, PrimitiveError> {
185182
if extents.min_element() > 0.0 {
186-
Ok(AxisAlignedBox {
183+
Ok(AABB {
187184
min: origin,
188185
max: extents + origin,
189186
})
@@ -192,15 +189,15 @@ impl AxisAlignedBox {
192189
}
193190
}
194191
/// Computes the AAB that
195-
pub fn from_points(points: Vec<Vec3>) -> AxisAlignedBox {
192+
pub fn from_points(points: &[Vec3]) -> AABB {
196193
let mut max = Vec3::splat(f32::MIN);
197194
let mut min = Vec3::splat(f32::MAX);
198195
for &point in points.iter() {
199196
max = point.max(max);
200197
min = point.min(min);
201198
}
202199
// Unwrap is okay here because min < max
203-
AxisAlignedBox::from_min_max(min, max).unwrap()
200+
AABB::from_min_max(min, max).unwrap()
204201
}
205202
}
206203

@@ -223,8 +220,8 @@ impl Primitive3d for Frustum {
223220
}
224221
}
225222
impl Frustum {
226-
fn compute_vertices(camera_position: Mat4, projection_matrix: Mat4) -> [Vec3; 8] {
227-
let ndc_to_world: Mat4 = camera_position * projection_matrix.inverse();
223+
fn compute_vertices(camera_position: &Mat4, projection_matrix: &Mat4) -> [Vec3; 8] {
224+
let ndc_to_world: Mat4 = *camera_position * projection_matrix.inverse();
228225
[
229226
ndc_to_world.project_point3(Vec3::new(-1.0, -1.0, -1.0)),
230227
ndc_to_world.project_point3(Vec3::new(1.0, -1.0, -1.0)),
@@ -237,7 +234,7 @@ impl Frustum {
237234
]
238235
}
239236

240-
pub fn from_camera_properties(camera_position: Mat4, projection_matrix: Mat4) -> Frustum {
237+
pub fn from_camera_properties(camera_position: &Mat4, projection_matrix: &Mat4) -> Frustum {
241238
let vertices = Frustum::compute_vertices(camera_position, projection_matrix);
242239
let [nbl_world, nbr_world, ntl_world, ntr_world, fbl_world, fbr_world, ftl_world, ftr_world] =
243240
vertices;
@@ -343,8 +340,8 @@ impl Plane {
343340
/// Returns the nearest distance from the supplied point to this plane. Positive values are in
344341
/// the direction of the plane's normal (outside), negative values are opposite the direction
345342
/// of the planes normal (inside).
346-
pub fn distance_to_point(&self, point: &Vec3) -> f32 {
347-
self.normal.dot(*point) + -self.normal.dot(self.point)
343+
pub fn distance_to_point(&self, point: Vec3) -> f32 {
344+
self.normal.dot(point) + -self.normal.dot(self.point)
348345
}
349346

350347
/// Get a reference to the plane's point.

0 commit comments

Comments
 (0)