use crate::{Cell, Pos, ShapeId, StampMode, StampSink};
mod box_shape;
mod connector;
pub(crate) mod fragment;
mod line;
mod route;
mod text;
#[cfg(test)]
mod gallery;
pub use box_shape::BoxShape;
pub use connector::{Connector, Endpoint, Terminal};
pub use line::Line;
pub use text::{Text, TextShape};
pub trait Surface {
fn stamp(&mut self, at: Pos, cell: Cell);
}
pub struct FigureLayer<'a> {
sink: &'a mut dyn StampSink,
mode: StampMode,
owner: Option<ShapeId>,
}
impl<'a> FigureLayer<'a> {
#[must_use]
pub fn new(sink: &'a mut dyn StampSink, mode: StampMode) -> Self {
Self {
sink,
mode,
owner: None,
}
}
#[must_use]
pub fn stamped_by(sink: &'a mut dyn StampSink, mode: StampMode, owner: ShapeId) -> Self {
Self {
sink,
mode,
owner: Some(owner),
}
}
}
impl Surface for FigureLayer<'_> {
fn stamp(&mut self, at: Pos, cell: Cell) {
self.sink.stamp(at, cell, self.mode, self.owner);
}
}
pub trait Shape {
fn draw(&self, surface: &mut dyn Surface);
}
#[cfg(test)]
pub(crate) mod counting {
use std::collections::HashMap;
use super::{Cell, Pos, Surface};
#[derive(Default)]
pub(crate) struct CountingSurface {
counts: HashMap<(i16, i16), u16>,
}
impl CountingSurface {
pub(crate) fn max_writes(&self) -> u16 {
self.counts.values().copied().max().unwrap_or(0)
}
}
impl Surface for CountingSurface {
fn stamp(&mut self, at: Pos, _cell: Cell) {
*self.counts.entry((at.x, at.y)).or_default() += 1;
}
}
}