use bevy_math::Vec2;
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
#[derive(Default, Copy, Clone, PartialEq, Debug, Reflect)]
#[reflect(Clone, PartialEq, Default)]
pub struct BorderRect {
pub min_inset: Vec2,
pub max_inset: Vec2,
}
impl BorderRect {
pub const ZERO: Self = Self::all(0.);
#[must_use]
#[inline]
pub const fn all(inset: f32) -> Self {
Self {
min_inset: Vec2::splat(inset),
max_inset: Vec2::splat(inset),
}
}
#[must_use]
#[inline]
pub const fn axes(horizontal: f32, vertical: f32) -> Self {
let insets = Vec2::new(horizontal, vertical);
Self {
min_inset: insets,
max_inset: insets,
}
}
}
impl From<f32> for BorderRect {
fn from(inset: f32) -> Self {
Self::all(inset)
}
}
impl From<[f32; 4]> for BorderRect {
fn from([min_x, max_x, min_y, max_y]: [f32; 4]) -> Self {
Self {
min_inset: Vec2::new(min_x, min_y),
max_inset: Vec2::new(max_x, max_y),
}
}
}
impl core::ops::Add for BorderRect {
type Output = Self;
fn add(mut self, rhs: Self) -> Self::Output {
self.min_inset += rhs.min_inset;
self.max_inset += rhs.max_inset;
self
}
}
impl core::ops::Sub for BorderRect {
type Output = Self;
fn sub(mut self, rhs: Self) -> Self::Output {
self.min_inset -= rhs.min_inset;
self.max_inset -= rhs.max_inset;
self
}
}
impl core::ops::Mul<f32> for BorderRect {
type Output = Self;
fn mul(mut self, rhs: f32) -> Self::Output {
self.min_inset *= rhs;
self.max_inset *= rhs;
self
}
}
impl core::ops::Div<f32> for BorderRect {
type Output = Self;
fn div(mut self, rhs: f32) -> Self::Output {
self.min_inset /= rhs;
self.max_inset /= rhs;
self
}
}