diff options
author | 2023-03-22 00:36:57 +0100 | |
---|---|---|
committer | 2023-04-04 02:08:02 +0200 | |
commit | 0f7abffc0e94b4bb9f8117db633bfd07d900eb93 (patch) | |
tree | 89b6606db2619574369bf8c4a29d5ef0ecb7969c /core/src/rectangle.rs | |
parent | 6fae8bf6cbe7155bcee42eaeba68e31564df057c (diff) | |
download | iced-0f7abffc0e94b4bb9f8117db633bfd07d900eb93.tar.gz iced-0f7abffc0e94b4bb9f8117db633bfd07d900eb93.tar.bz2 iced-0f7abffc0e94b4bb9f8117db633bfd07d900eb93.zip |
Draft (very) basic incremental rendering for `iced_tiny_skia`
Diffstat (limited to 'core/src/rectangle.rs')
-rw-r--r-- | core/src/rectangle.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/src/rectangle.rs b/core/src/rectangle.rs index 4fe91519..5cdcbe78 100644 --- a/core/src/rectangle.rs +++ b/core/src/rectangle.rs @@ -100,6 +100,30 @@ impl Rectangle<f32> { } } + /// Returns whether the [`Rectangle`] intersects with the given one. + pub fn intersects(&self, other: &Self) -> bool { + self.intersection(other).is_some() + } + + /// Computes the union with the given [`Rectangle`]. + pub fn union(&self, other: &Self) -> Self { + let x = self.x.min(other.x); + let y = self.y.min(other.y); + + let lower_right_x = (self.x + self.width).max(other.x + other.width); + let lower_right_y = (self.y + self.height).max(other.y + other.height); + + let width = lower_right_x - x; + let height = lower_right_y - y; + + Rectangle { + x, + y, + width, + height, + } + } + /// Snaps the [`Rectangle`] to __unsigned__ integer coordinates. pub fn snap(self) -> Rectangle<u32> { Rectangle { @@ -109,6 +133,16 @@ impl Rectangle<f32> { height: self.height as u32, } } + + /// Expands the [`Rectangle`] a given amount. + pub fn expand(self, amount: f32) -> Self { + Self { + x: self.x - amount, + y: self.y - amount, + width: self.width + amount * 2.0, + height: self.height + amount * 2.0, + } + } } impl std::ops::Mul<f32> for Rectangle<f32> { |