use crate::coords::Point;
use crate::LaneId;
pub(crate) fn orient(yaw: f64, pitch: f64, roll: f64, [u, v, z]: [f64; 3]) -> [f64; 3] {
let (sr, cr) = roll.sin_cos();
let (sp, cp) = pitch.sin_cos();
let (sy, cy) = yaw.sin_cos();
let (v, z) = (v * cr - z * sr, v * sr + z * cr);
let (u, z) = (u * cp + z * sp, -u * sp + z * cp);
let (u, v) = (u * cy - v * sy, u * sy + v * cy);
[u, v, z]
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ObjectId(pub usize);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum ObjectType {
None,
Obstacle,
Pole,
Tree,
Vegetation,
Barrier,
Building,
ParkingSpace,
Patch,
Railing,
TrafficIsland,
Crosswalk,
StreetLamp,
Gantry,
SoundBarrier,
RoadMark,
RoadSurface,
Unknown,
}
impl ObjectType {
pub fn as_str(&self) -> &'static str {
match self {
Self::None => "none",
Self::Obstacle => "obstacle",
Self::Pole => "pole",
Self::Tree => "tree",
Self::Vegetation => "vegetation",
Self::Barrier => "barrier",
Self::Building => "building",
Self::ParkingSpace => "parking-space",
Self::Patch => "patch",
Self::Railing => "railing",
Self::TrafficIsland => "traffic-island",
Self::Crosswalk => "crosswalk",
Self::StreetLamp => "street-lamp",
Self::Gantry => "gantry",
Self::SoundBarrier => "sound-barrier",
Self::RoadMark => "road-mark",
Self::RoadSurface => "road-surface",
Self::Unknown => "unknown",
}
}
}
impl std::fmt::Display for ObjectType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum Extent {
Box {
length: f32,
width: f32,
height: f32,
},
Cylinder {
radius: f32,
height: f32,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Corner {
pub base: Point,
pub top: Point,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Section {
pub left: Corner,
pub right: Corner,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum Shape {
Solid {
position: Point,
heading: f32,
pitch: f32,
roll: f32,
extent: Option<Extent>,
},
Outline {
corners: Vec<Corner>,
closed: bool,
holes: Vec<Vec<Corner>>,
},
Sweep {
sections: Vec<Section>,
round: bool,
},
Skeleton {
lines: Vec<Vec<SkeletonVertex>>,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SkeletonVertex {
pub position: Point,
pub radius: f32,
pub ground: bool,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Marking {
pub side: String,
pub color: String,
pub width: f32,
pub line_length: f32,
pub space_length: f32,
pub pieces: Vec<[Point; 4]>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Border {
pub kind: String,
pub width: f32,
pub pieces: Vec<[Point; 4]>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ParkingSpace {
pub access: String,
pub restrictions: String,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Material {
pub surface: String,
pub friction: Option<f32>,
pub roughness: Option<f32>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UserData {
pub code: String,
pub value: String,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Object {
pub id: ObjectId,
pub kind: ObjectType,
pub subtype: String,
pub name: String,
pub dynamic: bool,
pub lanes: Vec<LaneId>,
pub markings: Vec<Marking>,
pub borders: Vec<Border>,
pub parking_space: Option<ParkingSpace>,
pub materials: Vec<Material>,
pub user_data: Vec<UserData>,
pub shape: Shape,
}