use tiny_skia::Pixmap;
use crate::Snapr;
pub mod geometry;
pub mod style;
#[cfg(feature = "svg")]
pub mod svg;
#[derive(Debug, Clone)]
pub struct Context<'a> {
pub snapr: &'a Snapr<'a>,
pub center: geo::Point<f64>,
pub zoom: u8,
pub index: usize,
}
impl<'a> Context<'a> {
pub fn epsg_4326_to_pixel(&self, coord: &geo::Coord<f64>) -> geo::Coord<i32> {
let epsg_3857_point = Snapr::epsg_4326_to_epsg_3857(self.zoom, geo::Point::from(*coord))
- Snapr::epsg_4326_to_epsg_3857(self.zoom, self.center);
geo::coord!(
x: (epsg_3857_point.x().fract() * self.snapr.tile_size as f64 + self.snapr.width as f64 / 2.0).round() as i32,
y: (epsg_3857_point.y().fract() * self.snapr.tile_size as f64 + self.snapr.height as f64 / 2.0).round() as i32,
)
}
}
pub trait Drawable {
fn draw(&self, pixmap: &mut Pixmap, context: &Context) -> Result<(), crate::Error>;
fn as_geometry(&self) -> Option<geo::Geometry<f64>> {
None
}
}