Skip to content

Commit

Permalink
v3: add interop with glam 0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
jcornaz committed Aug 18, 2023
1 parent 8765253 commit 71b072d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ default = ["std"]
std = ["glam/std", "bvh-arena?/std"]
unstable-v3 = []
unstable-v3-aabb = ["unstable-v3", "libm"]
glam-0-24 = []

[dependencies]
# Public
Expand Down
8 changes: 4 additions & 4 deletions src/v3/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ pub struct Aabb {

impl Aabb {
#[must_use]
pub fn from_size(size: Vec2) -> Self {
pub fn from_size(size: impl Into<Vec2>) -> Self {
Self {
center: Point::ORIGIN,
half_size: size / 2.0,
half_size: size.into() / 2.0,
}
}

#[must_use]
pub fn with_center_at(mut self, center: Point) -> Self {
self.center = center;
pub fn with_center_at(mut self, center: impl Into<Point>) -> Self {
self.center = center.into();
self
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/v3/interop/glam_0_24.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::v3::{Point, Vec2};
use glam;

impl From<glam::Vec2> for Vec2 {
fn from(v: glam::Vec2) -> Self {
Vec2::new(v.x, v.y)
}
}

impl From<Vec2> for glam::Vec2 {
fn from(v: Vec2) -> Self {
glam::Vec2::new(v.x, v.y)
}
}

impl From<glam::Vec2> for Point {
fn from(v: glam::Vec2) -> Self {
Self::new(v.x, v.y)
}
}

impl From<Point> for glam::Vec2 {
fn from(p: Point) -> Self {
glam::Vec2::new(p.x(), p.y())
}
}
2 changes: 2 additions & 0 deletions src/v3/interop/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(feature = "glam-0-24")]
mod glam_0_24;
1 change: 1 addition & 0 deletions src/v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use vector::Vec2;

#[cfg(feature = "unstable-v3-aabb")]
mod aabb;
mod interop;
mod point;
mod range;
mod vector;
Expand Down

0 comments on commit 71b072d

Please sign in to comment.