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
use super::DrawOrder;

// TODO(cmc): come up with some DSL in our flatbuffers definitions so that we can declare these
// constants directly in there.
impl DrawOrder {
    /// Draw order used for images if no draw order was specified.
    pub const DEFAULT_IMAGE: DrawOrder = DrawOrder(-10.0);

    /// Draw order used for 2D boxes if no draw order was specified.
    pub const DEFAULT_BOX2D: DrawOrder = DrawOrder(10.0);

    /// Draw order used for 2D lines if no draw order was specified.
    pub const DEFAULT_LINES2D: DrawOrder = DrawOrder(20.0);

    /// Draw order used for 2D points if no draw order was specified.
    pub const DEFAULT_POINTS2D: DrawOrder = DrawOrder(30.0);
}

impl std::cmp::PartialEq for DrawOrder {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.0.is_nan() && other.0.is_nan() || self.0 == other.0
    }
}

impl std::cmp::Eq for DrawOrder {}

impl std::cmp::PartialOrd for DrawOrder {
    #[inline]
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl std::cmp::Ord for DrawOrder {
    #[inline]
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        if other == self {
            std::cmp::Ordering::Equal
        } else if other.0.is_nan() || self.0 < other.0 {
            std::cmp::Ordering::Less
        } else {
            std::cmp::Ordering::Greater
        }
    }
}