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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use std::fmt::Debug;

use cgmath::{EuclideanSpace, Zero};

use super::TreeValue;
use {Bound, HasBound};

/// Value together with bounding volume, for use with DBVT.
#[derive(Debug, Clone)]
pub struct TreeValueWrapped<V, B>
where
    B: Bound,
    <B::Point as EuclideanSpace>::Diff: Debug,
{
    /// The value
    pub value: V,

    /// The bounding volume
    pub bound: B,

    margin: <B::Point as EuclideanSpace>::Diff,
}

impl<V, B> TreeValueWrapped<V, B>
where
    B: Bound,
    <B::Point as EuclideanSpace>::Diff: Debug,
{
    /// Create a new shape
    pub fn new(value: V, bound: B, margin: <B::Point as EuclideanSpace>::Diff) -> Self {
        Self {
            value,
            bound,
            margin,
        }
    }
}

impl<V, B> TreeValue for TreeValueWrapped<V, B>
where
    V: Clone,
    B: Bound + Clone,
    <B::Point as EuclideanSpace>::Diff: Debug,
{
    type Bound = B;

    fn bound(&self) -> &Self::Bound {
        &self.bound
    }

    fn get_bound_with_margin(&self) -> Self::Bound {
        self.bound.with_margin(self.margin)
    }
}

impl<V, B> HasBound for TreeValueWrapped<V, B>
where
    B: Bound,
    <B::Point as EuclideanSpace>::Diff: Debug,
{
    type Bound = B;

    fn bound(&self) -> &Self::Bound {
        &self.bound
    }
}

impl<V, B, P> From<(V, B, P::Diff)> for TreeValueWrapped<V, B>
where
    P: EuclideanSpace,
    B: Bound<Point = P> + Clone,
    P::Diff: Debug,
{
    fn from((value, bound, margin): (V, B, P::Diff)) -> Self {
        Self::new(value, bound, margin)
    }
}

impl<V, B> From<(V, B)> for TreeValueWrapped<V, B>
where
    B: Bound + Clone,
    <<B as Bound>::Point as EuclideanSpace>::Diff: Debug + Zero,
{
    fn from((value, bound): (V, B)) -> Self {
        Self::new(
            value,
            bound,
            <<B as Bound>::Point as EuclideanSpace>::Diff::zero(),
        )
    }
}