diff options
Diffstat (limited to 'tiny_skia/src/primitive.rs')
-rw-r--r-- | tiny_skia/src/primitive.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tiny_skia/src/primitive.rs b/tiny_skia/src/primitive.rs index 5305788d..5de51047 100644 --- a/tiny_skia/src/primitive.rs +++ b/tiny_skia/src/primitive.rs @@ -1,3 +1,5 @@ +use crate::core::Rectangle; + #[derive(Debug, Clone, PartialEq)] pub enum Primitive { /// A path filled with some paint. @@ -19,3 +21,20 @@ pub enum Primitive { stroke: tiny_skia::Stroke, }, } + +impl Primitive { + /// Returns the visible bounds of the [`Primitive`]. + pub fn visible_bounds(&self) -> Rectangle { + let bounds = match self { + Primitive::Fill { path, .. } => path.bounds(), + Primitive::Stroke { path, .. } => path.bounds(), + }; + + Rectangle { + x: bounds.x(), + y: bounds.y(), + width: bounds.width(), + height: bounds.height(), + } + } +} |