From c4354e2d8d51cc9fc12dce9ad2d5736e400a8de4 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 4 Apr 2021 15:39:17 +0530 Subject: basic support for adding guides --- src/bitmap.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/bitmap.rs') diff --git a/src/bitmap.rs b/src/bitmap.rs index 2bf8556..8010a4b 100644 --- a/src/bitmap.rs +++ b/src/bitmap.rs @@ -4,6 +4,8 @@ use std::{ ops::{Add, Sub}, }; +use crate::lisp::{error::EvalError, expr::LispExpr}; + #[derive(Debug)] pub struct Pixmap { pub width: u32, @@ -71,12 +73,38 @@ impl Sub for MapPoint { } } -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum Axis { X, Y, } +impl Into for Axis { + fn into(self) -> LispExpr { + LispExpr::Quote( + Box::new(LispExpr::Ident(match self { + Self::X => "X".into(), + Self::Y => "Y".into(), + })), + 1, + ) + } +} + +impl TryFrom<&LispExpr> for Axis { + type Error = EvalError; + fn try_from(value: &LispExpr) -> Result { + match value { + LispExpr::Ident(id) => match id.as_ref() { + "x" => Ok(Axis::X), + "y" => Ok(Axis::Y), + _ => Err(EvalError::TypeMismatch), + }, + _ => Err(EvalError::TypeMismatch), + } + } +} + #[derive(Debug, Copy, Clone)] pub enum Quadrant { I, -- cgit v1.2.3