File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -227,6 +227,16 @@ impl Document {
227227 Ok ( ( ) )
228228 }
229229
230+ pub fn layer_axis_aligned_bounding_box ( & self , path : & [ LayerId ] ) -> Result < [ DVec2 ; 2 ] , DocumentError > {
231+ let layer = self . layer ( path) ?;
232+ Ok ( layer. bounding_box ( self . root . transform * layer. transform , layer. style ) )
233+ }
234+
235+ pub fn layer_local_bounding_box ( & self , path : & [ LayerId ] ) -> Result < [ DVec2 ; 2 ] , DocumentError > {
236+ let layer = self . layer ( path) ?;
237+ Ok ( layer. bounding_box ( layer. transform , layer. style ) )
238+ }
239+
230240 fn mark_as_dirty ( & mut self , path : & [ LayerId ] ) -> Result < ( ) , DocumentError > {
231241 let mut root = & mut self . root ;
232242 root. cache_dirty = true ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ pub use ellipse::Ellipse;
66pub mod line;
77use glam:: { DMat2 , DVec2 } ;
88use kurbo:: BezPath ;
9+ use kurbo:: Shape as KurboShape ;
910pub use line:: Line ;
1011
1112pub mod rect;
@@ -100,6 +101,12 @@ impl LayerDataTypes {
100101 }
101102 }
102103 }
104+
105+ pub fn bounding_box ( & self , transform : glam:: DAffine2 , style : style:: PathStyle ) -> [ DVec2 ; 2 ] {
106+ let bez_path = self . to_kurbo_path ( transform, style) ;
107+ let bbox = bez_path. bounding_box ( ) ;
108+ [ DVec2 :: new ( bbox. x0 , bbox. y0 ) , DVec2 :: new ( bbox. x1 , bbox. y1 ) ]
109+ }
103110}
104111
105112#[ derive( Serialize , Deserialize ) ]
@@ -168,6 +175,10 @@ impl Layer {
168175 self . data . to_kurbo_path ( self . transform , self . style )
169176 }
170177
178+ pub fn bounding_box ( & self , transform : glam:: DAffine2 , style : style:: PathStyle ) -> [ DVec2 ; 2 ] {
179+ self . data . bounding_box ( transform, style)
180+ }
181+
171182 pub fn as_folder_mut ( & mut self ) -> Result < & mut Folder , DocumentError > {
172183 match & mut self . data {
173184 LayerDataTypes :: Folder ( f) => Ok ( f) ,
You can’t perform that action at this time.
0 commit comments