Free as in Freedom: Codeberg.org. Create your repos!
Browse Source

Wed Dec 21 20:00:39 CET 2016

tags/v0.1.0
Jan Walter 2 years ago
parent
commit
51a42553e8

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+target

+ 102
- 0
Cargo.lock View File

@@ -0,0 +1,102 @@
1
+[root]
2
+name = "pbrt"
3
+version = "0.1.0"
4
+dependencies = [
5
+ "num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
6
+]
7
+
8
+[[package]]
9
+name = "libc"
10
+version = "0.2.18"
11
+source = "registry+https://github.com/rust-lang/crates.io-index"
12
+
13
+[[package]]
14
+name = "num"
15
+version = "0.1.36"
16
+source = "registry+https://github.com/rust-lang/crates.io-index"
17
+dependencies = [
18
+ "num-bigint 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
19
+ "num-complex 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
20
+ "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
21
+ "num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
22
+ "num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
23
+ "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
24
+]
25
+
26
+[[package]]
27
+name = "num-bigint"
28
+version = "0.1.35"
29
+source = "registry+https://github.com/rust-lang/crates.io-index"
30
+dependencies = [
31
+ "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
32
+ "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
33
+ "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
34
+ "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
35
+]
36
+
37
+[[package]]
38
+name = "num-complex"
39
+version = "0.1.35"
40
+source = "registry+https://github.com/rust-lang/crates.io-index"
41
+dependencies = [
42
+ "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
43
+ "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
44
+]
45
+
46
+[[package]]
47
+name = "num-integer"
48
+version = "0.1.32"
49
+source = "registry+https://github.com/rust-lang/crates.io-index"
50
+dependencies = [
51
+ "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
52
+]
53
+
54
+[[package]]
55
+name = "num-iter"
56
+version = "0.1.32"
57
+source = "registry+https://github.com/rust-lang/crates.io-index"
58
+dependencies = [
59
+ "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
60
+ "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
61
+]
62
+
63
+[[package]]
64
+name = "num-rational"
65
+version = "0.1.35"
66
+source = "registry+https://github.com/rust-lang/crates.io-index"
67
+dependencies = [
68
+ "num-bigint 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
69
+ "num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
70
+ "num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
71
+ "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
72
+]
73
+
74
+[[package]]
75
+name = "num-traits"
76
+version = "0.1.36"
77
+source = "registry+https://github.com/rust-lang/crates.io-index"
78
+
79
+[[package]]
80
+name = "rand"
81
+version = "0.3.15"
82
+source = "registry+https://github.com/rust-lang/crates.io-index"
83
+dependencies = [
84
+ "libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
85
+]
86
+
87
+[[package]]
88
+name = "rustc-serialize"
89
+version = "0.3.22"
90
+source = "registry+https://github.com/rust-lang/crates.io-index"
91
+
92
+[metadata]
93
+"checksum libc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "a51822fc847e7a8101514d1d44e354ba2ffa7d4c194dcab48870740e327cac70"
94
+"checksum num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "bde7c03b09e7c6a301ee81f6ddf66d7a28ec305699e3d3b056d2fc56470e3120"
95
+"checksum num-bigint 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "88b14378471f7c2adc5262f05b4701ef53e8da376453a8d8fee48e51db745e49"
96
+"checksum num-complex 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "f0c78e054dd19c3fd03419ade63fa661e9c49bb890ce3beb4eee5b7baf93f92f"
97
+"checksum num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "fb24d9bfb3f222010df27995441ded1e954f8f69cd35021f6bef02ca9552fb92"
98
+"checksum num-iter 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "287a1c9969a847055e1122ec0ea7a5c5d6f72aad97934e131c83d5c08ab4e45c"
99
+"checksum num-rational 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "54ff603b8334a72fbb27fe66948aac0abaaa40231b3cecd189e76162f6f38aaf"
100
+"checksum num-traits 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "a16a42856a256b39c6d3484f097f6713e14feacd9bfb02290917904fae46c81c"
101
+"checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d"
102
+"checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b"

+ 8
- 0
Cargo.toml View File

@@ -0,0 +1,8 @@
1
+[package]
2
+name = "pbrt"
3
+version = "0.1.0"
4
+authors = ["Jan Walter <jan@janwalter.com>"]
5
+
6
+[dependencies]
7
+
8
+num="*"

+ 32
- 0
Makefile View File

