Add recurse arg to get_bounds

libcentric
Jan Petykiewicz 1 year ago
parent 3758df6938
commit 7fc0902fe7

@ -286,12 +286,16 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable):
def get_bounds( def get_bounds(
self, self,
library: Optional[Mapping[str, 'Pattern']] = None, library: Optional[Mapping[str, 'Pattern']] = None,
recurse: bool = True,
) -> Optional[NDArray[numpy.float64]]: ) -> Optional[NDArray[numpy.float64]]:
""" """
Return a `numpy.ndarray` containing `[[x_min, y_min], [x_max, y_max]]`, corresponding to the Return a `numpy.ndarray` containing `[[x_min, y_min], [x_max, y_max]]`, corresponding to the
extent of the Pattern's contents in each dimension. extent of the Pattern's contents in each dimension.
Returns `None` if the Pattern is empty. Returns `None` if the Pattern is empty.
Args:
TODO docs for get_bounds
Returns: Returns:
`[[x_min, y_min], [x_max, y_max]]` or `None` `[[x_min, y_min], [x_max, y_max]]` or `None`
""" """
@ -311,12 +315,13 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable):
if self.refs and (library is None): if self.refs and (library is None):
raise PatternError('Must provide a library to get_bounds() to resolve refs') raise PatternError('Must provide a library to get_bounds() to resolve refs')
for entry in self.refs: if recurse:
bounds = entry.get_bounds(library=library) for entry in self.refs:
if bounds is None: bounds = entry.get_bounds(library=library)
continue if bounds is None:
min_bounds = numpy.minimum(min_bounds, bounds[0, :]) continue
max_bounds = numpy.maximum(max_bounds, bounds[1, :]) min_bounds = numpy.minimum(min_bounds, bounds[0, :])
max_bounds = numpy.maximum(max_bounds, bounds[1, :])
if (max_bounds < min_bounds).any(): if (max_bounds < min_bounds).any():
return None return None
@ -326,10 +331,14 @@ class Pattern(PortList, AnnotatableImpl, Mirrorable):
def get_bounds_nonempty( def get_bounds_nonempty(
self, self,
library: Optional[Mapping[str, 'Pattern']] = None, library: Optional[Mapping[str, 'Pattern']] = None,
recurse: bool = True,
) -> NDArray[numpy.float64]: ) -> NDArray[numpy.float64]:
""" """
Convenience wrapper for `get_bounds()` which asserts that the Pattern as non-None bounds. Convenience wrapper for `get_bounds()` which asserts that the Pattern as non-None bounds.
Args:
TODO docs for get_bounds
Returns: Returns:
`[[x_min, y_min], [x_max, y_max]]` `[[x_min, y_min], [x_max, y_max]]`
""" """

Loading…
Cancel
Save