-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bbox): implement LayerBbox trait
The LayerBbox trait allows users to find bounding boxes considering only the geometry on a specific LayerId.
- Loading branch information
Showing
5 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//! Bounding box utilities. | ||
use crate::pdk::layers::LayerId; | ||
use geometry::prelude::*; | ||
use geometry::union::BoundingUnion; | ||
|
||
/// A trait representing functions available for multi-layered objects with bounding boxes. | ||
pub trait LayerBbox: Bbox { | ||
/// Compute the bounding box considering only objects occupying the given layer. | ||
fn layer_bbox(&self, layer: LayerId) -> Option<Rect>; | ||
} | ||
|
||
impl<T: LayerBbox> LayerBbox for Vec<T> { | ||
fn layer_bbox(&self, layer: LayerId) -> Option<Rect> { | ||
let mut bbox = None; | ||
for item in self { | ||
bbox = bbox.bounding_union(&item.layer_bbox(layer)); | ||
} | ||
bbox | ||
} | ||
} | ||
|
||
impl<T: LayerBbox> LayerBbox for &T { | ||
fn layer_bbox(&self, layer: LayerId) -> Option<Rect> { | ||
(*self).layer_bbox(layer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters