pub type Coord = f32;
pub type Point = euclid::default::Point2D<Coord>;
pub type Rect = euclid::default::Rect<Coord>;
pub type Size = euclid::default::Size2D<Coord>;
pub type IntCoord = i32;
pub type IntPoint = euclid::default::Point2D<IntCoord>;
pub type IntRect = euclid::default::Rect<IntCoord>;
pub type IntSize = euclid::default::Size2D<IntCoord>;
pub type IntVector = euclid::default::Vector2D<IntCoord>;
pub type UintSize = euclid::default::Size2D<u32>;
#[allow(missing_docs)]
pub trait Corners {
fn top_left(&self) -> Point;
fn top_right(&self) -> Point;
fn bottom_left(&self) -> Point;
fn bottom_right(&self) -> Point;
}
impl Corners for Rect {
fn top_left(&self) -> Point {
euclid::point2(self.min_x(), self.min_y())
}
fn top_right(&self) -> Point {
euclid::point2(self.max_x(), self.min_y())
}
fn bottom_left(&self) -> Point {
euclid::point2(self.min_x(), self.max_y())
}
fn bottom_right(&self) -> Point {
euclid::point2(self.max_x(), self.max_y())
}
}
pub(crate) trait LimitToBounds {
fn limit_to_bounds(&self, point: IntPoint) -> IntPoint;
}
impl LimitToBounds for IntRect {
fn limit_to_bounds(&self, point: IntPoint) -> IntPoint {
let x = point.x.min(self.max_x()).max(self.min_x());
let y = point.y.min(self.max_y()).max(self.min_y());
euclid::point2(x, y)
}
}