Skip to main content

molgfx_render/engine/chunk_placement/
points.rs

1use super::{ChunkPlacementError, ChunkPlacementId, ChunkRepresentation};
2use molgfx_core::ResidencyTicket;
3use molgfx_math::{Mat4, Rgba8};
4
5/// Declarative rendering of one resident generic point chunk.
6#[derive(Clone, Copy, Debug, PartialEq)]
7pub struct PointChunkPlacement {
8    id: ChunkPlacementId,
9    ticket: ResidencyTicket,
10    model_to_world: Mat4,
11    diameter_pixels: f32,
12    color: Rgba8,
13}
14
15impl PointChunkPlacement {
16    /// Creates a generic point placement without copying its payload.
17    ///
18    /// # Errors
19    ///
20    /// Rejects non-finite transforms or invalid point diameters.
21    pub fn new(
22        id: ChunkPlacementId,
23        ticket: ResidencyTicket,
24        model_to_world: Mat4,
25        diameter_pixels: f32,
26        color: Rgba8,
27    ) -> Result<Self, ChunkPlacementError> {
28        if !model_to_world.is_finite() {
29            return Err(ChunkPlacementError::NonFiniteTransform);
30        }
31        ChunkRepresentation::points(diameter_pixels, color)?;
32        Ok(Self {
33            id,
34            ticket,
35            model_to_world,
36            diameter_pixels,
37            color,
38        })
39    }
40
41    /// Returns the stable caller-owned placement identity.
42    #[must_use]
43    pub const fn id(self) -> ChunkPlacementId {
44        self.id
45    }
46
47    /// Returns the exact generic point generation to draw.
48    #[must_use]
49    pub const fn ticket(self) -> ResidencyTicket {
50        self.ticket
51    }
52
53    /// Returns the dataset-local to world-space transform.
54    #[must_use]
55    pub const fn model_to_world(self) -> Mat4 {
56        self.model_to_world
57    }
58
59    /// Returns the validated point representation.
60    #[must_use]
61    pub const fn representation(self) -> ChunkRepresentation {
62        ChunkRepresentation::Points {
63            diameter_pixels: self.diameter_pixels,
64            color: self.color,
65        }
66    }
67
68    /// Returns the physical-pixel diameter.
69    #[must_use]
70    pub const fn diameter_pixels(self) -> f32 {
71        self.diameter_pixels
72    }
73
74    /// Returns the uniform packed display color.
75    #[must_use]
76    pub const fn color(self) -> Rgba8 {
77        self.color
78    }
79}