Move files into submodules
This commit is contained in:
parent
288afe0898
commit
c0a5b29af1
15 changed files with 180 additions and 74 deletions
6
Makefile
6
Makefile
|
@ -22,6 +22,8 @@ SRC_CRATE = $(TARGET).rs
|
|||
EXTERN_DIR = $(ROOT_DIR)/extern
|
||||
BUILD_DIR = $(ROOT_DIR)/lib
|
||||
|
||||
CFG = --cfg=geom --cfg=world
|
||||
|
||||
TEST = $(TARGET)
|
||||
TEST_BUILD_DIR = $(ROOT_DIR)/test
|
||||
|
||||
|
@ -30,7 +32,7 @@ TEST_BUILD_DIR = $(ROOT_DIR)/test
|
|||
$(TARGET):
|
||||
@echo "Building $(TARGET)..."
|
||||
@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"
|
||||
|
||||
all: $(TARGET)
|
||||
|
@ -38,7 +40,7 @@ all: $(TARGET)
|
|||
test:
|
||||
@echo "Building unit tests for $(TARGET)..."
|
||||
@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"
|
||||
@$(TEST_BUILD_DIR)/$(TARGET)
|
||||
|
||||
|
|
24
src/core/core.rs
Normal file
24
src/core/core.rs
Normal 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;
|
|
@ -13,11 +13,11 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub use dim::Dimensional;
|
||||
|
||||
use quat::{Quat, ToQuat};
|
||||
use vec::{Vec2, Vec3, Vec4};
|
||||
use core::Dimensional;
|
||||
use core::{Quat, ToQuat};
|
||||
use core::{Vec2, Vec3, Vec4};
|
||||
|
||||
#[path = "../num_macros.rs"]
|
||||
mod num_macros;
|
||||
mod dim_macros;
|
||||
|
||||
|
@ -336,8 +336,8 @@ impl<T:Clone + Real + ApproxEq<T>> Mat2<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod mat2_tests{
|
||||
use mat::*;
|
||||
use vec::*;
|
||||
use core::mat::*;
|
||||
use core::vec::*;
|
||||
|
||||
static a: Mat2<float> = Mat2 { x: Vec2 { x: 1.0, y: 3.0 },
|
||||
y: Vec2 { x: 2.0, y: 4.0 } };
|
||||
|
@ -900,8 +900,8 @@ impl<T:Clone + Real + ApproxEq<T>> Mat3<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod mat3_tests{
|
||||
use mat::*;
|
||||
use vec::*;
|
||||
use core::mat::*;
|
||||
use core::vec::*;
|
||||
|
||||
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 },
|
||||
|
@ -1429,8 +1429,8 @@ impl<T:Clone + Real + ApproxEq<T>> Mat4<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod mat4_tests {
|
||||
use mat::*;
|
||||
use vec::*;
|
||||
use core::mat::*;
|
||||
use core::vec::*;
|
||||
|
||||
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 },
|
|
@ -13,11 +13,11 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub use dim::Dimensional;
|
||||
|
||||
use mat::{Mat3, ToMat3};
|
||||
use vec::Vec3;
|
||||
use core::Dimensional;
|
||||
use core::{Mat3, ToMat3};
|
||||
use core::Vec3;
|
||||
|
||||
#[path = "../num_macros.rs"]
|
||||
mod num_macros;
|
||||
mod dim_macros;
|
||||
|
||||
|
@ -310,9 +310,9 @@ impl<T:Clone + Float> Quat<T> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use mat::*;
|
||||
use quat::*;
|
||||
use vec::*;
|
||||
use core::mat::*;
|
||||
use core::quat::*;
|
||||
use core::vec::*;
|
||||
|
||||
#[test]
|
||||
fn test_from_angle_axis() {
|
|
@ -13,8 +13,9 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub use dim::Dimensional;
|
||||
use core::Dimensional;
|
||||
|
||||
#[path = "../num_macros.rs"]
|
||||
mod num_macros;
|
||||
mod dim_macros;
|
||||
|
||||
|
@ -392,7 +393,7 @@ impl Vec2<bool> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod vec2_tests {
|
||||
use vec::*;
|
||||
use core::vec::*;
|
||||
|
||||
#[test]
|
||||
fn test_vec2() {
|
||||
|
@ -946,7 +947,7 @@ impl Vec3<bool> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod vec3_tests{
|
||||
use vec::*;
|
||||
use core::vec::*;
|
||||
|
||||
#[test]
|
||||
fn test_vec3() {
|
||||
|
@ -1546,7 +1547,7 @@ impl Vec4<bool> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod vec4_tests {
|
||||
use vec::*;
|
||||
use core::vec::*;
|
||||
|
||||
#[test]
|
||||
fn test_vec4() {
|
22
src/geom/geom.rs
Normal file
22
src/geom/geom.rs
Normal 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;
|
|
@ -13,14 +13,11 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
pub use dim::Dimensional;
|
||||
use mat::Mat3;
|
||||
use point::Point3;
|
||||
use ray::Ray3;
|
||||
use vec::{Vec3, Vec4};
|
||||
use core::{Vec3, Vec4, Mat3};
|
||||
use geom::{Point3, Ray3};
|
||||
|
||||
#[path = "../num_macros.rs"]
|
||||
mod num_macros;
|
||||
mod dim_macros;
|
||||
|
||||
/// A plane formed from the equation: `Ax + Bx + Cx + D = 0`
|
||||
///
|
||||
|
@ -37,10 +34,6 @@ pub struct Plane<T> {
|
|||
dist: T,
|
||||
}
|
||||
|
||||
impl_dimensional!(Plane, T, 4)
|
||||
impl_approx!(Plane, 4)
|
||||
impl_swap!(Plane)
|
||||
|
||||
impl<T:Clone + Real> Plane<T> {
|
||||
/// # 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> {
|
||||
pub fn to_str(&self) -> ~str {
|
||||
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)]
|
||||
mod tests {
|
||||
use plane::*;
|
||||
use point::*;
|
||||
use geom::plane::*;
|
||||
use geom::point::*;
|
||||
|
||||
#[test]
|
||||
fn test_from_3p() {
|
|
@ -13,10 +13,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use dim::Dimensional;
|
||||
use vec::{Vec2, Vec3};
|
||||
|
||||
mod dim_macros;
|
||||
use core::{Vec2, Vec3};
|
||||
|
||||
/// A geometric point
|
||||
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)]
|
||||
pub struct Point2<T>(Vec2<T>);
|
||||
|
||||
impl_dimensional!(Point2, T, 2)
|
||||
impl_approx!(Point2, 2)
|
||||
|
||||
impl<T> Point2<T> {
|
||||
pub fn new(x: T, y: T) -> Point2<T> {
|
||||
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> {
|
||||
pub fn to_str(&self) -> ~str {
|
||||
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
|
||||
#[deriving(Clone, Eq)]
|
||||
pub struct Point3<T>(Vec3<T>);
|
||||
|
||||
impl_dimensional!(Point3, T, 3)
|
||||
impl_approx!(Point3, 3)
|
||||
|
||||
impl<T> Point3<T> {
|
||||
pub fn new(x: T, y: T, z: T) -> Point3<T> {
|
||||
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> {
|
||||
pub fn to_str(&self) -> ~str {
|
||||
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)]
|
||||
mod test_point3 {
|
||||
use point::*;
|
||||
use geom::point::*;
|
||||
|
||||
#[test]
|
||||
fn test_to_str() {
|
|
@ -13,8 +13,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use vec::Vec3;
|
||||
use point::Point3;
|
||||
use core::Vec3;
|
||||
use geom::Point3;
|
||||
|
||||
/// 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.dir.approx_eq_eps(&other.dir, epsilon)
|
||||
}
|
||||
}
|
||||
}
|
18
src/lmath.rs
18
src/lmath.rs
|
@ -23,14 +23,14 @@
|
|||
#[license = "ASL2"];
|
||||
#[crate_type = "lib"];
|
||||
|
||||
pub mod dim;
|
||||
#[path = "core/core.rs"]
|
||||
pub mod core;
|
||||
|
||||
pub mod mat;
|
||||
pub mod quat;
|
||||
pub mod vec;
|
||||
#[cfg(geom)]
|
||||
#[path = "geom/geom.rs"]
|
||||
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;
|
||||
|
|
|
@ -13,10 +13,10 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use mat::Mat4;
|
||||
use plane::Plane;
|
||||
use point::Point3;
|
||||
use core::Mat4;
|
||||
use geom::{Plane, Point3};
|
||||
|
||||
#[path = "../num_macros.rs"]
|
||||
mod num_macros;
|
||||
|
||||
#[deriving(Clone, Eq)]
|
|
@ -13,10 +13,11 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use frustum::Frustum;
|
||||
use mat::Mat4;
|
||||
use plane::Plane;
|
||||
use core::Mat4;
|
||||
use geom::Plane;
|
||||
use world::Frustum;
|
||||
|
||||
#[path = "../num_macros.rs"]
|
||||
mod num_macros;
|
||||
|
||||
///
|
20
src/world/world.rs
Normal file
20
src/world/world.rs
Normal 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;
|
Loading…
Reference in a new issue