use crate::{
FeatureType, OpenVectorFeature, VectorGeometry, VectorLines3DWithOffset, VectorLinesWithOffset,
VectorPoints, VectorPoints3D, mapbox::MapboxVectorFeature,
};
use alloc::vec::Vec;
use s2json::{BBOX, Properties};
pub trait VectorFeatureMethods {
fn id(&self) -> Option<u64>;
fn version(&self) -> u16;
fn properties(&self) -> Properties;
fn extent(&self) -> usize;
fn get_type(&self) -> FeatureType;
fn bbox(&self) -> Option<BBOX>;
fn has_m_values(&self) -> bool;
fn is_points(&self) -> bool;
fn is_lines(&self) -> bool;
fn is_polygons(&self) -> bool;
fn is_points_3d(&self) -> bool;
fn is_lines_3d(&self) -> bool;
fn is_polygons_3d(&self) -> bool;
fn load_points(&mut self) -> VectorPoints;
fn load_points_3d(&mut self) -> VectorPoints3D;
fn load_lines(&mut self) -> VectorLinesWithOffset;
fn load_lines_3d(&mut self) -> VectorLines3DWithOffset;
fn load_polys(&mut self) -> Vec<VectorLinesWithOffset>;
fn load_polys_3d(&mut self) -> Vec<VectorLines3DWithOffset>;
fn load_geometry_flat(&mut self) -> (Vec<f64>, Vec<u32>);
fn load_geometry(&mut self) -> VectorGeometry;
fn read_indices(&mut self) -> Vec<u32>;
fn add_tessellation(&mut self, geometry: &mut Vec<f64>, multiplier: f64);
fn add_tessellation_3d(&mut self, geometry: &mut Vec<f64>, multiplier: f64);
}
#[derive(Debug)]
pub enum VectorFeature<'a> {
Mapbox(&'a mut MapboxVectorFeature),
Open(&'a mut OpenVectorFeature),
}
impl<'a> From<&'a mut MapboxVectorFeature> for VectorFeature<'a> {
fn from(value: &'a mut MapboxVectorFeature) -> Self {
VectorFeature::Mapbox(value)
}
}
impl<'a> From<&'a mut OpenVectorFeature> for VectorFeature<'a> {
fn from(value: &'a mut OpenVectorFeature) -> Self {
VectorFeature::Open(value)
}
}
impl VectorFeatureMethods for VectorFeature<'_> {
fn id(&self) -> Option<u64> {
match self {
VectorFeature::Mapbox(feature) => feature.id(),
VectorFeature::Open(feature) => feature.id(),
}
}
fn version(&self) -> u16 {
match self {
VectorFeature::Mapbox(feature) => feature.version(),
VectorFeature::Open(feature) => feature.version(),
}
}
fn properties(&self) -> Properties {
match self {
VectorFeature::Mapbox(feature) => feature.properties(),
VectorFeature::Open(feature) => feature.properties(),
}
}
fn extent(&self) -> usize {
match self {
VectorFeature::Mapbox(feature) => feature.extent(),
VectorFeature::Open(feature) => feature.extent(),
}
}
fn get_type(&self) -> FeatureType {
match self {
VectorFeature::Mapbox(feature) => feature.get_type(),
VectorFeature::Open(feature) => feature.get_type(),
}
}
fn bbox(&self) -> Option<BBOX> {
match self {
VectorFeature::Mapbox(feature) => feature.bbox(),
VectorFeature::Open(feature) => feature.bbox(),
}
}
fn has_m_values(&self) -> bool {
match self {
VectorFeature::Mapbox(feature) => feature.has_m_values(),
VectorFeature::Open(feature) => feature.has_m_values(),
}
}
fn is_points(&self) -> bool {
match self {
VectorFeature::Mapbox(feature) => feature.is_points(),
VectorFeature::Open(feature) => feature.is_points(),
}
}
fn is_lines(&self) -> bool {
match self {
VectorFeature::Mapbox(feature) => feature.is_lines(),
VectorFeature::Open(feature) => feature.is_lines(),
}
}
fn is_polygons(&self) -> bool {
match self {
VectorFeature::Mapbox(feature) => feature.is_polygons(),
VectorFeature::Open(feature) => feature.is_polygons(),
}
}
fn is_points_3d(&self) -> bool {
match self {
VectorFeature::Mapbox(feature) => feature.is_points_3d(),
VectorFeature::Open(feature) => feature.is_points_3d(),
}
}
fn is_lines_3d(&self) -> bool {
match self {
VectorFeature::Mapbox(feature) => feature.is_lines_3d(),
VectorFeature::Open(feature) => feature.is_lines_3d(),
}
}
fn is_polygons_3d(&self) -> bool {
match self {
VectorFeature::Mapbox(feature) => feature.is_polygons_3d(),
VectorFeature::Open(feature) => feature.is_polygons_3d(),
}
}
fn load_points(&mut self) -> VectorPoints {
match self {
VectorFeature::Mapbox(feature) => feature.load_points(),
VectorFeature::Open(feature) => feature.load_points(),
}
}
fn load_points_3d(&mut self) -> VectorPoints3D {
match self {
VectorFeature::Mapbox(feature) => feature.load_points_3d(),
VectorFeature::Open(feature) => feature.load_points_3d(),
}
}
fn load_lines(&mut self) -> VectorLinesWithOffset {
match self {
VectorFeature::Mapbox(feature) => feature.load_lines(),
VectorFeature::Open(feature) => feature.load_lines(),
}
}
fn load_lines_3d(&mut self) -> VectorLines3DWithOffset {
match self {
VectorFeature::Mapbox(feature) => feature.load_lines_3d(),
VectorFeature::Open(feature) => feature.load_lines_3d(),
}
}
fn load_polys(&mut self) -> Vec<VectorLinesWithOffset> {
match self {
VectorFeature::Mapbox(feature) => feature.load_polys(),
VectorFeature::Open(feature) => feature.load_polys(),
}
}
fn load_polys_3d(&mut self) -> Vec<VectorLines3DWithOffset> {
match self {
VectorFeature::Mapbox(feature) => feature.load_polys_3d(),
VectorFeature::Open(feature) => feature.load_polys_3d(),
}
}
fn load_geometry_flat(&mut self) -> (Vec<f64>, Vec<u32>) {
match self {
VectorFeature::Mapbox(feature) => feature.load_geometry_flat(),
VectorFeature::Open(feature) => feature.load_geometry_flat(),
}
}
fn load_geometry(&mut self) -> VectorGeometry {
match self {
VectorFeature::Mapbox(feature) => feature.load_geometry(),
VectorFeature::Open(feature) => feature.load_geometry(),
}
}
fn read_indices(&mut self) -> Vec<u32> {
match self {
VectorFeature::Mapbox(feature) => feature.read_indices(),
VectorFeature::Open(feature) => feature.read_indices(),
}
}
fn add_tessellation(&mut self, geometry: &mut Vec<f64>, multiplier: f64) {
match self {
VectorFeature::Mapbox(feature) => feature.add_tessellation(geometry, multiplier),
VectorFeature::Open(feature) => feature.add_tessellation(geometry, multiplier),
}
}
fn add_tessellation_3d(&mut self, geometry: &mut Vec<f64>, multiplier: f64) {
match self {
VectorFeature::Mapbox(feature) => feature.add_tessellation_3d(geometry, multiplier),
VectorFeature::Open(feature) => feature.add_tessellation_3d(geometry, multiplier),
}
}
}