use crate::bind;
mod rect;
pub use rect::*;
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[must_use]
pub struct Point {
pub x: i32,
pub y: i32,
}
impl From<bind::SDL_Point> for Point {
#[allow(clippy::unnecessary_cast)]
fn from(bind::SDL_Point { x, y }: bind::SDL_Point) -> Self {
Self {
x: x as i32,
y: y as i32,
}
}
}
impl From<Point> for bind::SDL_Point {
fn from(Point { x, y }: Point) -> Self {
use std::os::raw::c_int;
Self {
x: x as c_int,
y: y as c_int,
}
}
}
impl Point {
pub fn offset(self, x: i32, y: i32) -> Self {
Self {
x: self.x + x,
y: self.y + y,
}
}
#[must_use]
pub fn is_in(&self, rect: Rect) -> bool {
let bottom_right = rect.bottom_right();
rect.up_left.x <= self.x
&& self.x <= bottom_right.x
&& rect.up_left.y <= self.y
&& self.y <= bottom_right.y
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[must_use]
pub struct Size {
pub width: u32,
pub height: u32,
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
#[must_use]
pub struct Scale {
pub horizontal: f32,
pub vertical: f32,
}
impl Default for Scale {
fn default() -> Self {
Self {
horizontal: 1.0,
vertical: 1.0,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
#[must_use]
pub struct Line {
pub start: Point,
pub end: Point,
}
impl Line {
pub fn clip_with(mut self, rect: Rect) -> Self {
unsafe {
bind::SDL_IntersectRectAndLine(
&(rect.into()),
&mut self.start.x,
&mut self.start.y,
&mut self.end.x,
&mut self.end.y,
);
}
self
}
}