Skip to main content

molgfx_render/engine/chunk_placement/
representation.rs

1use super::ChunkPlacementError;
2use molgfx_math::Rgba8;
3
4/// Renderer-owned representation supported by the paged chunk path.
5#[derive(Clone, Copy, Debug, PartialEq)]
6pub enum ChunkRepresentation {
7    /// Pixel-stable circular points, batched across all resident chunks.
8    Points {
9        /// Diameter in physical pixels.
10        diameter_pixels: f32,
11        /// Uniform packed display color.
12        color: Rgba8,
13    },
14    /// Analytic van der Waals spheres derived from provider element identities.
15    Spacefill {
16        /// Multiplier applied to each element's display radius.
17        radius_scale: f32,
18        /// Uniform packed display color.
19        color: Rgba8,
20    },
21}
22
23impl ChunkRepresentation {
24    /// Creates the points representation after validating its finite diameter.
25    ///
26    /// # Errors
27    ///
28    /// Rejects non-finite or non-positive diameters.
29    pub fn points(diameter_pixels: f32, color: Rgba8) -> Result<Self, ChunkPlacementError> {
30        if !diameter_pixels.is_finite() || diameter_pixels <= 0.0 {
31            return Err(ChunkPlacementError::InvalidPointDiameter);
32        }
33        Ok(Self::Points {
34            diameter_pixels,
35            color,
36        })
37    }
38
39    /// Creates a space-filling representation over provider-owned radii.
40    ///
41    /// # Errors
42    ///
43    /// Rejects non-finite or non-positive radius scales.
44    pub fn spacefill(radius_scale: f32, color: Rgba8) -> Result<Self, ChunkPlacementError> {
45        if !radius_scale.is_finite() || radius_scale <= 0.0 {
46            return Err(ChunkPlacementError::InvalidRadiusScale);
47        }
48        Ok(Self::Spacefill {
49            radius_scale,
50            color,
51        })
52    }
53}