threecrate_core/
point.rs

1//! Point types and related functionality
2
3use nalgebra::{Point3, Vector3};
4use serde::{Deserialize, Serialize};
5use bytemuck::{Pod, Zeroable};
6
7/// A 3D point with floating point coordinates
8pub type Point3f = Point3<f32>;
9
10/// A 3D point with double precision coordinates
11pub type Point3d = Point3<f64>;
12
13/// A 3D vector with floating point components
14pub type Vector3f = Vector3<f32>;
15
16/// A 3D vector with double precision components
17pub type Vector3d = Vector3<f64>;
18
19/// A point with color information
20#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
21#[repr(C)]
22pub struct ColoredPoint3f {
23    pub position: Point3f,
24    pub color: [u8; 3],
25}
26
27unsafe impl Pod for ColoredPoint3f {}
28unsafe impl Zeroable for ColoredPoint3f {}
29
30/// A point with normal vector
31#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
32#[repr(C)]
33pub struct NormalPoint3f {
34    pub position: Point3f,
35    pub normal: Vector3f,
36}
37
38unsafe impl Pod for NormalPoint3f {}
39unsafe impl Zeroable for NormalPoint3f {}
40
41/// A point with color and normal information
42#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
43#[repr(C)]
44pub struct ColoredNormalPoint3f {
45    pub position: Point3f,
46    pub normal: Vector3f,
47    pub color: [u8; 3],
48}
49
50unsafe impl Pod for ColoredNormalPoint3f {}
51unsafe impl Zeroable for ColoredNormalPoint3f {}
52
53impl Default for ColoredPoint3f {
54    fn default() -> Self {
55        Self {
56            position: Point3f::origin(),
57            color: [255, 255, 255],
58        }
59    }
60}
61
62impl Default for NormalPoint3f {
63    fn default() -> Self {
64        Self {
65            position: Point3f::origin(),
66            normal: Vector3f::new(0.0, 0.0, 1.0),
67        }
68    }
69}
70
71impl Default for ColoredNormalPoint3f {
72    fn default() -> Self {
73        Self {
74            position: Point3f::origin(),
75            normal: Vector3f::new(0.0, 0.0, 1.0),
76            color: [255, 255, 255],
77        }
78    }
79}