mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-12-23 10:11:54 +00:00
Add a document method that returns a layer's bounding box (#273)
* Add a document method that returns a layer's bounding box * Moved `use` to the top of the file * Add layer local bounding box method
This commit is contained in:
parent
1b37e78d64
commit
6648e244a0
2 changed files with 21 additions and 0 deletions
|
|
@ -227,6 +227,16 @@ impl Document {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn layer_axis_aligned_bounding_box(&self, path: &[LayerId]) -> Result<[DVec2; 2], DocumentError> {
|
||||
let layer = self.layer(path)?;
|
||||
Ok(layer.bounding_box(self.root.transform * layer.transform, layer.style))
|
||||
}
|
||||
|
||||
pub fn layer_local_bounding_box(&self, path: &[LayerId]) -> Result<[DVec2; 2], DocumentError> {
|
||||
let layer = self.layer(path)?;
|
||||
Ok(layer.bounding_box(layer.transform, layer.style))
|
||||
}
|
||||
|
||||
fn mark_as_dirty(&mut self, path: &[LayerId]) -> Result<(), DocumentError> {
|
||||
let mut root = &mut self.root;
|
||||
root.cache_dirty = true;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ pub use ellipse::Ellipse;
|
|||
pub mod line;
|
||||
use glam::{DMat2, DVec2};
|
||||
use kurbo::BezPath;
|
||||
use kurbo::Shape as KurboShape;
|
||||
pub use line::Line;
|
||||
|
||||
pub mod rect;
|
||||
|
|
@ -100,6 +101,12 @@ impl LayerDataTypes {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bounding_box(&self, transform: glam::DAffine2, style: style::PathStyle) -> [DVec2; 2] {
|
||||
let bez_path = self.to_kurbo_path(transform, style);
|
||||
let bbox = bez_path.bounding_box();
|
||||
[DVec2::new(bbox.x0, bbox.y0), DVec2::new(bbox.x1, bbox.y1)]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
|
@ -168,6 +175,10 @@ impl Layer {
|
|||
self.data.to_kurbo_path(self.transform, self.style)
|
||||
}
|
||||
|
||||
pub fn bounding_box(&self, transform: glam::DAffine2, style: style::PathStyle) -> [DVec2; 2] {
|
||||
self.data.bounding_box(transform, style)
|
||||
}
|
||||
|
||||
pub fn as_folder_mut(&mut self) -> Result<&mut Folder, DocumentError> {
|
||||
match &mut self.data {
|
||||
LayerDataTypes::Folder(f) => Ok(f),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue