WIP - drawlib - new geometry

pull/3662/head
cepetr 1 month ago
parent 446eb6763b
commit 174ab733ac

@ -30,7 +30,7 @@ impl Default for Dma2d {
impl Dma2d {
pub fn new_fill(r: Rect, clip: Rect, color: Color, alpha: u8) -> Option<Self> {
let r = r.intersect(clip);
let r = r.clamp(clip);
if !r.is_empty() {
Some(
Self::default()
@ -59,7 +59,7 @@ impl Dma2d {
}
// Clip with the canvas viewport
let mut r = r_dst.intersect(clip);
let mut r = r_dst.clamp(clip);
// Clip with the bitmap top-left
if r.x0 > r_dst.x0 {

@ -826,6 +826,22 @@ fn fill_octant(
}
}
impl Rect {
/// Normalizes the rectangle coordinates.
///
/// Returns a new `Rect` with potentially swapped left/right,
/// top/bottom coordinates, ensuring that `x0`, `y0` represents
/// the top-left corner and `x1`, `y1` represents the bottom-right corner.
pub fn normalize(&self) -> Self {
Rect {
x0: core::cmp::min(self.x0, self.x1),
y0: core::cmp::min(self.y0, self.y1),
x1: core::cmp::max(self.x0, self.x1),
y1: core::cmp::max(self.y0, self.y1),
}
}
}
impl Point {
fn onleft(self) -> Self {
Self {

@ -94,9 +94,7 @@ impl<'a> Canvas for Rgb565Canvas<'a> {
#[cfg(feature = "ui_blurring")]
fn blur_rect(&mut self, r: Rect, radius: usize, cache: &DrawingCache) {
let clip = r
.translate(self.viewport.origin)
.intersect(self.viewport.clip);
let clip = r.translate(self.viewport.origin).clamp(self.viewport.clip);
let ofs = radius as i16;

@ -56,7 +56,7 @@ impl Viewport {
/// Checks if the viewport intersects with the specified rectangle
/// given in relative coordinates.
pub fn contains(&self, r: Rect) -> bool {
r.translate(self.origin).has_intersection(self.clip)
!r.translate(self.origin).clamp(self.clip).is_empty()
}
pub fn translate(self, offset: Offset) -> Self {
@ -77,7 +77,7 @@ impl Viewport {
/// remains unchanged.
pub fn absolute_clip(self, r: Rect) -> Self {
Self {
clip: r.intersect(self.clip),
clip: r.clamp(self.clip),
..self
}
}
@ -87,7 +87,7 @@ impl Viewport {
/// remains unchanged.
pub fn relative_clip(self, r: Rect) -> Self {
Self {
clip: r.translate(self.origin).intersect(self.clip),
clip: r.translate(self.origin).clamp(self.clip),
..self
}
}
@ -96,7 +96,7 @@ impl Viewport {
/// given in relative coordinates. The origin of the new viewport
/// is set to the top-left corner of the rectangle.
pub fn relative_window(&self, r: Rect) -> Self {
let clip = r.translate(self.origin).intersect(self.clip);
let clip = r.translate(self.origin).clamp(self.clip);
let origin = self.origin + (clip.top_left() - self.clip.top_left());
Self { clip, origin }
}

@ -57,7 +57,7 @@ impl<'a> ToifImage<'a> {
let viewport = canvas.viewport();
let mut clip = self
.bounds(cache)
.intersect(viewport.clip.translate(-viewport.origin))
.clamp(viewport.clip.translate(-viewport.origin))
.translate((-bounds.top_left()).into());
let buff = &mut unwrap!(cache.image_buff(), "No image buffer");
@ -105,7 +105,7 @@ impl<'a> ToifImage<'a> {
let viewport = canvas.viewport();
let mut clip = self
.bounds(cache)
.intersect(viewport.clip.translate(-viewport.origin))
.clamp(viewport.clip.translate(-viewport.origin))
.translate((-bounds.top_left()).into());
let buff = &mut unwrap!(cache.image_buff(), "No image buffer");

Loading…
Cancel
Save