def _get_bbox(self): """BBox(x1, y1, x2, y2) namedtuple of the shape.""" # TODO: Compute bezier curve. anchors = self._get_anchors() if not anchors or len(anchors) < 2: # Likely be all-pixel fill. return BBox(0, 0, self._psd.width, self._psd.height) return BBox(min([p[0] for p in anchors]), min([p[1] for p in anchors]), max([p[0] for p in anchors]), max([p[1] for p in anchors]))
def combined_bbox(layers): """ Returns a bounding box for ``layers`` or BBox(0, 0, 0, 0) if the layers have no bbox. """ bboxes = [layer.bbox for layer in layers if not layer.bbox.is_empty()] if len(bboxes) == 0: return BBox(0, 0, 0, 0) lefts, tops, rights, bottoms = zip(*bboxes) return BBox(min(lefts), min(tops), max(rights), max(bottoms))
def get_bbox(self, vector=False): """BBox(x1, y1, x2, y2) namedtuple of the shape.""" if vector: # TODO: Compute bezier curve. anchors = self.get_anchors() if not anchors or len(anchors) < 2: # Could be all pixel fill. return BBox(0, 0, 0, 0) return BBox(min([p[0] for p in anchors]), min([p[1] for p in anchors]), max([p[0] for p in anchors]), max([p[1] for p in anchors])) else: return super(ShapeLayer, self).bbox
def bbox(self): """BBox(x1, y1, x2, y2) namedtuple with layer bounding box. :rtype: BBox """ return BBox(self._record.left, self._record.top, self._record.right, self._record.bottom)
def _translate_unit_rect(data): items = dict(data.items) return BBox( items.get(b'Left').value, items.get(b'Top ').value, items.get(b'Rght').value, items.get(b'Btom').value)
def object_bbox(self): """ BBox(x1, y1, x2, y2) with original object content coordinates. """ if self._block: size = dict(self._block.get(PlacedLayerProperty.SIZE).items) return BBox(0, 0, size[SzProperty.WIDTH].value, size[SzProperty.HEIGHT].value) else: return None
def placed_bbox(self): """ BBox(x1, y1, x2, y2) with transformed box. The tranform of a layer the points for all 4 corners. """ if self._block: transform = self._block.get(PlacedLayerProperty.TRANSFORM).items return BBox(transform[0].value, transform[1].value, transform[4].value, transform[5].value) else: return None
def viewbox(self): """Return BBox of the viewport.""" return BBox(0, 0, self.width, self.height)