use crate::coords::Point;
use crate::LaneId;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RoadMarkId(pub usize);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum RoadMarkType {
None,
Solid,
Broken,
SolidSolid,
SolidBroken,
BrokenSolid,
BrokenBroken,
BottsDots,
Grass,
Curb,
Edge,
Custom,
Unknown,
}
impl RoadMarkType {
pub fn as_str(&self) -> &'static str {
match self {
Self::None => "none",
Self::Solid => "solid",
Self::Broken => "broken",
Self::SolidSolid => "solid-solid",
Self::SolidBroken => "solid-broken",
Self::BrokenSolid => "broken-solid",
Self::BrokenBroken => "broken-broken",
Self::BottsDots => "botts-dots",
Self::Grass => "grass",
Self::Curb => "curb",
Self::Edge => "edge",
Self::Custom => "custom",
Self::Unknown => "unknown",
}
}
}
impl std::fmt::Display for RoadMarkType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum RoadMarkWeight {
#[default]
Standard,
Bold,
}
impl RoadMarkWeight {
pub fn as_str(&self) -> &'static str {
match self {
Self::Standard => "standard",
Self::Bold => "bold",
}
}
}
impl std::fmt::Display for RoadMarkWeight {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum LaneChange {
Both,
Increase,
Decrease,
None,
Unknown,
}
impl LaneChange {
pub fn as_str(&self) -> &'static str {
match self {
Self::Both => "both",
Self::Increase => "increase",
Self::Decrease => "decrease",
Self::None => "none",
Self::Unknown => "unknown",
}
}
}
impl std::fmt::Display for LaneChange {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[non_exhaustive]
pub enum LineRule {
NoPassing,
Caution,
None,
Unknown,
}
impl LineRule {
pub fn as_str(&self) -> &'static str {
match self {
Self::NoPassing => "no-passing",
Self::Caution => "caution",
Self::None => "none",
Self::Unknown => "unknown",
}
}
}
impl std::fmt::Display for LineRule {
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))]
pub enum LinePattern {
Continuous,
Dashed {
length: f32,
space: f32,
},
Single {
length: f32,
},
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RoadMarkLine {
pub color: String,
pub width: f32,
pub t_offset: f32,
pub s_offset: f32,
pub pattern: LinePattern,
pub rule: LineRule,
pub pieces: Vec<[Point; 4]>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RoadMark {
pub id: RoadMarkId,
pub kind: RoadMarkType,
pub weight: RoadMarkWeight,
pub color: String,
pub width: f32,
pub height: Option<f32>,
pub lane_change: LaneChange,
pub left: Option<LaneId>,
pub right: Option<LaneId>,
pub lines: Vec<RoadMarkLine>,
}