Move files into submodules

This commit is contained in:
Brendan Zabarauskas 2013-07-08 17:00:38 +10:00
parent 288afe0898
commit c0a5b29af1
15 changed files with 180 additions and 74 deletions

View file

@ -22,6 +22,8 @@ SRC_CRATE = $(TARGET).rs
EXTERN_DIR = $(ROOT_DIR)/extern EXTERN_DIR = $(ROOT_DIR)/extern
BUILD_DIR = $(ROOT_DIR)/lib BUILD_DIR = $(ROOT_DIR)/lib
CFG = --cfg=geom --cfg=world
TEST = $(TARGET) TEST = $(TARGET)
TEST_BUILD_DIR = $(ROOT_DIR)/test TEST_BUILD_DIR = $(ROOT_DIR)/test
@ -30,7 +32,7 @@ TEST_BUILD_DIR = $(ROOT_DIR)/test
$(TARGET): $(TARGET):
@echo "Building $(TARGET)..." @echo "Building $(TARGET)..."
@mkdir -p $(BUILD_DIR) @mkdir -p $(BUILD_DIR)
@rustc $(SRC_DIR)/$(SRC_CRATE) --out-dir=$(BUILD_DIR) @rustc $(CFG) $(SRC_DIR)/$(SRC_CRATE) --out-dir=$(BUILD_DIR)
@echo "Success" @echo "Success"
all: $(TARGET) all: $(TARGET)
@ -38,7 +40,7 @@ all: $(TARGET)
test: test:
@echo "Building unit tests for $(TARGET)..." @echo "Building unit tests for $(TARGET)..."
@mkdir -p $(TEST_BUILD_DIR) @mkdir -p $(TEST_BUILD_DIR)
@rustc $(SRC_DIR)/$(SRC_CRATE) --test --out-dir=$(TEST_BUILD_DIR) @rustc $(CFG) $(SRC_DIR)/$(SRC_CRATE) --test --out-dir=$(TEST_BUILD_DIR)
@echo "Success" @echo "Success"
@$(TEST_BUILD_DIR)/$(TARGET) @$(TEST_BUILD_DIR)/$(TARGET)

24
src/core/core.rs Normal file
View file

@ -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::dim::Dimensional;
pub use self::mat::{Mat2, ToMat2, Mat3, ToMat3, Mat4, ToMat4};
pub use self::quat::{Quat, ToQuat};
pub use self::vec::{Vec2, Vec3, Vec4};
pub mod dim;
pub mod mat;
pub mod quat;
pub mod vec;

View file

