use crate::{Id, IdGenerator};
pub(crate) trait Datum {
fn all_variables(&self) -> impl IntoIterator<Item = Id>;
}
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "fuzz", derive(arbitrary::Arbitrary))]
pub struct DatumDistance {
pub id: Id,
}
impl DatumDistance {
pub fn new(id: Id) -> Self {
Self { id }
}
}
impl Datum for DatumDistance {
fn all_variables(&self) -> impl IntoIterator<Item = Id> {
[self.id]
}
}
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "fuzz", derive(arbitrary::Arbitrary))]
pub struct DatumPoint {
pub x_id: Id,
pub y_id: Id,
}
impl DatumPoint {
pub fn new(id_generator: &mut IdGenerator) -> Self {
Self {
x_id: id_generator.next_id(),
y_id: id_generator.next_id(),
}
}
pub fn new_xy(x: Id, y: Id) -> Self {
Self { x_id: x, y_id: y }
}
#[inline(always)]
pub fn id_x(&self) -> Id {
self.x_id
}
#[inline(always)]
pub fn id_y(&self) -> Id {
self.y_id
}
}
impl Datum for DatumPoint {
fn all_variables(&self) -> impl IntoIterator<Item = Id> {
[self.id_x(), self.id_y()]
}
}
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "fuzz", derive(arbitrary::Arbitrary))]
pub struct DatumLineSegment {
pub p0: DatumPoint,
pub p1: DatumPoint,
}
impl DatumLineSegment {
pub fn new(p0: DatumPoint, p1: DatumPoint) -> Self {
Self { p0, p1 }
}
}
impl Datum for DatumLineSegment {
fn all_variables(&self) -> impl IntoIterator<Item = Id> {
[
self.p0.id_x(),
self.p0.id_y(),
self.p1.id_x(),
self.p1.id_y(),
]
}
}
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "fuzz", derive(arbitrary::Arbitrary))]
pub struct DatumCircle {
pub center: DatumPoint,
pub radius: DatumDistance,
}
impl Datum for DatumCircle {
fn all_variables(&self) -> impl IntoIterator<Item = Id> {
[self.center.id_x(), self.center.id_y(), self.radius.id]
}
}
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "fuzz", derive(arbitrary::Arbitrary))]
pub struct DatumCircularArc {
pub center: DatumPoint,
pub start: DatumPoint,
pub end: DatumPoint,
}
impl Datum for DatumCircularArc {
fn all_variables(&self) -> impl IntoIterator<Item = Id> {
[
self.start.id_x(),
self.start.id_y(),
self.end.id_x(),
self.end.id_y(),
self.center.id_x(),
self.center.id_y(),
]
}
}