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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! geometry representation types & operators
//!
//! This module contains all code related to custom spatial reprentation type implementations.
//! This include custom vector / vertex types as well as generic traits for value encoding.

// ------ MODULE DECLARATIONS

mod dim2;
mod dim3;

// ------ IMPORTS

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

// ------ CONTENT

// --- re-exports

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

// --- error enum

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

// --- generic fp repersentation trait

/// Common trait implemented by types used for coordinate representation.
///
/// The static lifetime is a requirements induced by specific implementations that use
/// [`TypeId`][std::any::TypeId];
/// This is used in order to identify types in two contexts:
/// - Interacting with VTK files (`io` feature),
/// - Coding vertices and generic attributes handling
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
{
}