use crate::geometry::Dimensions;
pub mod circle;
pub mod line;
pub mod rectangle;
pub mod triangle;
pub trait Primitive: Dimensions {}
pub use self::circle::Circle;
pub use self::line::Line;
pub use self::rectangle::Rectangle;
pub use self::triangle::Triangle;
#[macro_export]
macro_rules! egcircle {
(($cx:expr, $cy:expr), $r:expr $(, $style_key:ident = $style_value:expr )* $(,)?) => {{
#[allow(unused_imports)]
use $crate::style::WithStyle;
$crate::primitives::Circle::new($crate::geometry::Point::new($cx, $cy), $r)
$( .$style_key($style_value) )*
}};
}
#[macro_export]
macro_rules! egline {
(($x1:expr, $y1:expr), ($x2:expr, $y2:expr) $(, $style_key:ident = $style_value:expr )* $(,)?) => {{
#[allow(unused_imports)]
use $crate::style::WithStyle;
$crate::primitives::Line::new($crate::geometry::Point::new($x1, $y1), $crate::geometry::Point::new($x2, $y2))
$( .$style_key($style_value) )*
}};
}
#[macro_export]
macro_rules! egrectangle {
(($x1:expr, $y1:expr), ($x2:expr, $y2:expr) $(, $style_key:ident = $style_value:expr )* $(,)?) => {{
#[allow(unused_imports)]
use $crate::style::WithStyle;
$crate::primitives::Rectangle::new($crate::geometry::Point::new($x1, $y1), $crate::geometry::Point::new($x2, $y2))
$( .$style_key($style_value) )*
}};
}
#[macro_export]
macro_rules! egtriangle {
(($x1:expr, $y1:expr), ($x2:expr, $y2:expr), ($x3:expr, $y3:expr) $(, $style_key:ident = $style_value:expr )* $(,)?) => {{
#[allow(unused_imports)]
use $crate::style::WithStyle;
$crate::primitives::Triangle::new($crate::geometry::Point::new($x1, $y1), $crate::geometry::Point::new($x2, $y2), $crate::geometry::Point::new($x3, $y3))
$( .$style_key($style_value) )*
}};
}
#[cfg(test)]
mod tests {
use super::*;
use crate::pixelcolor::{Rgb565, RgbColor};
use crate::style::Style;
#[test]
fn circle() {
let _c: Circle<Rgb565> = egcircle!((10, 20), 30);
let _c: Circle<Rgb565> = egcircle!(
(10, 20),
30,
stroke = Some(Rgb565::RED),
fill = Some(Rgb565::GREEN)
);
let _c: Circle<Rgb565> = egcircle!((10, 20), 30, style = Style::default());
}
#[test]
fn line() {
let _l: Line<Rgb565> = egline!((10, 20), (30, 40));
let _l: Line<Rgb565> = egline!(
(10, 20),
(30, 40),
stroke = Some(Rgb565::RED),
fill = Some(Rgb565::GREEN)
);
let _l: Line<Rgb565> = egline!((10, 20), (30, 40), style = Style::default());
}
#[test]
fn rectangle() {
let _r: Rectangle<Rgb565> = egrectangle!((10, 20), (30, 40));
let _r: Rectangle<Rgb565> = egrectangle!(
(10, 20),
(30, 40),
stroke = Some(Rgb565::RED),
fill = Some(Rgb565::GREEN)
);
let _r: Rectangle<Rgb565> = egrectangle!((10, 20), (30, 40), style = Style::default());
}
#[test]
fn triangle() {
let _t: Triangle<Rgb565> = egtriangle!((10, 20), (30, 40), (50, 60));
let _t: Triangle<Rgb565> = egtriangle!(
(10, 20),
(30, 40),
(50, 60),
stroke = Some(Rgb565::RED),
fill = Some(Rgb565::GREEN)
);
let _t: Triangle<Rgb565> =
egtriangle!((10, 20), (30, 40), (50, 60), style = Style::default());
}
}