Skip to main content

mlt_core/frames/v01/geometry/
model.rs

1use num_enum::TryFromPrimitive;
2use serde::{Deserialize, Serialize};
3
4use crate::EncDec;
5use crate::v01::{EncodedStream, RawStream};
6
7/// Geometry column representation, either raw (borrowed from bytes) or parsed.
8pub type Geometry<'a> = EncDec<RawGeometry<'a>, GeometryValues>;
9
10/// Raw geometry data as read directly from the tile (borrows from input bytes)
11#[derive(Debug, PartialEq, Clone)]
12pub struct RawGeometry<'a> {
13    pub meta: RawStream<'a>,
14    pub items: Vec<RawStream<'a>>,
15}
16
17/// Parsed (decoded) geometry data
18#[derive(Clone, Default, PartialEq, Eq)]
19pub struct GeometryValues {
20    pub vector_types: Vec<GeometryType>,
21    pub geometry_offsets: Option<Vec<u32>>,
22    pub part_offsets: Option<Vec<u32>>,
23    pub ring_offsets: Option<Vec<u32>>,
24    pub index_buffer: Option<Vec<u32>>,
25    pub triangles: Option<Vec<u32>>,
26    pub vertices: Option<Vec<i32>>,
27}
28
29/// Wire-ready encoded geometry data (owns its byte buffers)
30#[derive(Debug, PartialEq, Clone)]
31pub struct EncodedGeometry {
32    pub meta: EncodedStream,
33    pub items: Vec<EncodedStream>,
34}
35
36/// Types of geometries supported in MLT
37#[derive(
38    Debug,
39    Clone,
40    Copy,
41    PartialEq,
42    PartialOrd,
43    Eq,
44    Hash,
45    Ord,
46    TryFromPrimitive,
47    strum::Display,
48    strum::IntoStaticStr,
49    Serialize,
50    Deserialize,
51)]
52#[repr(u8)]
53#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
54pub enum GeometryType {
55    Point,
56    LineString,
57    Polygon,
58    MultiPoint,
59    MultiLineString,
60    MultiPolygon,
61}
62
63/// Describes how the vertex buffer should be encoded.
64#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Default)]
65#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
66#[cfg_attr(all(not(test), feature = "arbitrary"), derive(arbitrary::Arbitrary))]
67pub enum VertexBufferType {
68    /// Standard 2D `(x, y)` pairs encoded with componentwise delta.
69    #[default]
70    Vec2,
71    /// Morton (Z-order) dictionary encoding:
72    /// Unique vertices are sorted by their Morton code and stored once.
73    /// Each vertex position in the stream is replaced by its index into that dictionary.
74    Morton,
75}