diff options
| author | adamhrv <adam@ahprojects.com> | 2019-10-08 16:02:47 +0200 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2019-10-08 16:02:47 +0200 |
| commit | 27340ac4cd43f8eec7414495b541a65566ae2656 (patch) | |
| tree | cd43fcf1af026c75e6045d71d7d783ec460ba3ee /megapixels/app/models/bbox.py | |
| parent | a4ea2852f4b46566a61f988342aa04e4059ccef9 (diff) | |
update site, white
Diffstat (limited to 'megapixels/app/models/bbox.py')
| -rw-r--r-- | megapixels/app/models/bbox.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/megapixels/app/models/bbox.py b/megapixels/app/models/bbox.py index 8ecc8971..c840ea1b 100644 --- a/megapixels/app/models/bbox.py +++ b/megapixels/app/models/bbox.py @@ -207,11 +207,21 @@ class BBox: # ----------------------------------------------------------------- # Convert to - def to_square(self, bounds): + def to_square(self): '''Forces bbox to square dimensions - :param bounds: (int, int) w, h of the image :returns (BBox) in square ratio ''' + if self._width > self._height: + delta = (self._width - self._height) / 2 + self._y1 -= delta + self._y2 += delta + elif self._height > self._width: + delta = (self._height - self._width) / 2 + self._x1 -= delta + self._x2 += delta + return BBox(self._x1, self._y1, self._x2, self._y2) + + def to_dim(self, dim): """scale is (w, h) is tuple of dimensions""" |
