kdtree_ray/
config.rs

1static DEFAULT_COST_TRAVERSAL: f32 = 15.;
2static DEFAULT_COST_INTERSECTION: f32 = 20.;
3static DEFAULT_EMPTY_CUT_BONUS: f32 = 0.2;
4
5/// Configuration for the builder.
6#[derive(Clone, Copy, Debug)]
7pub struct BuilderConfig {
8    /// Cost of a traversal in the kdtree.
9    cost_traversal: f32,
10    /// Cost of an intersection test.
11    cost_intersection: f32,
12    /// Bonus (between `0.` and `1.`) for cutting an empty space:
13    /// * `1.` means that cutting an empty space is in any case better than cutting a full space.
14    /// * `0.` means that cutting an empty space isn't better than cutting a full space.
15    empty_cut_bonus: f32,
16}
17
18impl BuilderConfig {
19    /// Create a new `BuilderConfig` given the cost of a traversal, the cost of an intersection
20    /// test and the bonus for cutting an empty space.
21    ///
22    /// ### Panics
23    ///
24    /// * If `cost_traversal` is not strictly positive.
25    /// * If `cost_intersection` is not strictly positive.
26    /// * If `empty_cut_bonus` is not between `0.` and `1.`.
27    pub fn new(cost_traversal: f32, cost_intersection: f32, empty_cut_bonus: f32) -> Self {
28        assert!(cost_traversal > 0.);
29        assert!(cost_intersection > 0.);
30        assert!((0. ..=1.).contains(&empty_cut_bonus));
31        BuilderConfig {
32            cost_traversal,
33            cost_intersection,
34            empty_cut_bonus,
35        }
36    }
37
38    /// Retrieve the cost of a traversal.
39    pub fn cost_traversal(&self) -> f32 {
40        self.cost_traversal
41    }
42
43    /// Retrieve the cost of an intersection.
44    pub fn cost_intersection(&self) -> f32 {
45        self.cost_intersection
46    }
47
48    /// Retrieve the bonus for cutting an empty space.
49    pub fn empty_cut_bonus(&self) -> f32 {
50        self.empty_cut_bonus
51    }
52}
53
54impl Default for BuilderConfig {
55    /// Create a new `BuilderConfig` with the default values.
56    /// * Traversal cost: `15.`
57    /// * Intersection cost: `20.`
58    /// * Empty cut bonus: `0.2`
59    fn default() -> Self {
60        BuilderConfig {
61            cost_traversal: DEFAULT_COST_TRAVERSAL,
62            cost_intersection: DEFAULT_COST_INTERSECTION,
63            empty_cut_bonus: DEFAULT_EMPTY_CUT_BONUS,
64        }
65    }
66}