Skip to main content

sim_logic/rendering/extraction/
primitives.rs

1//! Ordered screen-vector records; rendering remains Engine-owned.
2
3use super::ResolvedScreenRectangle;
4use crate::{
5    identity::LogicEntity,
6    screen::{ScreenCircleVisual, ScreenLineVisual, ScreenPolylineVisual},
7};
8use sim_engine::{Layer, SceneError, ScreenScene};
9
10/// One sampled screen primitive. Images and labels remain separate retained sources.
11#[derive(Debug, Clone, PartialEq)]
12pub enum ResolvedScreenPrimitive {
13    /// One complete open path, sharing its immutable point storage with the component.
14    Polyline {
15        /// Managed source entity.
16        source: LogicEntity,
17        /// Exact sampled point sequence, style, clip and ordering.
18        visual: ScreenPolylineVisual,
19    },
20    /// A square/rounded filled rectangle, with its optional outline and clip.
21    Rectangle(ResolvedScreenRectangle),
22    /// A presentation-only line, sampled without fixed interpolation.
23    Line {
24        /// Managed entity producing this line.
25        source: LogicEntity,
26        /// Exact sampled screen geometry and style.
27        visual: ScreenLineVisual,
28    },
29    /// A filled or outline-only circle, sampled without fixed interpolation.
30    Circle {
31        /// Managed entity producing this circle.
32        source: LogicEntity,
33        /// Exact sampled screen geometry and style.
34        visual: ScreenCircleVisual,
35    },
36}
37
38impl ResolvedScreenPrimitive {
39    /// Returns the managed source identity.
40    pub const fn source(&self) -> LogicEntity {
41        match self {
42            Self::Rectangle(value) => value.source(),
43            Self::Line { source, .. }
44            | Self::Circle { source, .. }
45            | Self::Polyline { source, .. } => *source,
46        }
47    }
48    /// Returns the mixed-screen ordering layer.
49    pub const fn layer(&self) -> Layer {
50        match self {
51            Self::Rectangle(value) => value.layer(),
52            Self::Line { visual, .. } => visual.layer(),
53            Self::Circle { visual, .. } => visual.layer(),
54            Self::Polyline { visual, .. } => visual.layer(),
55        }
56    }
57    /// Returns within-layer ordering depth, not camera depth.
58    pub const fn draw_order_depth(&self) -> f32 {
59        match self {
60            Self::Rectangle(value) => value.draw_order_depth(),
61            Self::Line { visual, .. } => visual.draw_order_depth(),
62            Self::Circle { visual, .. } => visual.draw_order_depth(),
63            Self::Polyline { visual, .. } => visual.draw_order_depth(),
64        }
65    }
66    pub(super) const fn kind_order(&self) -> u8 {
67        match self {
68            Self::Rectangle(_) => 0,
69            Self::Line { .. } => 1,
70            Self::Circle { .. } => 2,
71            Self::Polyline { .. } => 3,
72        }
73    }
74    pub(crate) fn append(&self, scene: &mut ScreenScene) -> Result<(), SceneError> {
75        match self {
76            Self::Rectangle(value) => value.visual().append(scene),
77            Self::Line { visual, .. } => visual.append(scene),
78            Self::Circle { visual, .. } => visual.append(scene),
79            Self::Polyline { visual, .. } => visual.append(scene),
80        }
81    }
82}