@@ -0,0 +1,32 @@
1
+all: release
2
+
3
+clean:
4
+	-rm -f *~ examples/*~ src/*~ examples/*.rs.bk src/*.rs.bk
5
+
6
+clobber: clean
7
+	-rm -fr target
8
+
9
+doc:
10
+	cargo doc
11
+
12
+browse: doc
13
+	firefox ./target/doc/pbrt/index.html
14
+
15
+debug:
16
+	cargo test
17
+
18
+release:
19
+	cargo test --release
20
+
21
+examples: release
22
+	./target/release/examples/geometry_bounds2_unit_cube
23
+	./target/release/examples/geometry_bounds3_unit_cube
24
+	./target/release/examples/geometry_length
25
+	./target/release/examples/geometry_length_squared
26
+	./target/release/examples/geometry_matrix4x4_identity
27
+	./target/release/examples/geometry_normal3_null
28
+	./target/release/examples/geometry_point2_origin
29
+	./target/release/examples/geometry_point3_origin
30
+	./target/release/examples/geometry_ray_creation
31
+	./target/release/examples/geometry_vector2_null
32
+	./target/release/examples/geometry_vector3_null

+ 21
- 0
examples/geometry_bounds2_unit_cube.rs View File

@@ -0,0 +1,21 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::{Bounds2, Point2};
4
+
5
+fn main() {
6
+    let int_origin = Point2 { x: 0, y: 0 };
7
+    let int_xy11 = Point2 { x: 1, y: 1 };
8
+    let float_origin = Point2 { x: 0.0, y: 0.0 };
9
+    let float_xy11 = Point2 { x: 1.0, y: 1.0 };
10
+    let int_unit_cube = Bounds2 {
11
+        p_min: int_origin,
12
+        p_max: int_xy11,
13
+    };
14
+    let float_unit_cube = Bounds2 {
15
+        p_min: float_origin,
16
+        p_max: float_xy11,
17
+    };
18
+
19
+    println!("int   {:?}", int_unit_cube);
20
+    println!("float {:?}", float_unit_cube);
21
+}

+ 29
- 0
examples/geometry_bounds3_unit_cube.rs View File

@@ -0,0 +1,29 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::{Bounds3, Point3};
4
+
5
+fn main() {
6
+    let int_origin = Point3 { x: 0, y: 0, z: 0 };
7
+    let int_xyz111 = Point3 { x: 1, y: 1, z: 1 };
8
+    let float_origin = Point3 {
9
+        x: 0.0,
10
+        y: 0.0,
11
+        z: 0.0,
12
+    };
13
+    let float_xyz111 = Point3 {
14
+        x: 1.0,
15
+        y: 1.0,
16
+        z: 1.0,
17
+    };
18
+    let int_unit_cube = Bounds3 {
19
+        p_min: int_origin,
20
+        p_max: int_xyz111,
21
+    };
22
+    let float_unit_cube = Bounds3 {
23
+        p_min: float_origin,
24
+        p_max: float_xyz111,
25
+    };
26
+
27
+    println!("int   {:?}", int_unit_cube);
28
+    println!("float {:?}", float_unit_cube);
29
+}

+ 53
- 0
examples/geometry_length.rs View File

@@ -0,0 +1,53 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::{Vector2, Vector3, Normal3};
4
+
5
+fn main() {
6
+    let float_vec2_f32 = Vector2 {
7
+        x: 1.2_f32,
8
+        y: 2.3_f32,
9
+    };
10
+    let float_vec2_f64 = Vector2 {
11
+        x: 1.2_f64,
12
+        y: 2.3_f64,
13
+    };
14
+
15
+    println!("float_vec2_f32 = {:?}", float_vec2_f32);
16
+    println!("float_vec2_f32.length() = {:?}", float_vec2_f32.length());
17
+    println!("float_vec2_f64 = {:?}", float_vec2_f64);
18
+    println!("float_vec2_f64.length() = {:?}", float_vec2_f64.length());
19
+
20
+    let float_vec3_f32 = Vector3 {
21
+        x: 1.2_f32,
22
+        y: 2.3_f32,
23
+        z: 3.4_f32,
24
+    };
25
+    let float_vec3_f64 = Vector3 {
26
+        x: 1.2_f64,
27
+        y: 2.3_f64,
28
+        z: 3.4_f64,
29
+    };
30
+
31
+    println!("float_vec3_f32 = {:?}", float_vec3_f32);
32
+    println!("float_vec3_f32.length() = {:?}", float_vec3_f32.length());
33
+    println!("float_vec3_f64 = {:?}", float_vec3_f64);
34
+    println!("float_vec3_f64.length() = {:?}", float_vec3_f64.length());
35
+
36
+    let float_normal3_f32 = Normal3 {
37
+        x: 2.2_f32,
38
+        y: 3.3_f32,
39
+        z: 4.4_f32,
40
+    };
41
+    let float_normal3_f64 = Normal3 {
42
+        x: 2.2_f64,
43
+        y: 3.3_f64,
44
+        z: 4.4_f64,
45
+    };
46
+
47
+    println!("float_normal3_f32 = {:?}", float_normal3_f32);
48
+    println!("float_normal3_f32.length() = {:?}",
49
+             float_normal3_f32.length());
50
+    println!("float_normal3_f64 = {:?}", float_normal3_f64);
51
+    println!("float_normal3_f64.length() = {:?}",
52
+             float_normal3_f64.length());
53
+}

+ 49
- 0
examples/geometry_length_squared.rs View File

@@ -0,0 +1,49 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::{Vector2, Vector3, Normal3};
4
+
5
+fn main() {
6
+    let int_vec2 = Vector2 { x: 1, y: 2 };
7
+
8
+    println!("int_vec2 = {:?}", int_vec2);
9
+    println!("int_vec2.length_squared() = {:?}",
10
+             int_vec2.length_squared());
11
+
12
+    let float_vec2 = Vector2 { x: 1.2, y: 2.3 };
13
+
14
+    println!("float_vec2 = {:?}", float_vec2);
15
+    println!("float_vec2.length_squared() = {:?}",
16
+             float_vec2.length_squared());
17
+
18
+    let int_vec3 = Vector3 { x: 1, y: 2, z: 3 };
19
+
20
+    println!("int_vec3 = {:?}", int_vec3);
21
+    println!("int_vec3.length_squared() = {:?}",
22
+             int_vec3.length_squared());
23
+
24
+    let float_vec3 = Vector3 {
25
+        x: 1.2,
26
+        y: 2.3,
27
+        z: 3.4,
28
+    };
29
+
30
+    println!("float_vec3 = {:?}", float_vec3);
31
+    println!("float_vec3.length_squared() = {:?}",
32
+             float_vec3.length_squared());
33
+
34
+    let int_normal3 = Normal3 { x: 2, y: 3, z: 4 };
35
+
36
+    println!("int_normal3 = {:?}", int_normal3);
37
+    println!("int_normal3.length_squared() = {:?}",
38
+             int_normal3.length_squared());
39
+
40
+    let float_normal3 = Normal3 {
41
+        x: 2.2,
42
+        y: 3.3,
43
+        z: 4.4,
44
+    };
45
+
46
+    println!("float_normal3 = {:?}", float_normal3);
47
+    println!("float_normal3.length_squared() = {:?}",
48
+             float_normal3.length_squared());
49
+}

+ 9
- 0
examples/geometry_matrix4x4_identity.rs View File

@@ -0,0 +1,9 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::Matrix4x4;
4
+
5
+fn main() {
6
+    let identity: Matrix4x4 = Matrix4x4::new();
7
+
8
+    println!("identity matrix = {:?}", identity);
9
+}

+ 15
- 0
examples/geometry_normal3_null.rs View File

@@ -0,0 +1,15 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::Normal3;
4
+
5
+fn main() {
6
+    let int_null = Normal3 { x: 0, y: 0, z: 0 };
7
+    let float_null = Normal3 {
8
+        x: 0.0,
9
+        y: 0.0,
10
+        z: 0.0,
11
+    };
12
+
13
+    println!("int   {:?}", int_null);
14
+    println!("float {:?}", float_null);
15
+}

+ 11
- 0
examples/geometry_point2_origin.rs View File

@@ -0,0 +1,11 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::Point2;
4
+
5
+fn main() {
6
+    let int_origin = Point2 { x: 0, y: 0 };
7
+    let float_origin = Point2 { x: 0.0, y: 0.0 };
8
+
9
+    println!("int   {:?}", int_origin);
10
+    println!("float {:?}", float_origin);
11
+}

+ 15
- 0
examples/geometry_point3_origin.rs View File

@@ -0,0 +1,15 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::Point3;
4
+
5
+fn main() {
6
+    let int_origin = Point3 { x: 0, y: 0, z: 0 };
7
+    let float_origin = Point3 {
8
+        x: 0.0,
9
+        y: 0.0,
10
+        z: 0.0,
11
+    };
12
+
13
+    println!("int   {:?}", int_origin);
14
+    println!("float {:?}", float_origin);
15
+}

+ 22
- 0
examples/geometry_ray_creation.rs View File

@@ -0,0 +1,22 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::{Ray, Point3f, Vector3f};
4
+
5
+fn main() {
6
+    let origin = Point3f {
7
+        x: -5.5,
8
+        y: 2.75,
9
+        z: 0.0,
10
+    };
11
+    let direction = Vector3f {
12
+        x: 1.0,
13
+        y: -8.75,
14
+        z: 2.25,
15
+    };
16
+    let ray = Ray {
17
+        o: origin,
18
+        d: direction,
19
+    };
20
+
21
+    println!("{:?}", ray);
22
+}

+ 11
- 0
examples/geometry_vector2_null.rs View File

@@ -0,0 +1,11 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::Vector2;
4
+
5
+fn main() {
6
+    let int_null = Vector2 { x: 0, y: 0 };
7
+    let float_null = Vector2 { x: 0.0, y: 0.0 };
8
+
9
+    println!("int   {:?}", int_null);
10
+    println!("float {:?}", float_null);
11
+}

+ 15
- 0
examples/geometry_vector3_null.rs View File

@@ -0,0 +1,15 @@
1
+extern crate pbrt;
2
+
3
+use pbrt::Vector3;
4
+
5
+fn main() {
6
+    let int_null = Vector3 { x: 0, y: 0, z: 0 };
7
+    let float_null = Vector3 {
8
+        x: 0.0,
9
+        y: 0.0,
10
+        z: 0.0,
11
+    };
12
+
13
+    println!("int   {:?}", int_null);
14
+    println!("float {:?}", float_null);
15
+}

+ 306
- 0
src/lib.rs View File

@@ -0,0 +1,306 @@
1
+//! # pbrt
2
+//!
3
+//! ## Vectors
4
+//!
5
+//! **pbrt** provides both 2D and 3D **vector** classes. Both are
6
+//! parameterized by the type of the underlying vector element, thus
7
+//! making it easy to instantiate vectors of both integer and
8
+//! floating-point types.
9
+//!
10
+//! ```rust
11
+//! extern crate pbrt;
12
+//!
13
+//! use pbrt::Vector3;
14
+//!
15
+//! fn main() {
16
+//!     let int_null = Vector3 { x: 0, y: 0, z: 0 };
17
+//!     let float_null = Vector3 {
18
+//!         x: 0.0,
19
+//!         y: 0.0,
20
+//!         z: 0.0,
21
+//!     };
22
+//!
23
+//!     println!("int   {:?}", int_null);
24
+//!     println!("float {:?}", float_null);
25
+//! }
26
+//! ```
27
+//!
28
+//! ## Points
29
+//!
30
+//! A **point** is a zero-dimensional location in 2D or 3D space. The
31
+//! **Point2** and **Point3** classes in **pbrt** represent points in
32
+//! the obvious way: using x, y, z (in 3D) coordinates with respect to
33
+//! a coordinate system. Although the same representation is used for
34
+//! vectors, the fact that a point represents a position whereas a
35
+//! vector represents a direction leads to a number of important
36
+//! differences in how they are treated.
37
+//!
38
+//! ```rust
39
+//! extern crate pbrt;
40
+//!
41
+//! use pbrt::Point3;
42
+//!
43
+//! fn main() {
44
+//!     let int_origin = Point3 { x: 0, y: 0, z: 0 };
45
+//!     let float_origin = Point3 {
46
+//!         x: 0.0,
47
+//!         y: 0.0,
48
+//!         z: 0.0,
49
+//!     };
50
+//!
51
+//!     println!("int   {:?}", int_origin);
52
+//!     println!("float {:?}", float_origin);
53
+//! }
54
+//! ```
55
+//!
56
+//! ## Normals
57
+//!
58
+//! A surface **normal** (or just normal) is a vector that is
59
+//! perpendicular to a surface at a particular position. It can be
60
+//! defined as the cross product of any two nonparallel vectors that
61
+//! are tangent to the surface at a point. Although normals are
62
+//! superficially similar to vectors, it is important to distinguish
63
+//! between the two of them: because normals are defined in terms of
64
+//! their relationship to a particular surface, they behave
65
+//! differently than vectors in some situations, particularly when
66
+//! applying transformations.
67
+//!
68
+//! ```rust
69
+//! extern crate pbrt;
70
+//!
71
+//! use pbrt::Normal3;
72
+//!
73
+//! fn main() {
74
+//!     let int_null = Normal3 { x: 0, y: 0, z: 0 };
75
+//!     let float_null = Normal3 {
76
+//!         x: 0.0,
77
+//!         y: 0.0,
78
+//!         z: 0.0,
79
+//!     };
80
+//!
81
+//!     println!("int   {:?}", int_null);
82
+//!     println!("float {:?}", float_null);
83
+//! }
84
+//! ```
85
+//!
86
+//! ## Rays
87
+//!
88
+//! A **ray** is a semi-infinite line specified by its origin and
89
+//! direction. **pbrt** represents a **Ray** with a **Point3f** for
90
+//! the origin and a **Vector3f** for the direction. We only need rays
91
+//! with floating-point origins and directions, so **Ray** isn't a
92
+//! template class parameterized by an arbitrary type, as points,
93
+//! vectors, and normals were.
94
+//!
95
+//! ```rust
96
+//! extern crate pbrt;
97
+//!
98
+//! use pbrt::{Ray, Point3f, Vector3f};
99
+//!
100
+//! fn main() {
101
+//!     let origin = Point3f {
102
+//!         x: -5.5,
103
+//!         y: 2.75,
104
+//!         z: 0.0,
105
+//!     };
106
+//!     let direction = Vector3f {
107
+//!         x: 1.0,
108
+//!         y: -8.75,
109
+//!         z: 2.25,
110
+//!     };
111
+//!     let ray = Ray {
112
+//!         o: origin,
113
+//!         d: direction,
114
+//!     };
115
+//!
116
+//!     println!("{:?}", ray);
117
+//! }
118
+//! ```
119
+//!
120
+//! ## Bounding Boxes
121
+//!
122
+//! Many parts of the system operate on axis-aligned regions of
123
+//! space. For example, multi-threading in **pbrt** is implemented by
124
+//! subdividing the image into rectangular tiles that can be processed
125
+//! independently, and the bounding volume hierarchy uses 3D boxes to
126
+//! bound geometric primitives in the scene. The **Bounds2** and
127
+//! **Bounds3** template classes are used to represent the extent of
128
+//! these sort of regions. Both are parameterized by a type T that is
129
+//! used to represent the coordinates of its extents.
130
+//!
131
+//! ```rust
132
+//! extern crate pbrt;
133
+//!
134
+//! use pbrt::{Bounds3, Point3};
135
+//!
136
+//! fn main() {
137
+//!     let int_origin = Point3 { x: 0, y: 0, z: 0 };
138
+//!     let int_xyz111 = Point3 { x: 1, y: 1, z: 1 };
139
+//!     let float_origin = Point3 {
140
+//!         x: 0.0,
141
+//!         y: 0.0,
142
+//!         z: 0.0,
143
+//!     };
144
+//!     let float_xyz111 = Point3 {
145
+//!         x: 1.0,
146
+//!         y: 1.0,
147
+//!         z: 1.0,
148
+//!     };
149
+//!     let int_unit_cube = Bounds3 {
150
+//!         p_min: int_origin,
151
+//!         p_max: int_xyz111,
152
+//!     };
153
+//!     let float_unit_cube = Bounds3 {
154
+//!         p_min: float_origin,
155
+//!         p_max: float_xyz111,
156
+//!     };
157
+//!
158
+//!     println!("int   {:?}", int_unit_cube);
159
+//!     println!("float {:?}", float_unit_cube);
160
+//! }
161
+//! ```
162
+//!
163
+//! ## 4 x 4 Matrices
164
+//!
165
+//! The **Matrix4x4** structure provides a low-level representation of
166
+//! 4 x 4 matrices. It is an integral part of the **Transform** class.
167
+//!
168
+//! ```rust
169
+//! extern crate pbrt;
170
+//!
171
+//! use pbrt::Matrix4x4;
172
+//!
173
+//! fn main() {
174
+//!     let identity: Matrix4x4 = Matrix4x4::new();
175
+//!
176
+//!     println!("identity matrix = {:?}", identity);
177
+//! }
178
+//! ```
179
+
180
+extern crate num;
181
+
182
+use std::ops::{Add, Mul};
183
+
184
+pub type Float = f64;
185
+pub type Point3f = Point3<Float>;
186
+pub type Vector3f = Vector3<Float>;
187
+
188
+#[derive(Debug)]
189
+pub struct Vector2<T> {
190
+    pub x: T,
191
+    pub y: T,
192
+}
193
+
194
+impl<T> Vector2<T> {
195
+    pub fn length_squared(&self) -> T
196
+        where T: Copy + Add<T, Output = T> + Mul<T, Output = T>
197
+    {
198
+        self.x * self.x + self.y * self.y
199
+    }
200
+    pub fn length(&self) -> T
201
+        where T: num::Float
202
+    {
203
+        self.length_squared().sqrt()
204
+    }
205
+}
206
+
207
+pub fn vec2_dot<T>(v1: Vector2<T>, v2: Vector2<T>) -> T
208
+    where T: Copy + Add<T, Output = T> + Mul<T, Output = T>
209
+{
210
+    v1.x * v2.x + v1.y * v2.y
211
+}
212
+
213
+#[derive(Debug)]
214
+pub struct Vector3<T> {
215
+    pub x: T,
216
+    pub y: T,
217
+    pub z: T,
218
+}
219
+
220
+impl<T> Vector3<T> {
221
+    pub fn length_squared(&self) -> T
222
+        where T: Copy + Add<T, Output = T> + Mul<T, Output = T>
223
+    {
224
+        self.x * self.x + self.y * self.y + self.z * self.z
225
+    }
226
+    pub fn length(&self) -> T
227
+        where T: num::Float
228
+    {
229
+        self.length_squared().sqrt()
230
+    }
231
+}
232
+
233
+pub fn vec3_dot<T>(v1: Vector3<T>, v2: Vector3<T>) -> T
234
+    where T: Copy + Add<T, Output = T> + Mul<T, Output = T>
235
+{
236
+    v1.x * v2.x + v1.y * v2.y + v1.z * v2.z
237
+}
238
+
239
+#[derive(Debug)]
240
+pub struct Point2<T> {
241
+    pub x: T,
242
+    pub y: T,
243
+}
244
+
245
+#[derive(Debug)]
246
+pub struct Point3<T> {
247
+    pub x: T,
248
+    pub y: T,
249
+    pub z: T,
250
+}
251
+
252
+#[derive(Debug)]
253
+pub struct Normal3<T> {
254
+    pub x: T,
255
+    pub y: T,
256
+    pub z: T,
257
+}
258
+
259
+impl<T> Normal3<T> {
260
+    pub fn length_squared(&self) -> T
261
+        where T: Copy + Add<T, Output = T> + Mul<T, Output = T>
262
+    {
263
+        self.x * self.x + self.y * self.y + self.z * self.z
264
+    }
265
+    pub fn length(&self) -> T
266
+        where T: num::Float
267
+    {
268
+        self.length_squared().sqrt()
269
+    }
270
+}
271
+
272
+#[derive(Debug)]
273
+pub struct Bounds2<T> {
274
+    pub p_min: Point2<T>,
275
+    pub p_max: Point2<T>,
276
+}
277
+
278
+#[derive(Debug)]
279
+pub struct Bounds3<T> {
280
+    pub p_min: Point3<T>,
281
+    pub p_max: Point3<T>,
282
+}
283
+
284
+#[derive(Debug)]
285
+pub struct Ray {
286
+    /// origin
287
+    pub o: Point3f,
288
+    /// direction
289
+    pub d: Vector3f,
290
+}
291
+
292
+#[derive(Debug)]
293
+pub struct Matrix4x4 {
294
+    pub m: [[Float; 4]; 4],
295
+}
296
+
297
+impl Matrix4x4 {
298
+    pub fn new() -> Matrix4x4 {
299
+        Matrix4x4 {
300
+            m: [[1.0, 0.0, 0.0, 0.0],
301
+                [0.0, 1.0, 0.0, 0.0],
302
+                [0.0, 0.0, 1.0, 0.0],
303
+                [0.0, 0.0, 0.0, 1.0]],
304
+        }
305
+    }
306
+}

Loading…
Cancel
Save