Skip to content

Commit

Permalink
Fix extrema badness calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
jenskutilek committed Apr 16, 2024
1 parent 3756ff5 commit c8ce406
Showing 1 changed file with 20 additions and 19 deletions.
Expand Up @@ -501,62 +501,63 @@ def _checkExtremaQuad(self, segment):
def _getBadness(self, pointToCheck, myRect):
# calculate distance of point to rect
badness = 0
if pointToCheck.x < myRect[0]:
x, y = pointToCheck
if x < myRect[0]:
# point is left from rect
if pointToCheck.y < myRect[1]:
if y < myRect[1]:
# point is lower left from rect
badness = int(
round(
sqrt(
(myRect[0] - pointToCheck.x) ** 2
+ (myRect[1] - pointToCheck.y) ** 2
(myRect[0] - x) ** 2
+ (myRect[1] - y) ** 2
)
)
)
elif pointToCheck.y > myRect[3]:
elif y > myRect[3]:
# point is upper left from rect
badness = int(
round(
sqrt(
(myRect[0] - pointToCheck.x) ** 2
+ (myRect[3] - pointToCheck.y) ** 2
(myRect[0] - x) ** 2
+ (myRect[3] - y) ** 2
)
)
)
else:
badness = myRect[0] - pointToCheck.x
elif pointToCheck.x > myRect[2]:
badness = myRect[0] - x
elif x > myRect[2]:
# point is right from rect
if pointToCheck.y < myRect[1]:
if y < myRect[1]:
# point is lower right from rect
badness = int(
round(
sqrt(
(myRect[2] - pointToCheck.x) ** 2
+ (myRect[1] - pointToCheck.y) ** 2
(myRect[2] - x) ** 2
+ (myRect[1] - y) ** 2
)
)
)
elif pointToCheck.y > myRect[3]:
elif y > myRect[3]:
# point is upper right from rect
badness = int(
round(
sqrt(
(myRect[2] - pointToCheck.x) ** 2
+ (myRect[3] - pointToCheck.y) ** 2
(myRect[2] - x) ** 2
+ (myRect[3] - y) ** 2
)
)
)
else:
badness = pointToCheck.x - myRect[2]
badness = x - myRect[2]
else:
# point is centered from rect, check for upper/lower
if pointToCheck.y < myRect[1]:
if y < myRect[1]:
# point is lower center from rect
badness = myRect[1] - pointToCheck.y
badness = myRect[1] - y
elif pointToCheck[1] > myRect[3]:
# point is upper center from rect
badness = pointToCheck.y - myRect[3]
badness = y - myRect[3]
else:
badness = 0
return badness
Expand Down

0 comments on commit c8ce406

Please sign in to comment.