From d5514fc982bc8871532325039fb82e53669a5417 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Sun, 14 Jul 2013 11:44:50 +1000 Subject: [PATCH] Move contents of geom and core modules into new math module Having these two modules separate made more sense when the library was divided into lmath and cgmath. Now that the two have been combined, it makes more sense to bundle these types in one module (I think). --- Makefile | 2 +- src/bounds/aabb.rs | 3 +-- src/bounds/bounds.rs | 2 ++ src/bounds/box.rs | 18 +++++++++++++++++- src/bounds/cylinder.rs | 11 ++++++++++- src/bounds/frustum.rs | 5 +++-- src/bounds/sphere.rs | 2 +- src/color/hsv.rs | 2 +- src/color/rgb.rs | 2 +- src/color/srgb.rs | 2 +- src/color/ycbcr.rs | 2 +- src/geom/geom.rs | 24 ------------------------ src/lmath.rs | 12 ++++-------- src/{core => math}/macros.rs | 0 src/{core => math}/mat.rs | 20 +++++++++++--------- src/{core/core.rs => math/math.rs} | 10 ++++++++++ src/{geom => math}/plane.rs | 12 ++++++------ src/{geom => math}/point.rs | 14 ++++++++------ src/{core => math}/quat.rs | 14 ++++++++------ src/{geom => math}/ray.rs | 6 +++--- src/{core => math}/vec.rs | 10 ++++++---- src/noise/perlin.rs | 2 +- src/noise/simplex.rs | 4 ++-- src/transform/projection.rs | 4 ++-- src/transform/transform.rs | 2 +- 25 files changed, 101 insertions(+), 84 deletions(-) delete mode 100644 src/geom/geom.rs rename src/{core => math}/macros.rs (100%) rename src/{core => math}/mat.rs (99%) rename src/{core/core.rs => math/math.rs} (88%) rename src/{geom => math}/plane.rs (97%) rename src/{geom => math}/point.rs (97%) rename src/{core => math}/quat.rs (98%) rename src/{geom => math}/ray.rs (95%) rename src/{core => math}/vec.rs (99%) diff --git a/Makefile b/Makefile index f75ef6b..06848f0 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=bounds --cfg=color --cfg=geom --cfg=noise --cfg=transform --cfg=space +CFG = --cfg=bounds --cfg=color --cfg=noise --cfg=transform --cfg=space TEST = $(TARGET) TEST_BUILD_DIR = $(ROOT_DIR)/test diff --git a/src/bounds/aabb.rs b/src/bounds/aabb.rs index c063ff8..b29f792 100644 --- a/src/bounds/aabb.rs +++ b/src/bounds/aabb.rs @@ -15,8 +15,7 @@ //! Axis-aligned bounding boxes -use core::*; -use geom::*; +use math::*; #[deriving(Clone, Eq)] pub struct AABB2 { diff --git a/src/bounds/bounds.rs b/src/bounds/bounds.rs index 8c55aba..884e4f2 100644 --- a/src/bounds/bounds.rs +++ b/src/bounds/bounds.rs @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +//! Bounding volumes + pub use self::aabb::{AABB2, AABB3}; pub use self::frustum::{Frustum, FrustumPoints}; pub use self::sphere::Sphere; diff --git a/src/bounds/box.rs b/src/bounds/box.rs index 0bed11c..842e335 100644 --- a/src/bounds/box.rs +++ b/src/bounds/box.rs @@ -13,4 +13,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Bounding boxes +//! Oriented bounding boxes + +use math::*; + +#[deriving(Clone, Eq)] +pub struct Box2 { + center: Point2, + axis: Vec2, + extents: Vec2, +} + +#[deriving(Clone, Eq)] +pub struct Box3 { + center: Point3, + axis: Vec3, + extents: Vec3, +} diff --git a/src/bounds/cylinder.rs b/src/bounds/cylinder.rs index 9459784..e749ab0 100644 --- a/src/bounds/cylinder.rs +++ b/src/bounds/cylinder.rs @@ -13,4 +13,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Bounding cylinder +//! Oriented bounding cylinder + +use math::*; + +#[deriving(Clone, Eq)] +pub struct Cylinder3 { + center: Point3, + axis: Vec3, + radius: T, +} diff --git a/src/bounds/frustum.rs b/src/bounds/frustum.rs index 58ed7c2..2dc97aa 100644 --- a/src/bounds/frustum.rs +++ b/src/bounds/frustum.rs @@ -13,8 +13,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::*; -use geom::*; +//! View frustum for visibility determination + +use math::*; #[deriving(Clone, Eq)] pub struct Frustum { diff --git a/src/bounds/sphere.rs b/src/bounds/sphere.rs index 7355e72..bc45876 100644 --- a/src/bounds/sphere.rs +++ b/src/bounds/sphere.rs @@ -15,7 +15,7 @@ //! Bounding sphere -use geom::*; +use math::*; #[deriving(Clone, Eq)] pub struct Sphere { diff --git a/src/color/hsv.rs b/src/color/hsv.rs index ef8687f..66c3a83 100644 --- a/src/color/hsv.rs +++ b/src/color/hsv.rs @@ -16,7 +16,7 @@ use std::num; use std::cast; -use core::*; +use math::*; use color::{Color, FloatColor}; use color::{Channel, FloatChannel}; diff --git a/src/color/rgb.rs b/src/color/rgb.rs index 2a5456f..7a96458 100644 --- a/src/color/rgb.rs +++ b/src/color/rgb.rs @@ -16,7 +16,7 @@ use std::num; use std::cast; -use core::*; +use math::*; use color::{Color, FloatColor}; use color::{Channel, FloatChannel}; diff --git a/src/color/srgb.rs b/src/color/srgb.rs index f222851..bd2d895 100644 --- a/src/color/srgb.rs +++ b/src/color/srgb.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::*; +use math::*; #[deriving(Clone, Eq)] pub struct SRGB { r: T, g: T, b: T } diff --git a/src/color/ycbcr.rs b/src/color/ycbcr.rs index ebfc3a3..c782ac5 100644 --- a/src/color/ycbcr.rs +++ b/src/color/ycbcr.rs @@ -15,7 +15,7 @@ // http://en.wikipedia.org/wiki/YCbCr -use core::*; +use math::*; #[deriving(Clone, Eq)] pub struct YCbCr { y: T, cb: T, cr: T } diff --git a/src/geom/geom.rs b/src/geom/geom.rs deleted file mode 100644 index b2158b6..0000000 --- a/src/geom/geom.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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::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 mod plane; -pub mod point; -pub mod ray; diff --git a/src/lmath.rs b/src/lmath.rs index beaadd7..416e253 100644 --- a/src/lmath.rs +++ b/src/lmath.rs @@ -26,11 +26,11 @@ // Macros mod macros; -#[path = "core/macros.rs"] -mod core_macros; +#[path = "math/macros.rs"] +mod math_macros; -#[path = "core/core.rs"] -pub mod core; +#[path = "math/math.rs"] +pub mod math; #[cfg(bounds)] #[path = "bounds/bounds.rs"] @@ -40,10 +40,6 @@ pub mod bounds; #[path = "color/color.rs"] pub mod color; -#[cfg(geom)] -#[path = "geom/geom.rs"] -pub mod geom; - #[cfg(noise)] #[path = "noise/noise.rs"] pub mod noise; diff --git a/src/core/macros.rs b/src/math/macros.rs similarity index 100% rename from src/core/macros.rs rename to src/math/macros.rs diff --git a/src/core/mat.rs b/src/math/mat.rs similarity index 99% rename from src/core/mat.rs rename to src/math/mat.rs index 7a4c5ec..146f609 100644 --- a/src/core/mat.rs +++ b/src/math/mat.rs @@ -13,9 +13,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::{Dimensional, Swap}; -use core::{Quat, ToQuat}; -use core::{Vec2, Vec3, Vec4}; +//! Matrix types + +use math::{Dimensional, Swap}; +use math::{Quat, ToQuat}; +use math::{Vec2, Vec3, Vec4}; pub trait Mat: Dimensional + Swap { pub fn col<'a>(&'a self, i: uint) -> &'a Vec; @@ -330,8 +332,8 @@ impl FloatMat,[Vec3,..3]> for Mat2 { #[cfg(test)] mod mat2_tests{ - use core::mat::*; - use core::vec::*; + use math::mat::*; + use math::vec::*; static A: Mat2 = Mat2 { x: Vec2 { x: 1.0, y: 3.0 }, y: Vec2 { x: 2.0, y: 4.0 } }; @@ -950,8 +952,8 @@ impl FloatMat,[Vec4,..4]> for Mat3 { #[cfg(test)] mod mat3_tests{ - use core::mat::*; - use core::vec::*; + use math::mat::*; + use math::vec::*; static A: Mat3 = Mat3 { x: Vec3 { x: 1.0, y: 4.0, z: 7.0 }, y: Vec3 { x: 2.0, y: 5.0, z: 8.0 }, @@ -1546,8 +1548,8 @@ impl FloatMat,[Vec4,..4]> for Mat4 { #[cfg(test)] mod mat4_tests { - use core::mat::*; - use core::vec::*; + use math::mat::*; + use math::vec::*; static A: Mat4 = Mat4 { x: Vec4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 }, y: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 }, diff --git a/src/core/core.rs b/src/math/math.rs similarity index 88% rename from src/core/core.rs rename to src/math/math.rs index b1d7274..7f16264 100644 --- a/src/core/core.rs +++ b/src/math/math.rs @@ -26,10 +26,20 @@ pub use self::vec::{Vec2, ToVec2, AsVec2}; pub use self::vec::{Vec3, ToVec3, AsVec3}; pub use self::vec::{Vec4, ToVec4, AsVec4}; +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 mod mat; pub mod quat; pub mod vec; +pub mod plane; +pub mod point; +pub mod ray; + pub trait Dimensional { pub fn index<'a>(&'a self, i: uint) -> &'a T; pub fn index_mut<'a>(&'a mut self, i: uint) -> &'a mut T; diff --git a/src/geom/plane.rs b/src/math/plane.rs similarity index 97% rename from src/geom/plane.rs rename to src/math/plane.rs index 1b95c18..49cac67 100644 --- a/src/geom/plane.rs +++ b/src/math/plane.rs @@ -13,11 +13,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::*; +//! Three-dimensional plane type -use geom::Point; -use geom::Point3; -use geom::Ray3; +use math::{Vec3, Vec4, Mat3}; +use math::{Point, Point3}; +use math::Ray3; /// A plane formed from the equation: `Ax + Bx + Cx + D = 0` /// @@ -157,8 +157,8 @@ impl ToStr for Plane3 { #[cfg(test)] mod tests { - use geom::plane::*; - use geom::point::*; + use math::plane::*; + use math::point::*; #[test] fn test_from_3p() { diff --git a/src/geom/point.rs b/src/math/point.rs similarity index 97% rename from src/geom/point.rs rename to src/math/point.rs index e3db3e0..56fe160 100644 --- a/src/geom/point.rs +++ b/src/math/point.rs @@ -22,10 +22,12 @@ use std::cast; -use core::*; - -use geom::Ray2; -use geom::Ray3; +use math::{Dimensional, Swap}; +use math::{Mat2, Mat3, Quat}; +use math::{Ray2, Ray3}; +use math::{Vec2, ToVec2, AsVec2}; +use math::{Vec3, ToVec3, AsVec3}; +use math::{Vec4, ToVec4}; /// A geometric point pub trait Point: Eq @@ -174,7 +176,7 @@ impl ToStr for Point2 { #[cfg(test)] mod test_point2 { - use geom::point::*; + use math::point::*; #[test] fn test_to_str() { @@ -317,7 +319,7 @@ impl ToStr for Point3 { #[cfg(test)] mod test_point3 { - use geom::point::*; + use math::point::*; #[test] fn test_to_str() { diff --git a/src/core/quat.rs b/src/math/quat.rs similarity index 98% rename from src/core/quat.rs rename to src/math/quat.rs index df18a2f..65b6668 100644 --- a/src/core/quat.rs +++ b/src/math/quat.rs @@ -13,9 +13,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::{Dimensional, Swap}; -use core::{Mat3, ToMat3}; -use core::Vec3; +//! Quaternion type + +use math::{Dimensional, Swap}; +use math::{Mat3, ToMat3}; +use math::Vec3; // GLSL-style type aliases @@ -306,9 +308,9 @@ impl Quat { #[cfg(test)] mod tests { - use core::mat::*; - use core::quat::*; - use core::vec::*; + use math::mat::*; + use math::quat::*; + use math::vec::*; #[test] fn test_from_angle_axis() { diff --git a/src/geom/ray.rs b/src/math/ray.rs similarity index 95% rename from src/geom/ray.rs rename to src/math/ray.rs index d793d30..c12d6f2 100644 --- a/src/geom/ray.rs +++ b/src/math/ray.rs @@ -13,10 +13,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::*; +//! Ray types -use geom::Point2; -use geom::Point3; +use math::{Point2, Point3}; +use math::{Vec2, Vec3}; #[deriving(Clone, Eq)] pub struct Ray2 { diff --git a/src/core/vec.rs b/src/math/vec.rs similarity index 99% rename from src/core/vec.rs rename to src/math/vec.rs index cb82ba8..ba316d2 100644 --- a/src/core/vec.rs +++ b/src/math/vec.rs @@ -13,7 +13,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::{Dimensional, Swap}; +//! Abstract vector types + +use math::{Dimensional, Swap}; pub trait Vec: Dimensional + Swap {} @@ -495,7 +497,7 @@ impl> Not> for Vec2 { #[cfg(test)] mod vec2_tests { - use core::vec::*; + use math::vec::*; static A: Vec2 = Vec2 { x: 1.0, y: 2.0 }; static B: Vec2 = Vec2 { x: 3.0, y: 4.0 }; @@ -1086,7 +1088,7 @@ impl> Not> for Vec3 { #[cfg(test)] mod vec3_tests{ - use core::vec::*; + use math::vec::*; static A: Vec3 = Vec3 { x: 1.0, y: 2.0, z: 3.0 }; static B: Vec3 = Vec3 { x: 4.0, y: 5.0, z: 6.0 }; @@ -1705,7 +1707,7 @@ impl> Not> for Vec4 { #[cfg(test)] mod vec4_tests { - use core::vec::*; + use math::vec::*; static A: Vec4 = Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 }; static B: Vec4 = Vec4 { x: 5.0, y: 6.0, z: 7.0, w: 8.0 }; diff --git a/src/noise/perlin.rs b/src/noise/perlin.rs index 6f26a41..5dba280 100644 --- a/src/noise/perlin.rs +++ b/src/noise/perlin.rs @@ -13,7 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use geom::{Point2, Point3}; +use math::{Point2, Point3}; pub struct Perlin; diff --git a/src/noise/simplex.rs b/src/noise/simplex.rs index 3aea7bc..7678d9f 100644 --- a/src/noise/simplex.rs +++ b/src/noise/simplex.rs @@ -13,8 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::Vec4; -use geom::{Point2, Point3}; +use math::Vec4; +use math::{Point2, Point3}; pub struct Simplex; diff --git a/src/transform/projection.rs b/src/transform/projection.rs index f242183..439dde1 100644 --- a/src/transform/projection.rs +++ b/src/transform/projection.rs @@ -14,8 +14,8 @@ // limitations under the License. use bounds::Frustum; -use core::Mat4; -use geom::Plane3; +use math::Mat4; +use math::Plane3; /// /// Create a perspective projection matrix diff --git a/src/transform/transform.rs b/src/transform/transform.rs index aa3b2a5..2de7ecd 100644 --- a/src/transform/transform.rs +++ b/src/transform/transform.rs @@ -15,7 +15,7 @@ pub use self::projection::{Projection, Perspective, PerspectiveFOV, Ortho}; -use core::{Vec3, Quat}; +use math::{Vec3, Quat}; pub mod projection;