use crate::{
math::{relative_source_rectangle, Scalar},
types::SourceRectangle,
};
pub trait SourceRectangled {
fn src_rect(self, x: Scalar, y: Scalar, w: Scalar, h: Scalar) -> Self;
fn src_rel(self, x: Scalar, y: Scalar) -> Self;
fn src_flip_h(self) -> Self;
fn src_flip_v(self) -> Self;
fn src_flip_hv(self) -> Self;
}
impl SourceRectangled for SourceRectangle {
#[inline(always)]
fn src_rect(self, x: Scalar, y: Scalar, w: Scalar, h: Scalar) -> Self {
[x, y, w, h]
}
#[inline(always)]
fn src_rel(self, x: Scalar, y: Scalar) -> Self {
relative_source_rectangle(self, x, y)
}
#[inline(always)]
fn src_flip_h(self) -> Self {
[self[0] + self[2], self[1], -self[2], self[3]]
}
#[inline(always)]
fn src_flip_v(self) -> Self {
[self[0], self[1] + self[3], self[2], -self[3]]
}
#[inline(always)]
fn src_flip_hv(self) -> Self {
[self[0] + self[2], self[1] + self[3], -self[2], -self[3]]
}
}