use std::fmt::Display;
use super::Unit;
#[derive(Debug, PartialEq, PartialOrd, Clone, Copy)]
pub struct Point {
pub x: f32,
pub y: f32,
pub unit: Unit,
}
impl From<(f32, f32)> for Point {
fn from(value: (f32, f32)) -> Self {
Self::px(value.0, value.1)
}
}
impl Display for Point {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "point({}{},{}{})", self.x, self.unit, self.y, self.unit)
}
}
impl Point {
pub fn em(x: f32, y: f32) -> Self {
Self {
x,
y,
unit: Unit::Em,
}
}
pub fn ex(x: f32, y: f32) -> Self {
Self {
x,
y,
unit: Unit::Ex,
}
}
pub fn px(x: f32, y: f32) -> Self {
Self {
x,
y,
unit: Unit::Px,
}
}
pub fn inch(x: f32, y: f32) -> Self {
Self {
x,
y,
unit: Unit::In,
}
}
pub fn cm(x: f32, y: f32) -> Self {
Self {
x,
y,
unit: Unit::Cm,
}
}
pub fn mm(x: f32, y: f32) -> Self {
Self {
x,
y,
unit: Unit::Mm,
}
}
pub fn pt(x: f32, y: f32) -> Self {
Self {
x,
y,
unit: Unit::Pt,
}
}
pub fn pc(x: f32, y: f32) -> Self {
Self {
x,
y,
unit: Unit::Pc,
}
}
pub fn percentage(x: f32, y: f32) -> Self {
Self {
x,
y,
unit: Unit::Percentages,
}
}
}