use crate::models::AltitudeMode;
use rustial_math::GeoCoord;
#[derive(Debug, Clone)]
pub struct ColumnInstance {
pub position: GeoCoord,
pub height: f64,
pub base: f64,
pub width: f64,
pub color: Option<[f32; 4]>,
pub pick_id: u64,
pub altitude_mode: AltitudeMode,
}
impl ColumnInstance {
pub fn new(position: GeoCoord, height: f64, width: f64) -> Self {
Self {
position,
height,
base: 0.0,
width,
color: None,
pick_id: 0,
altitude_mode: AltitudeMode::ClampToGround,
}
}
pub fn with_pick_id(mut self, id: u64) -> Self {
self.pick_id = id;
self
}
pub fn with_color(mut self, color: [f32; 4]) -> Self {
self.color = Some(color);
self
}
pub fn with_base(mut self, base: f64) -> Self {
self.base = base;
self
}
}
#[derive(Debug, Clone)]
pub struct ColumnInstanceSet {
pub columns: Vec<ColumnInstance>,
pub generation: u64,
}
impl ColumnInstanceSet {
pub fn new(columns: Vec<ColumnInstance>) -> Self {
Self {
columns,
generation: 0,
}
}
#[inline]
pub fn len(&self) -> usize {
self.columns.len()
}
#[inline]
pub fn is_empty(&self) -> bool {
self.columns.is_empty()
}
}
impl Default for ColumnInstanceSet {
fn default() -> Self {
Self::new(Vec::new())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn column_instance_defaults() {
let col = ColumnInstance::new(GeoCoord::from_lat_lon(0.0, 0.0), 100.0, 10.0);
assert!((col.height - 100.0).abs() < 1e-9);
assert!((col.width - 10.0).abs() < 1e-9);
assert!((col.base - 0.0).abs() < 1e-9);
assert!(col.color.is_none());
assert_eq!(col.pick_id, 0);
}
#[test]
fn column_instance_builder() {
let col = ColumnInstance::new(GeoCoord::from_lat_lon(0.0, 0.0), 50.0, 5.0)
.with_pick_id(42)
.with_color([1.0, 0.0, 0.0, 1.0])
.with_base(10.0);
assert_eq!(col.pick_id, 42);
assert_eq!(col.color, Some([1.0, 0.0, 0.0, 1.0]));
assert!((col.base - 10.0).abs() < 1e-9);
}
#[test]
fn column_instance_set_len() {
let set = ColumnInstanceSet::new(vec![
ColumnInstance::new(GeoCoord::from_lat_lon(0.0, 0.0), 10.0, 5.0),
ColumnInstance::new(GeoCoord::from_lat_lon(1.0, 1.0), 20.0, 5.0),
]);
assert_eq!(set.len(), 2);
assert!(!set.is_empty());
}
#[test]
fn column_instance_set_empty() {
let set = ColumnInstanceSet::default();
assert!(set.is_empty());
assert_eq!(set.generation, 0);
}
}