Skip to content

Commit e46108b

Browse files
authored
Add From impls for Aabb and Aabb3d (#21307)
# Objective - i want to write functions that are generic over aabb type by taking impl Into<Aabb> as a parameter ## Solution - impl From ## Testing -
1 parent d54545b commit e46108b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

crates/bevy_camera/src/primitives.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use core::borrow::Borrow;
22

33
use bevy_ecs::{component::Component, entity::EntityHashMap, reflect::ReflectComponent};
4-
use bevy_math::{Affine3A, Mat3A, Mat4, Vec3, Vec3A, Vec4, Vec4Swizzles};
4+
use bevy_math::{
5+
bounding::{Aabb3d, BoundingVolume},
6+
Affine3A, Mat3A, Mat4, Vec3, Vec3A, Vec4, Vec4Swizzles,
7+
};
58
use bevy_mesh::{Mesh, VertexAttributeValues};
69
use bevy_reflect::prelude::*;
710

@@ -132,6 +135,24 @@ impl Aabb {
132135
}
133136
}
134137

138+
impl From<Aabb3d> for Aabb {
139+
fn from(aabb: Aabb3d) -> Self {
140+
Self {
141+
center: aabb.center(),
142+
half_extents: aabb.half_size(),
143+
}
144+
}
145+
}
146+
147+
impl From<Aabb> for Aabb3d {
148+
fn from(aabb: Aabb) -> Self {
149+
Self {
150+
min: aabb.min(),
151+
max: aabb.max(),
152+
}
153+
}
154+
}
155+
135156
impl From<Sphere> for Aabb {
136157
#[inline]
137158
fn from(sphere: Sphere) -> Self {

0 commit comments

Comments
 (0)