From e1e6b90c1b7306587aae9194c26d9f94ee2b6b6a Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sat, 13 Jul 2013 23:00:33 +1000 Subject: [PATCH] Move types related to bounding volumes to bounds module --- Makefile | 2 +- src/{geom => bounds}/aabb.rs | 12 ++++++++---- src/bounds/bounds.rs | 24 ++++++++++++++++++++++++ src/{geom => bounds}/box.rs | 0 src/{geom => bounds}/cylinder.rs | 0 src/{geom => bounds}/frustum.rs | 0 src/{geom => bounds}/sphere.rs | 1 + src/geom/geom.rs | 8 -------- src/lmath.rs | 4 ++++ src/transform/projection.rs | 3 ++- 10 files changed, 40 insertions(+), 14 deletions(-) rename src/{geom => bounds}/aabb.rs (85%) create mode 100644 src/bounds/bounds.rs rename src/{geom => bounds}/box.rs (100%) rename src/{geom => bounds}/cylinder.rs (100%) rename src/{geom => bounds}/frustum.rs (100%) rename src/{geom => bounds}/sphere.rs (97%) diff --git a/Makefile b/Makefile index ea1e0ac..f75ef6b 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ SRC_CRATE = $(TARGET).rs EXTERN_DIR = $(ROOT_DIR)/extern BUILD_DIR = $(ROOT_DIR)/lib -CFG = --cfg=color --cfg=geom --cfg=noise --cfg=transform --cfg=space +CFG = --cfg=bounds --cfg=color --cfg=geom --cfg=noise --cfg=transform --cfg=space TEST = $(TARGET) TEST_BUILD_DIR = $(ROOT_DIR)/test diff --git a/src/geom/aabb.rs b/src/bounds/aabb.rs similarity index 85% rename from src/geom/aabb.rs rename to src/bounds/aabb.rs index 1088854..155e8ca 100644 --- a/src/geom/aabb.rs +++ b/src/bounds/aabb.rs @@ -18,6 +18,7 @@ use core::{Vec2, AsVec2, Vec3, AsVec3}; use geom::{Point2, Point3}; +#[deriving(Clone, Eq)] pub struct AABB2 { center: Point2, size: Vec2, @@ -33,15 +34,17 @@ impl AABB2 { } impl AABB2 { - #[inline] pub fn from_bounds(mn: Point2, mx: Point2) -> AABB2 { AABB2 { - center: Point2::from_vec2(mn.as_vec2().add_v(mx.as_vec2()).div_t(two!(T))), + center: Point2::from_vec2( + mn.as_vec2().add_v(mx.as_vec2()).div_t(two!(T)) + ), size: mx - mn, } } } +#[deriving(Clone, Eq)] pub struct AABB3 { center: Point3, size: Vec3, @@ -57,10 +60,11 @@ impl AABB3 { } impl AABB3 { - #[inline] pub fn from_bounds(mn: Point3, mx: Point3) -> AABB3 { AABB3 { - center: Point3::from_vec3(mn.as_vec3().add_v(mx.as_vec3()).div_t(two!(T))), + center: Point3::from_vec3( + mn.as_vec3().add_v(mx.as_vec3()).div_t(two!(T)) + ), size: mx - mn, } } diff --git a/src/bounds/bounds.rs b/src/bounds/bounds.rs new file mode 100644 index 0000000..8c55aba --- /dev/null +++ b/src/bounds/bounds.rs @@ -0,0 +1,24 @@ +// Copyright 2013 The Lmath Developers. For a full listing of the authors, +// refer to the AUTHORS file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +pub use self::aabb::{AABB2, AABB3}; +pub use self::frustum::{Frustum, FrustumPoints}; +pub use self::sphere::Sphere; + +pub mod aabb; +pub mod box; +pub mod cylinder; +pub mod frustum; +pub mod sphere; diff --git a/src/geom/box.rs b/src/bounds/box.rs similarity index 100% rename from src/geom/box.rs rename to src/bounds/box.rs diff --git a/src/geom/cylinder.rs b/src/bounds/cylinder.rs similarity index 100% rename from src/geom/cylinder.rs rename to src/bounds/cylinder.rs diff --git a/src/geom/frustum.rs b/src/bounds/frustum.rs similarity index 100% rename from src/geom/frustum.rs rename to src/bounds/frustum.rs diff --git a/src/geom/sphere.rs b/src/bounds/sphere.rs similarity index 97% rename from src/geom/sphere.rs rename to src/bounds/sphere.rs index 1faea1b..f8c7759 100644 --- a/src/geom/sphere.rs +++ b/src/bounds/sphere.rs @@ -17,6 +17,7 @@ use geom::Point3; +#[deriving(Clone, Eq)] pub struct Sphere { center: Point3, radius: T, diff --git a/src/geom/geom.rs b/src/geom/geom.rs index 735452e..b2158b6 100644 --- a/src/geom/geom.rs +++ b/src/geom/geom.rs @@ -13,20 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub use self::aabb::{AABB2, AABB3}; -pub use self::frustum::{Frustum, FrustumPoints}; pub use self::plane::Plane3; pub use self::point::Point; pub use self::point::{Point2, AsPoint2}; pub use self::point::{Point3, AsPoint3}; pub use self::ray::{Ray2, Ray3}; -pub use self::sphere::Sphere; -pub mod aabb; -pub mod box; -pub mod cylinder; -pub mod frustum; pub mod plane; pub mod point; pub mod ray; -pub mod sphere; diff --git a/src/lmath.rs b/src/lmath.rs index 786aeed..beaadd7 100644 --- a/src/lmath.rs +++ b/src/lmath.rs @@ -32,6 +32,10 @@ mod core_macros; #[path = "core/core.rs"] pub mod core; +#[cfg(bounds)] +#[path = "bounds/bounds.rs"] +pub mod bounds; + #[cfg(color)] #[path = "color/color.rs"] pub mod color; diff --git a/src/transform/projection.rs b/src/transform/projection.rs index 176668c..f242183 100644 --- a/src/transform/projection.rs +++ b/src/transform/projection.rs @@ -13,8 +13,9 @@ // See the License for the specific language governing permissions and // limitations under the License. +use bounds::Frustum; use core::Mat4; -use geom::{Plane3, Frustum}; +use geom::Plane3; /// /// Create a perspective projection matrix