Skip to content

Commit fe13b17

Browse files
src/__init__.py: restore missing Rect.get_area().
Fixes #4742.
1 parent ace19a4 commit fe13b17

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/__init__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14660,6 +14660,10 @@ def contains(self, x):
1466014660
def height(self):
1466114661
return max(0, self.y1 - self.y0)
1466214662

14663+
def get_area(self, *args) -> float:
14664+
"""Calculate area of rectangle.\nparameter is one of 'px' (default), 'in', 'cm', or 'mm'."""
14665+
return _rect_area(self.width, self.height, args)
14666+
1466314667
def include_point(self, p):
1466414668
"""Extend to include point-like p."""
1466514669
if len(p) != 2:
@@ -17263,13 +17267,7 @@ def contains(self, x):
1726317267

1726417268
def get_area(self, *args) -> float:
1726517269
"""Calculate area of rectangle.\nparameter is one of 'px' (default), 'in', 'cm', or 'mm'."""
17266-
if args:
17267-
unit = args[0]
17268-
else:
17269-
unit = "px"
17270-
u = {"px": (1, 1), "in": (1.0, 72.0), "cm": (2.54, 72.0), "mm": (25.4, 72.0)}
17271-
f = (u[unit][0] / u[unit][1]) ** 2
17272-
return f * self.width * self.height
17270+
return _rect_area(self.width, self.height, args)
1727317271

1727417272
def include_point(self, p):
1727517273
"""Extend rectangle to include point p."""
@@ -18277,6 +18275,13 @@ class EmptyFileError(FileDataError):
1827718275
# Functions
1827818276
#
1827918277

18278+
def _rect_area(width, height, args):
18279+
# Used by IRect.get_area() and Rect.get_area().
18280+
unit = args[0] if args else 'px'
18281+
u = {"px": (1, 1), "in": (1.0, 72.0), "cm": (2.54, 72.0), "mm": (25.4, 72.0)}
18282+
f = (u[unit][0] / u[unit][1]) ** 2
18283+
return f * width * height
18284+
1828018285
def _read_samples( pixmap, offset, n):
1828118286
# fixme: need to be able to get a sample in one call, as a Python
1828218287
# bytes or similar.

0 commit comments

Comments
 (0)