@ -13,11 +13,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
pub use dim::Dimensional; use core::Dimensional;
use core::{Quat, ToQuat};
use quat::{Quat, ToQuat}; use core::{Vec2, Vec3, Vec4};
use vec::{Vec2, Vec3, Vec4};
#[path = "../num_macros.rs"]
mod num_macros; mod num_macros;
mod dim_macros; mod dim_macros;
@ -336,8 +336,8 @@ impl<T:Clone + Real + ApproxEq<T>> Mat2<T> {
#[cfg(test)] #[cfg(test)]
mod mat2_tests{ mod mat2_tests{
use mat::*; use core::mat::*;
use vec::*; use core::vec::*;
static a: Mat2<float> = Mat2 { x: Vec2 { x: 1.0, y: 3.0 }, static a: Mat2<float> = Mat2 { x: Vec2 { x: 1.0, y: 3.0 },
y: Vec2 { x: 2.0, y: 4.0 } }; y: Vec2 { x: 2.0, y: 4.0 } };
@ -900,8 +900,8 @@ impl<T:Clone + Real + ApproxEq<T>> Mat3<T> {
#[cfg(test)] #[cfg(test)]
mod mat3_tests{ mod mat3_tests{
use mat::*; use core::mat::*;
use vec::*; use core::vec::*;
static a: Mat3<float> = Mat3 { x: Vec3 { x: 1.0, y: 4.0, z: 7.0 }, static a: Mat3<float> = Mat3 { x: Vec3 { x: 1.0, y: 4.0, z: 7.0 },
y: Vec3 { x: 2.0, y: 5.0, z: 8.0 }, y: Vec3 { x: 2.0, y: 5.0, z: 8.0 },
@ -1429,8 +1429,8 @@ impl<T:Clone + Real + ApproxEq<T>> Mat4<T> {
#[cfg(test)] #[cfg(test)]
mod mat4_tests { mod mat4_tests {
use mat::*; use core::mat::*;
use vec::*; use core::vec::*;
static a: Mat4<float> = Mat4 { x: Vec4 { x: 1.0, y: 5.0, z: 9.0, w: 13.0 }, static a: Mat4<float> = 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 }, y: Vec4 { x: 2.0, y: 6.0, z: 10.0, w: 14.0 },

View file

@ -13,11 +13,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
pub use dim::Dimensional; use core::Dimensional;
use core::{Mat3, ToMat3};
use mat::{Mat3, ToMat3}; use core::Vec3;
use vec::Vec3;
#[path = "../num_macros.rs"]
mod num_macros; mod num_macros;
mod dim_macros; mod dim_macros;
@ -310,9 +310,9 @@ impl<T:Clone + Float> Quat<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use mat::*; use core::mat::*;
use quat::*; use core::quat::*;
use vec::*; use core::vec::*;
#[test] #[test]
fn test_from_angle_axis() { fn test_from_angle_axis() {

View file

@ -13,8 +13,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
pub use dim::Dimensional; use core::Dimensional;
#[path = "../num_macros.rs"]
mod num_macros; mod num_macros;
mod dim_macros; mod dim_macros;
@ -392,7 +393,7 @@ impl Vec2<bool> {
#[cfg(test)] #[cfg(test)]
mod vec2_tests { mod vec2_tests {
use vec::*; use core::vec::*;
#[test] #[test]
fn test_vec2() { fn test_vec2() {
@ -946,7 +947,7 @@ impl Vec3<bool> {
#[cfg(test)] #[cfg(test)]
mod vec3_tests{ mod vec3_tests{
use vec::*; use core::vec::*;
#[test] #[test]
fn test_vec3() { fn test_vec3() {
@ -1546,7 +1547,7 @@ impl Vec4<bool> {
#[cfg(test)] #[cfg(test)]
mod vec4_tests { mod vec4_tests {
use vec::*; use core::vec::*;
#[test] #[test]
fn test_vec4() { fn test_vec4() {

22
src/geom/geom.rs Normal file
View file

@ -0,0 +1,22 @@
// 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::Plane;
pub use self::point::{Point2, Point3};
pub use self::ray::Ray3;
pub mod plane;
pub mod point;
pub mod ray;

View file

@ -13,14 +13,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
pub use dim::Dimensional; use core::{Vec3, Vec4, Mat3};
use mat::Mat3; use geom::{Point3, Ray3};
use point::Point3;
use ray::Ray3;
use vec::{Vec3, Vec4};
#[path = "../num_macros.rs"]
mod num_macros; mod num_macros;
mod dim_macros;
/// A plane formed from the equation: `Ax + Bx + Cx + D = 0` /// A plane formed from the equation: `Ax + Bx + Cx + D = 0`
/// ///
@ -37,10 +34,6 @@ pub struct Plane<T> {
dist: T, dist: T,
} }
impl_dimensional!(Plane, T, 4)
impl_approx!(Plane, 4)
impl_swap!(Plane)
impl<T:Clone + Real> Plane<T> { impl<T:Clone + Real> Plane<T> {
/// # Arguments /// # Arguments
/// ///
@ -150,6 +143,24 @@ impl<T:Clone + Real + ApproxEq<T>> Plane<T> {
} }
} }
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Plane<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &Plane<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &Plane<T>, epsilon: &T) -> bool {
self.norm.approx_eq_eps(&other.norm, epsilon) &&
self.dist.approx_eq_eps(&other.dist, epsilon)
}
}
impl<T> ToStr for Plane<T> { impl<T> ToStr for Plane<T> {
pub fn to_str(&self) -> ~str { pub fn to_str(&self) -> ~str {
fmt!("%?x + %?y + %?z + %? = 0", self.norm.x, self.norm.y, self.norm.z, self.dist) fmt!("%?x + %?y + %?z + %? = 0", self.norm.x, self.norm.y, self.norm.z, self.dist)
@ -158,8 +169,8 @@ impl<T> ToStr for Plane<T> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use plane::*; use geom::plane::*;
use point::*; use geom::point::*;
#[test] #[test]
fn test_from_3p() { fn test_from_3p() {

View file

@ -13,10 +13,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use dim::Dimensional; use core::{Vec2, Vec3};
use vec::{Vec2, Vec3};
mod dim_macros;
/// A geometric point /// A geometric point
pub trait Point<T,V>: Eq + ApproxEq<T> + ToStr { pub trait Point<T,V>: Eq + ApproxEq<T> + ToStr {
@ -28,9 +25,6 @@ pub trait Point<T,V>: Eq + ApproxEq<T> + ToStr {
#[deriving(Clone, Eq)] #[deriving(Clone, Eq)]
pub struct Point2<T>(Vec2<T>); pub struct Point2<T>(Vec2<T>);
impl_dimensional!(Point2, T, 2)
impl_approx!(Point2, 2)
impl<T> Point2<T> { impl<T> Point2<T> {
pub fn new(x: T, y: T) -> Point2<T> { pub fn new(x: T, y: T) -> Point2<T> {
Point2(Vec2::new(x, y)) Point2(Vec2::new(x, y))
@ -47,19 +41,43 @@ impl<T:Clone + Real> Point<T,Vec2<T>> for Point2<T> {
} }
} }
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Point2<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &Point2<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &Point2<T>, epsilon: &T) -> bool {
(**self).approx_eq_eps(&**other, epsilon)
}
}
impl<T> ToStr for Point2<T> { impl<T> ToStr for Point2<T> {
pub fn to_str(&self) -> ~str { pub fn to_str(&self) -> ~str {
fmt!("[%?, %?]", self.x, self.y) fmt!("[%?, %?]", self.x, self.y)
} }
} }
#[cfg(test)]
mod test_point2 {
use geom::point::*;
#[test]
fn test_to_str() {
assert_eq!(Point2::new(1, 2).to_str(), ~"[1, 2]");
}
}
/// A three-dimensional point /// A three-dimensional point
#[deriving(Clone, Eq)] #[deriving(Clone, Eq)]
pub struct Point3<T>(Vec3<T>); pub struct Point3<T>(Vec3<T>);
impl_dimensional!(Point3, T, 3)
impl_approx!(Point3, 3)
impl<T> Point3<T> { impl<T> Point3<T> {
pub fn new(x: T, y: T, z: T) -> Point3<T> { pub fn new(x: T, y: T, z: T) -> Point3<T> {
Point3(Vec3::new(x, y, z)) Point3(Vec3::new(x, y, z))
@ -76,25 +94,32 @@ impl<T:Clone + Real> Point<T,Vec3<T>> for Point3<T> {
} }
} }
impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Point3<T> {
#[inline]
pub fn approx_epsilon() -> T {
ApproxEq::approx_epsilon::<T,T>()
}
#[inline]
pub fn approx_eq(&self, other: &Point3<T>) -> bool {
self.approx_eq_eps(other, &ApproxEq::approx_epsilon::<T,T>())
}
#[inline]
pub fn approx_eq_eps(&self, other: &Point3<T>, epsilon: &T) -> bool {
(**self).approx_eq_eps(&**other, epsilon)
}
}
impl<T> ToStr for Point3<T> { impl<T> ToStr for Point3<T> {
pub fn to_str(&self) -> ~str { pub fn to_str(&self) -> ~str {
fmt!("[%?, %?, %?]", self.x, self.y, self.z) fmt!("[%?, %?, %?]", self.x, self.y, self.z)
} }
} }
#[cfg(test)]
mod test_point2 {
use point::*;
#[test]
fn test_to_str() {
assert_eq!(Point2::new(1, 2).to_str(), ~"[1, 2]");
}
}
#[cfg(test)] #[cfg(test)]
mod test_point3 { mod test_point3 {
use point::*; use geom::point::*;
#[test] #[test]
fn test_to_str() { fn test_to_str() {

View file

@ -13,8 +13,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use vec::Vec3; use core::Vec3;
use point::Point3; use geom::Point3;
/// A three-dimensional ray /// A three-dimensional ray
/// ///
@ -44,4 +44,4 @@ impl<T:Clone + Eq + ApproxEq<T>> ApproxEq<T> for Ray3<T> {
self.pos.approx_eq_eps(&other.pos, epsilon) && self.pos.approx_eq_eps(&other.pos, epsilon) &&
self.dir.approx_eq_eps(&other.dir, epsilon) self.dir.approx_eq_eps(&other.dir, epsilon)
} }
} }

View file

@ -23,14 +23,14 @@
#[license = "ASL2"]; #[license = "ASL2"];
#[crate_type = "lib"]; #[crate_type = "lib"];
pub mod dim; #[path = "core/core.rs"]
pub mod core;
pub mod mat; #[cfg(geom)]
pub mod quat; #[path = "geom/geom.rs"]
pub mod vec; pub mod geom;
#[cfg(world)]
#[path = "world/world.rs"]
pub mod world;
pub mod frustum;
pub mod plane;
pub mod point;
pub mod projection;
pub mod ray;

View file

@ -13,10 +13,10 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use mat::Mat4; use core::Mat4;
use plane::Plane; use geom::{Plane, Point3};
use point::Point3;
#[path = "../num_macros.rs"]
mod num_macros; mod num_macros;
#[deriving(Clone, Eq)] #[deriving(Clone, Eq)]

View file

@ -13,10 +13,11 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use frustum::Frustum; use core::Mat4;
use mat::Mat4; use geom::Plane;
use plane::Plane; use world::Frustum;
#[path = "../num_macros.rs"]
mod num_macros; mod num_macros;
/// ///

20
src/world/world.rs Normal file
View file

@ -0,0 +1,20 @@
// 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::frustum::Frustum;
pub use self::projection::{Projection, Ortho, Perspective, PerspectiveFOV};
pub mod frustum;
pub mod projection;