Skip to main content

mlt_core/decoder/geometry/
model.rs

1use derive_debug::Dbg;
2use num_enum::TryFromPrimitive;
3use serde::{Deserialize, Serialize};
4
5use crate::decoder::RawStream;
6use crate::utils::formatter::{opt_vec_seq, vec_seq};
7use crate::{DecodeState, Lazy};
8
9/// Geometry column representation, parameterized by decode state.
10///
11/// - `Geometry<'a>` / `Geometry<'a, Lazy>` — either raw bytes or decoded, in an [`crate::LazyParsed`] enum.
12/// - `Geometry<'a, Parsed>` — decoded [`GeometryValues`] directly (no enum wrapper).
13pub type Geometry<'a, S = Lazy> = <S as DecodeState>::LazyOrParsed<RawGeometry<'a>, GeometryValues>;
14
15/// Raw geometry data as read directly from the tile (borrows from input bytes)
16#[derive(Debug, PartialEq, Clone)]
17pub struct RawGeometry<'a> {
18    pub(crate) meta: RawStream<'a>,
19    pub(crate) items: Vec<RawStream<'a>>,
20}
21
22/// Parsed (decoded) geometry data
23#[derive(Clone, Dbg, Default, PartialEq, Eq)]
24pub struct GeometryValues {
25    #[dbg(formatter = "vec_seq")]
26    pub(crate) vector_types: Vec<GeometryType>,
27    #[dbg(formatter = "opt_vec_seq")]
28    pub(crate) geometry_offsets: Option<Vec<u32>>,
29    #[dbg(formatter = "opt_vec_seq")]
30    pub(crate) part_offsets: Option<Vec<u32>>,
31    #[dbg(formatter = "opt_vec_seq")]
32    pub(crate) ring_offsets: Option<Vec<u32>>,
33    #[dbg(formatter = "opt_vec_seq")]
34    pub(crate) index_buffer: Option<Vec<u32>>,
35    #[dbg(formatter = "opt_vec_seq")]
36    pub(crate) triangles: Option<Vec<u32>>,
37    #[dbg(formatter = "opt_vec_seq")]
38    pub(crate) vertices: Option<Vec<i32>>,
39}
40
41/// Types of geometries supported in MLT
42#[derive(
43    Debug,
44    Clone,
45    Copy,
46    PartialEq,
47    PartialOrd,
48    Eq,
49    Hash,
50    Ord,
51    TryFromPrimitive,
52    strum::Display,
53    strum::IntoStaticStr,
54    Serialize,
55    Deserialize,
56)]
57#[repr(u8)]
58#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
59pub enum GeometryType {
60    /*
61        ATTENTION: Do not modify the order of this enum - it is being used in geometry decoding
62    */
63    Point,
64    LineString,
65    Polygon,
66    MultiPoint,
67    MultiLineString,
68    MultiPolygon,
69}