Skip to main content

molgfx_render/engine/chunk_placement/
windows.rs

1use super::{ChunkPlacementError, ChunkPlacementId};
2use molgfx_core::ResidencyTicket;
3
4macro_rules! validate_interpolation {
5    ($value:expr) => {
6        if !$value.is_finite() || !(0.0..=1.0).contains(&$value) {
7            return Err(ChunkPlacementError::InvalidInterpolation);
8        }
9    };
10}
11
12/// Bounded two-frame window for one topology-stable structure chunk.
13#[derive(Clone, Copy, Debug, PartialEq)]
14pub struct TrajectoryChunkWindow {
15    /// Exact resident structure generation receiving interpolated coordinates.
16    pub structure: ResidencyTicket,
17    /// Exact resident provider-frame generation at interpolation zero.
18    pub start: ResidencyTicket,
19    /// Exact resident provider-frame generation at interpolation one.
20    pub end: ResidencyTicket,
21    /// Closed-interval interpolation factor.
22    pub interpolation: f32,
23}
24
25/// Bounded two-frame window for one declared rigid-instance occurrence.
26#[derive(Clone, Copy, Debug, PartialEq)]
27pub struct InstanceChunkWindow {
28    /// Stable placement whose transform stream is animated.
29    pub placement: ChunkPlacementId,
30    /// Exact resident rigid-transform generation at interpolation zero.
31    pub start: ResidencyTicket,
32    /// Exact resident rigid-transform generation at interpolation one.
33    pub end: ResidencyTicket,
34    /// Closed-interval interpolation factor.
35    pub interpolation: f32,
36}
37
38/// Bounded two-frame window for one scene-independent attribute column.
39#[derive(Clone, Copy, Debug, PartialEq)]
40pub struct AttributeChunkWindow {
41    /// Stable attribute ticket referenced by visual descriptors.
42    pub attribute: ResidencyTicket,
43    /// Exact resident attribute generation at interpolation zero.
44    pub start: ResidencyTicket,
45    /// Exact resident attribute generation at interpolation one.
46    pub end: ResidencyTicket,
47    /// Closed-interval interpolation factor.
48    pub interpolation: f32,
49}
50
51impl AttributeChunkWindow {
52    /// Creates a topology- and type-stable paged attribute window.
53    ///
54    /// # Errors
55    /// Rejects interpolation outside the closed unit interval.
56    pub fn new(
57        attribute: ResidencyTicket,
58        start: ResidencyTicket,
59        end: ResidencyTicket,
60        interpolation: f32,
61    ) -> Result<Self, ChunkPlacementError> {
62        validate_interpolation!(interpolation);
63        Ok(Self {
64            attribute,
65            start,
66            end,
67            interpolation,
68        })
69    }
70}
71
72impl InstanceChunkWindow {
73    /// Creates a topology-stable paged rigid-transform window.
74    ///
75    /// # Errors
76    /// Rejects interpolation outside the closed unit interval.
77    pub fn new(
78        placement: ChunkPlacementId,
79        start: ResidencyTicket,
80        end: ResidencyTicket,
81        interpolation: f32,
82    ) -> Result<Self, ChunkPlacementError> {
83        validate_interpolation!(interpolation);
84        Ok(Self {
85            placement,
86            start,
87            end,
88            interpolation,
89        })
90    }
91}
92
93impl TrajectoryChunkWindow {
94    /// Creates a topology-stable two-frame window.
95    ///
96    /// # Errors
97    /// Rejects interpolation outside the closed unit interval.
98    pub fn new(
99        structure: ResidencyTicket,
100        start: ResidencyTicket,
101        end: ResidencyTicket,
102        interpolation: f32,
103    ) -> Result<Self, ChunkPlacementError> {
104        validate_interpolation!(interpolation);
105        Ok(Self {
106            structure,
107            start,
108            end,
109            interpolation,
110        })
111    }
112}