mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-17 15:28:04 +08:00
Add support for folder bounding boxes (#276)
This commit is contained in:
committed by
Keavon Chambers
parent
59b817301d
commit
783b7801e6
@@ -141,7 +141,7 @@ impl Document {
|
||||
}
|
||||
|
||||
/// Returns a reference to the layer or folder at the path. Does not return an error for root
|
||||
pub fn document_layer(&mut self, path: &[LayerId]) -> Result<&Layer, DocumentError> {
|
||||
pub fn document_layer(&self, path: &[LayerId]) -> Result<&Layer, DocumentError> {
|
||||
if path.is_empty() {
|
||||
return Ok(&self.root);
|
||||
}
|
||||
@@ -227,13 +227,20 @@ 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_axis_aligned_bounding_box(&self, path: &[LayerId]) -> Result<Option<[DVec2; 2]>, DocumentError> {
|
||||
// TODO: Replace with functions of the transform api
|
||||
if let &[] = path {
|
||||
// Special case for root. Root's local is the documents global, so we avoid transforming its transform by itself.
|
||||
self.layer_local_bounding_box(path)
|
||||
} else {
|
||||
let layer = self.document_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)?;
|
||||
pub fn layer_local_bounding_box(&self, path: &[LayerId]) -> Result<Option<[DVec2; 2]>, DocumentError> {
|
||||
// TODO: Replace with functions of the transform api
|
||||
let layer = self.document_layer(path)?;
|
||||
Ok(layer.bounding_box(layer.transform, layer.style))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user