1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! This crate is a fast implementation of [KD-tree](https://en.wikipedia.org/wiki/K-d_tree)
//! for raytracer (or other rendering method using ray).
//!
//! It's based on this [paper](http://www.irisa.fr/prive/kadi/Sujets_CTR/kadi/Kadi_sujet2_article_Kdtree.pdf)
//! written by *Ingo Wald* and *Vlastimil Havran*.
//!
//! # Installation
//!
//! ```toml
//! [dependencies]
//! kdtree-ray="1.2.2"
//! ```
//!
//! # Usage & Tips
//!
//! To create a [KD-tree](struct.KDtree.html) you only need to implement
//! the [BoundingBox](trait.BoundingBox.html) on the object.
//!
//! If you're doing a raytracer each mesh could contain a KD-tree of triangles.
//! Since `KDtree` his implementing `BoundingBox` itself you can create a KDtree
//! of meshes in your scene.
//!
//! # Example
//!
//! ```
//! use cgmath::*;
//! use kdtree_ray::{AABB, Bounded, KDTree};
//! struct Triangle(Vector3<f32>, Vector3<f32>, Vector3<f32>);
//!
//! // To use the KDTree on an object you need first to implement the BoundingBox trait.
//! impl Bounded for Triangle {
//! fn bound(&self) -> AABB {
//! let min = Vector3::new(
//! self.0.x.min(self.1.x).min(self.2.x),
//! self.0.y.min(self.1.y).min(self.2.y),
//! self.0.z.min(self.1.z).min(self.2.z),
//! );
//! let max = Vector3::new(
//! self.0.x.max(self.1.x).max(self.2.x),
//! self.0.y.max(self.1.y).max(self.2.y),
//! self.0.z.max(self.1.z).max(self.2.z),
//! );
//! AABB::new(min, max)
//! }
//! }
//!
//! // Kdtree creation
//! let triangle = Triangle(Vector3::zero(), Vector3::zero(), Vector3::zero());
//! let triangles: Vec<Triangle> = vec![triangle, /* ... */];
//! let kdtree = KDTree::build(&triangles);
//!
//! // Get a reduced list of triangles that a ray could intersect
//! let ray_origin = Vector3::zero();
//! let ray_direction = Vector3::new(1., 0., 0.);
//! let candidates_triangles = kdtree.intersect(&ray_origin, &ray_direction);
//! ```
pub use *;
pub use BuilderConfig;
pub use KDTree;
type Point3 = Vector3;
type Vector3 = Vector3;
extern crate enum_map;