Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Introduce centerOfBox function and related tests #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion pyscreeze/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,10 +695,26 @@ def center(coords):
Point(x=14, y=15)
"""

# TODO - one day, add code to handle a Box namedtuple.
return Point(coords[0] + int(coords[2] / 2), coords[1] + int(coords[3] / 2))


def centerOfBox(box):
"""
Returns a `Point` object with the x and y set to an integer determined by the center
of `box`.

The `box` argument is a `Box` namedtuple of (left, top, width, height).

For example:

>>> centerOfBox(Box(10, 10, 6, 8))
Point(x=13, y=14)
>>> centerOfBox(Box(40, 30, 12, 16))
Point(x=46, y=38)
"""
return Point(box.left + box.width / 2, box.top + box.height / 2)


def pixelMatchesColor(x, y, expectedRGBColor, tolerance=0):
"""
Return True if the pixel at x, y is matches the expected color of the RGB
Expand Down
4 changes: 4 additions & 0 deletions tests/test_pyscreeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ def test_center(self):
self.assertEqual((100, 100), pyscreeze.center((0, 0, 200, 200)))
self.assertEqual((100, 100), pyscreeze.center((50, 50, 100, 100)))

def test_centerOfBox(self):
self.assertEqual((10, 10), pyscreeze.centerOfBox(pyscreeze.Box(0, 0, 20, 20)))
self.assertEqual((10, 10), pyscreeze.centerOfBox(pyscreeze.Box(5, 5, 10, 10)))

"""
# Disabling step test; we don't use this feature because it does not bring any significant performance improvement.
def test_locate_im_step(self):
Expand Down