From 4acdcea1bc2329917e6d499d11361956d94c870f Mon Sep 17 00:00:00 2001 From: n4n5 Date: Thu, 6 Aug 2026 13:29:05 +0200 Subject: [PATCH 1/5] fix: change the to_int_rect method --- examples/image_on_image.rs | 18 ++++++++++-------- path/src/size.rs | 4 ++-- src/mask.rs | 4 ++-- src/painter.rs | 16 ++++++++++++---- src/pixmap.rs | 2 +- tests/integration/mask.rs | 2 +- tests/integration/pixmap.rs | 6 +++--- 7 files changed, 31 insertions(+), 21 deletions(-) diff --git a/examples/image_on_image.rs b/examples/image_on_image.rs index ef284cd..152cb7e 100644 --- a/examples/image_on_image.rs +++ b/examples/image_on_image.rs @@ -10,14 +10,16 @@ fn main() { let mut paint = PixmapPaint::default(); paint.quality = FilterQuality::Bicubic; - pixmap.draw_pixmap( - 20, - 20, - triangle.as_ref(), - &paint, - Transform::from_row(1.2, 0.5, 0.5, 1.2, 0.0, 0.0), - None, - ); + pixmap + .draw_pixmap( + 20, + 20, + triangle.as_ref(), + &paint, + Transform::from_row(1.2, 0.5, 0.5, 1.2, 0.0, 0.0), + None, + ) + .unwrap(); println!( "Rendered in {:.2}ms", diff --git a/path/src/size.rs b/path/src/size.rs index b314cae..18a502d 100644 --- a/path/src/size.rs +++ b/path/src/size.rs @@ -84,8 +84,8 @@ impl IntSize { } /// Converts into [`IntRect`] at the provided position. - pub fn to_int_rect(&self, x: i32, y: i32) -> IntRect { - IntRect::from_xywh(x, y, self.width(), self.height()).unwrap() + pub fn to_int_rect(&self, x: i32, y: i32) -> Option { + IntRect::from_xywh(x, y, self.width(), self.height()) } } diff --git a/src/mask.rs b/src/mask.rs index 420a813..f4d6364 100644 --- a/src/mask.rs +++ b/src/mask.rs @@ -146,7 +146,7 @@ impl Mask { } pub(crate) fn submask(&self, rect: IntRect) -> Option> { - let rect = self.size.to_int_rect(0, 0).intersect(&rect)?; + let rect = self.size.to_int_rect(0, 0)?.intersect(&rect)?; let row_bytes = self.width() as usize; let offset = rect.top() as usize * row_bytes + rect.left() as usize; @@ -166,7 +166,7 @@ impl Mask { } pub(crate) fn subpixmap(&mut self, rect: IntRect) -> Option> { - let rect = self.size.to_int_rect(0, 0).intersect(&rect)?; + let rect = self.size.to_int_rect(0, 0)?.intersect(&rect)?; let row_bytes = self.width() as usize; let offset = rect.top() as usize * row_bytes + rect.left() as usize; diff --git a/src/painter.rs b/src/painter.rs index 624e00a..aebff2e 100644 --- a/src/painter.rs +++ b/src/painter.rs @@ -160,9 +160,9 @@ impl Pixmap { paint: &PixmapPaint, transform: Transform, mask: Option<&Mask>, - ) { + ) -> std::io::Result<()> { self.as_mut() - .draw_pixmap(x, y, pixmap, paint, transform, mask); + .draw_pixmap(x, y, pixmap, paint, transform, mask) } /// Applies a masks. @@ -477,8 +477,15 @@ impl PixmapMut<'_> { paint: &PixmapPaint, transform: Transform, mask: Option<&Mask>, - ) { - let rect = pixmap.size().to_int_rect(x, y).to_rect(); + ) -> std::io::Result<()> { + let rect = pixmap + .size() + .to_int_rect(x, y) + .ok_or(std::io::Error::new( + std::io::ErrorKind::InvalidInput, + "Cannot convert the size to a rect", + ))? + .to_rect(); // TODO: SkSpriteBlitter // TODO: partially clipped @@ -502,6 +509,7 @@ impl PixmapMut<'_> { }; self.fill_rect(rect, &paint, transform, mask); + Ok(()) } /// Applies a masks. diff --git a/src/pixmap.rs b/src/pixmap.rs index e576ef2..22d014f 100644 --- a/src/pixmap.rs +++ b/src/pixmap.rs @@ -542,7 +542,7 @@ impl<'a> PixmapMut<'a> { /// /// Returns `None` when `Pixmap`'s rect doesn't contain `rect`. pub(crate) fn subpixmap(&mut self, rect: IntRect) -> Option> { - let rect = self.size.to_int_rect(0, 0).intersect(&rect)?; + let rect = self.size.to_int_rect(0, 0)?.intersect(&rect)?; let row_bytes = self.width() as usize * BYTES_PER_PIXEL; let offset = rect.top() as usize * row_bytes + rect.left() as usize * BYTES_PER_PIXEL; diff --git a/tests/integration/mask.rs b/tests/integration/mask.rs index 6a48ae2..2ebd1cd 100644 --- a/tests/integration/mask.rs +++ b/tests/integration/mask.rs @@ -129,7 +129,7 @@ fn skip_dest() { mask.fill_path(&clip_path, FillRule::Winding, true, Transform::default()); pixmap.draw_pixmap(0, 0, pixmap2.as_ref(), &PixmapPaint::default(), - Transform::identity(), Some(&mask)); + Transform::identity(), Some(&mask)).unwrap(); let expected = Pixmap::load_png("tests/images/mask/skip-dest.png").unwrap(); assert_eq!(pixmap, expected); diff --git a/tests/integration/pixmap.rs b/tests/integration/pixmap.rs index 1dda753..6b46feb 100644 --- a/tests/integration/pixmap.rs +++ b/tests/integration/pixmap.rs @@ -95,7 +95,7 @@ fn draw_pixmap() { paint.quality = FilterQuality::Bicubic; let mut pixmap = Pixmap::new(200, 200).unwrap(); - pixmap.draw_pixmap(20, 20, sub_pixmap.as_ref(), &paint, Transform::identity(), None); + pixmap.draw_pixmap(20, 20, sub_pixmap.as_ref(), &paint, Transform::identity(), None).unwrap(); let expected = Pixmap::load_png("tests/images/canvas/draw-pixmap.png").unwrap(); assert_eq!(pixmap, expected); @@ -130,7 +130,7 @@ fn draw_pixmap_ts() { &paint, Transform::from_row(1.2, 0.5, 0.5, 1.2, 0.0, 0.0), None, - ); + ).unwrap(); let expected = Pixmap::load_png("tests/images/canvas/draw-pixmap-ts.png").unwrap(); assert_eq!(pixmap, expected); @@ -166,7 +166,7 @@ fn draw_pixmap_opacity() { &paint, Transform::from_row(1.2, 0.5, 0.5, 1.2, 0.0, 0.0), None, - ); + ).unwrap(); let expected = Pixmap::load_png("tests/images/canvas/draw-pixmap-opacity.png").unwrap(); assert_eq!(pixmap, expected); From a7a556321beabb5424c82de8d31fe0140841227f Mon Sep 17 00:00:00 2001 From: n4n5 Date: Thu, 6 Aug 2026 13:38:25 +0200 Subject: [PATCH 2/5] no std --- src/painter.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/painter.rs b/src/painter.rs index aebff2e..f39cb0e 100644 --- a/src/painter.rs +++ b/src/painter.rs @@ -28,6 +28,9 @@ pub enum FillRule { EvenOdd, } +#[derive(Debug)] +pub struct InvalidSize; + /// Controls how a shape should be painted. #[derive(Clone, PartialEq, Debug)] pub struct Paint<'a> { @@ -160,7 +163,7 @@ impl Pixmap { paint: &PixmapPaint, transform: Transform, mask: Option<&Mask>, - ) -> std::io::Result<()> { + ) -> Result<(), InvalidSize> { self.as_mut() .draw_pixmap(x, y, pixmap, paint, transform, mask) } @@ -477,14 +480,11 @@ impl PixmapMut<'_> { paint: &PixmapPaint, transform: Transform, mask: Option<&Mask>, - ) -> std::io::Result<()> { + ) -> Result<(), InvalidSize> { let rect = pixmap .size() .to_int_rect(x, y) - .ok_or(std::io::Error::new( - std::io::ErrorKind::InvalidInput, - "Cannot convert the size to a rect", - ))? + .ok_or(InvalidSize)? .to_rect(); // TODO: SkSpriteBlitter From 5b6904a7d5e2913365880d14d4bd2756b7f14a42 Mon Sep 17 00:00:00 2001 From: n4n5 Date: Thu, 6 Aug 2026 13:40:52 +0200 Subject: [PATCH 3/5] cleanup --- path/src/size.rs | 2 +- src/painter.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/path/src/size.rs b/path/src/size.rs index 18a502d..e4a0430 100644 --- a/path/src/size.rs +++ b/path/src/size.rs @@ -117,7 +117,7 @@ mod tests { let size = IntSize::from_wh(3, 4).unwrap(); assert_eq!( - size.to_int_rect(1, 2), + size.to_int_rect(1, 2).unwrap(), IntRect::from_xywh(1, 2, 3, 4).unwrap() ); } diff --git a/src/painter.rs b/src/painter.rs index f39cb0e..417a6a7 100644 --- a/src/painter.rs +++ b/src/painter.rs @@ -28,7 +28,8 @@ pub enum FillRule { EvenOdd, } -#[derive(Debug)] +/// Invalid Size +#[derive(Debug, Copy)] pub struct InvalidSize; /// Controls how a shape should be painted. From 85ef22ba73c6a2405e8e47de3008eebd719ff77e Mon Sep 17 00:00:00 2001 From: n4n5 Date: Thu, 6 Aug 2026 13:42:07 +0200 Subject: [PATCH 4/5] feat: add Clone --- src/painter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/painter.rs b/src/painter.rs index 417a6a7..ca835e5 100644 --- a/src/painter.rs +++ b/src/painter.rs @@ -29,7 +29,7 @@ pub enum FillRule { } /// Invalid Size -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct InvalidSize; /// Controls how a shape should be painted. From 38f90ab56f874f69134d2310d94c2fe1adbba0c2 Mon Sep 17 00:00:00 2001 From: n4n5 Date: Thu, 6 Aug 2026 14:43:04 +0200 Subject: [PATCH 5/5] trigger ci