diff --git a/src/miniogl/RectangleShape.py b/src/miniogl/RectangleShape.py index 09f468b..d876bc3 100644 --- a/src/miniogl/RectangleShape.py +++ b/src/miniogl/RectangleShape.py @@ -154,9 +154,12 @@ def Inside(self, x, y) -> bool: """ True if (x, y) is inside the rectangle. - @param x - @param y - @return bool + Args: + x: + y: + + Returns: + """ # this also works if width and/or height is negative. sx, sy = self.GetPosition() @@ -167,10 +170,10 @@ def Inside(self, x, y) -> bool: topLeftX: int = sx - self._ox topLeftY: int = sy - self._oy - topXLeftIsInside: bool = x > topLeftX - topXRightIsInside: bool = x < topLeftX + width - topYLeftIsInside: bool = y > topLeftY - topYRightIsInside: bool = y < topLeftY + height + topXLeftIsInside: bool = x >= topLeftX + topXRightIsInside: bool = x <= topLeftX + width + topYLeftIsInside: bool = y >= topLeftY + topYRightIsInside: bool = y <= topLeftY + height if topXLeftIsInside and topXRightIsInside and topYLeftIsInside and topYRightIsInside: return True else: diff --git a/src/ogl/OglInterface2.py b/src/ogl/OglInterface2.py index 527a82b..7cc52f9 100644 --- a/src/ogl/OglInterface2.py +++ b/src/ogl/OglInterface2.py @@ -80,6 +80,7 @@ def Draw(self, dc: DC, withChildren: bool = True): dc.SetFont(self._defaultFont) xFaceName: str = self.pyutInterface.name + self.logger.debug(f'{xFaceName=} {self._pyutInterface.id=}') extentSize: Tuple[int, int] = dc.GetTextExtent(xFaceName) # width, height diff --git a/src/ogl/_version.py b/src/ogl/_version.py index 2d93b16..b85f221 100644 --- a/src/ogl/_version.py +++ b/src/ogl/_version.py @@ -1 +1 @@ -__version__ = '2.1.32' +__version__ = '2.1.33' diff --git a/tests/miniogl/TestRectangleShape.py b/tests/miniogl/TestRectangleShape.py index 5f48c3d..cf4984a 100644 --- a/tests/miniogl/TestRectangleShape.py +++ b/tests/miniogl/TestRectangleShape.py @@ -46,6 +46,38 @@ def testInsideFalseViaY(self): self.assertFalse(actualAnswer, 'The x-coordinate IS NOT inside the rectangle') + def testOnLeftXBoundary(self): + + rectangleShape: RectangleShape = RectangleShape(x=120, y=60, width=66, height=60) + + isInside: bool = rectangleShape.Inside(x=120, y=90) + + self.assertTrue(isInside, 'Left boundary point should be inside') + + def testOnRightXBoundary(self): + + rectangleShape: RectangleShape = RectangleShape(x=120, y=60, width=66, height=60) + + isInside: bool = rectangleShape.Inside(x=120+66, y=90) + + self.assertTrue(isInside, 'Right boundary point should be inside') + + def testOnTopYBoundary(self): + + rectangleShape: RectangleShape = RectangleShape(x=120, y=60, width=66, height=60) + + isInside: bool = rectangleShape.Inside(x=120, y=60) + + self.assertTrue(isInside, 'Top Y boundary point should be inside') + + def testOnBottomYBoundary(self): + + rectangleShape: RectangleShape = RectangleShape(x=120, y=60, width=66, height=60) + + isInside: bool = rectangleShape.Inside(x=120, y=60+60) + + self.assertTrue(isInside, 'Bottom Y boundary point should be inside') + def suite() -> TestSuite: """You need to change the name of the test class here also."""