#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct LogicalPoint {
pub x: f32,
pub y: f32,
}
impl LogicalPoint {
pub fn new(x: f32, y: f32) -> Self {
LogicalPoint { x, y }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct LogicalSize {
pub width: f32,
pub height: f32,
}
impl LogicalSize {
pub fn new(width: f32, height: f32) -> Self {
LogicalSize { width, height }
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct LogicalRect {
pub origin: LogicalPoint,
pub size: LogicalSize,
}
impl LogicalRect {
pub fn new(origin: LogicalPoint, size: LogicalSize) -> Self {
LogicalRect { origin, size }
}
pub fn max_x(&self) -> f32 {
self.origin.x + self.size.width
}
pub fn max_y(&self) -> f32 {
self.origin.y + self.size.height
}
pub fn contains(&self, p: LogicalPoint) -> bool {
p.x >= self.origin.x && p.x < self.max_x() && p.y >= self.origin.y && p.y < self.max_y()
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Edge {
#[default]
Bottom,
Top,
Left,
Right,
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub struct Insets {
pub top: f32,
pub right: f32,
pub bottom: f32,
pub left: f32,
}
impl Insets {
pub fn uniform(v: f32) -> Self {
Insets {
top: v,
right: v,
bottom: v,
left: v,
}
}
pub fn symmetric(horizontal: f32, vertical: f32) -> Self {
Insets {
top: vertical,
right: horizontal,
bottom: vertical,
left: horizontal,
}
}
pub fn horizontal(&self) -> f32 {
self.left + self.right
}
pub fn vertical(&self) -> f32 {
self.top + self.bottom
}
}