honeycomb_core/geometry/
mod.rs

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
//! geometry representation types & operators
//!
//! This module contains all code related to custom spatial representation type implementations.
//! This include custom vector / vertex types as well as a generic FP trait.

mod dim2;
mod dim3;

use std::fmt::Debug;
use std::ops::{AddAssign, DivAssign, MulAssign, SubAssign};
use thiserror::Error;

//

pub use dim2::{vector::Vector2, vertex::Vertex2};
pub use dim3::{vector::Vector3, vertex::Vertex3};

/// # Coordinates-level error enum
#[derive(Error, Debug, PartialEq)]
pub enum CoordsError {
    /// Error returned when trying to compute the unit vector of a null [`Vector2`].
    #[error("cannot compute unit direction of a null vector")]
    InvalidUnitDir,
    /// Error returned when trying to compute the normal to a null [`Vector2`].
    #[error("cannot compute normal direction to a null vector")]
    InvalidNormDir,
}

/// # Generic FP type trait
///
/// This trait is used for vertex & vector values. The static lifetime is a requirements induced
/// by the attribute system implementation.
pub trait CoordsFloat:
    num_traits::Float
    + Default
    + AddAssign
    + SubAssign
    + MulAssign
    + DivAssign
    + Debug
    + Send
    + Sync
    + 'static
{
}

impl<
        T: num_traits::Float
            + Default
            + AddAssign
            + SubAssign
            + MulAssign
            + DivAssign
            + Debug
            + Send
            + Sync
            + 'static,
    > CoordsFloat for T
{
}