use derive_debug::Dbg;
use crate::decoder::{DictionaryType, GeometryValues, StreamType};
use crate::encoder::geometry::VertexBufferType;
use crate::encoder::{IntEncoder, StagedId, StagedProperty};
#[derive(Debug, Clone, Default, PartialEq)]
pub struct EncodedUnknown {
pub(crate) tag: u8,
pub(crate) value: Vec<u8>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct CurveParams {
pub shift: u32,
pub bits: u32,
}
impl Default for CurveParams {
fn default() -> Self {
Self { shift: 0, bits: 1 }
}
}
impl CurveParams {
#[must_use]
pub fn from_vertices(vertices: &[i32]) -> Self {
if vertices.is_empty() {
return Self::default();
}
let (min, max) = vertices
.iter()
.fold((i32::MAX, i32::MIN), |(mn, mx), &v| (mn.min(v), mx.max(v)));
crate::codecs::hilbert::hilbert_curve_params_from_bounds(min, max)
}
}
#[derive(Debug, PartialEq, Clone)]
pub struct StagedLayer {
pub name: String,
pub extent: u32,
pub id: StagedId,
pub geometry: GeometryValues,
pub properties: Vec<StagedProperty>,
}
#[derive(Debug, Clone, Copy, PartialEq, Hash)]
#[expect(
clippy::struct_excessive_bools,
reason = "enums would not model this better, not a state machine"
)]
pub struct EncoderConfig {
pub tessellate: bool,
pub try_spatial_morton_sort: bool,
pub try_spatial_hilbert_sort: bool,
pub try_id_sort: bool,
pub allow_fsst: bool,
pub allow_fpf: bool,
pub allow_shared_dict: bool,
}
impl Default for EncoderConfig {
fn default() -> Self {
Self {
tessellate: false,
try_spatial_morton_sort: true,
try_spatial_hilbert_sort: true,
try_id_sort: true,
allow_fsst: true,
allow_fpf: true,
allow_shared_dict: true,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StrEncoding {
Plain,
Dict,
Fsst,
FsstDict,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ColumnKind {
Id,
Geometry,
Property,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct StreamCtx<'a> {
pub kind: ColumnKind,
pub stream_type: StreamType,
pub name: &'a str,
pub subname: &'a str,
}
impl<'a> StreamCtx<'a> {
#[inline]
#[must_use]
pub const fn new(
kind: ColumnKind,
stream_type: StreamType,
name: &'a str,
subname: &'a str,
) -> Self {
Self {
kind,
stream_type,
name,
subname,
}
}
#[inline]
#[must_use]
pub const fn id(stream_type: StreamType) -> Self {
Self::new(ColumnKind::Id, stream_type, "", "")
}
#[inline]
#[must_use]
pub const fn geom(stream_type: StreamType, name: &'a str) -> Self {
Self::new(ColumnKind::Geometry, stream_type, name, "")
}
#[inline]
#[must_use]
pub const fn prop(stream_type: StreamType, name: &'a str) -> Self {
Self::new(ColumnKind::Property, stream_type, name, "")
}
#[inline]
#[must_use]
pub const fn prop_data(name: &'a str) -> Self {
let stream_type = StreamType::Data(DictionaryType::None);
Self::new(ColumnKind::Property, stream_type, name, "")
}
#[inline]
#[must_use]
pub const fn prop2(stream_type: StreamType, prefix: &'a str, suffix: &'a str) -> Self {
Self::new(ColumnKind::Property, stream_type, prefix, suffix)
}
}
#[derive(Dbg)]
pub struct ExplicitEncoder {
pub vertex_buffer_type: VertexBufferType,
#[dbg(skip)]
pub force_stream: Box<dyn for<'a> Fn(&'a StreamCtx<'a>) -> bool>,
#[dbg(skip)]
pub get_int_encoder: Box<dyn for<'a> Fn(&'a StreamCtx<'a>) -> IntEncoder>,
#[dbg(skip)]
pub get_str_encoding: Box<dyn Fn(&str) -> StrEncoding>,
}