summaryrefslogtreecommitdiff
path: root/megapixels/app/models/bbox.py
diff options
context:
space:
mode:
Diffstat (limited to 'megapixels/app/models/bbox.py')
-rw-r--r--megapixels/app/models/bbox.py14
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"""