1from .imports
import dependsOnPackage
2from typing
import Union
5@dependsOnPackage('Point', 'Point')
6def findClosestXPoint(target, comparatorList, offsetIndex=0):
7 """ I've forgotten what *exactly* this does. I think it finds the point in a list of
8 points who's x point is closest to the target
14 for current
in comparatorList:
16 currentDist = abs(target.x - current.x)
17 if currentDist < finalDist:
19 finalDist = currentDist
23@dependsOnPackage('Point', ('Point', 'Pointi', 'Pointf'))
24def getPointsAlongLine(p1, p2):
25 """ I don't remember what this does. """
34 for x
in range(p1.x, p2.x):
35 y = p1.y + dy * (x - p1.x) / dx
36 returnMe.append(Pointf(x, y))
40@dependsOnPackage('Point', 'Point')
41def rotatePoint(p, angle, pivotPoint, radians=False):
42 """ This rotates one point around another point a certain amount, and returns it's new position """
44 angle = math.radians(angle)
49 dx = p.x - pivotPoint.x
50 dy = p.y - pivotPoint.y
51 newX = dx * math.cos(angle) - dy * math.sin(angle) + pivotPoint.x
52 newY = dx * math.sin(angle) + dy * math.cos(angle) + pivotPoint.y
54 return Pointf(newX, newY)
56@dependsOnPackage('Point', 'Point')
57def getMidPoint(p1, p2):
58 """ Returns the halfway point between 2 given points """
59 assert type(p1) == type(p2)
61 return p1._initCopy((p1.x + p2.x) / 2, (p1.y + p2.y) / 2)
63@dependsOnPackage('Point', 'Point')
64def findClosestPoint(target, comparatorList):
65 """ Finds the closest point in the list to what it's given"""
68 for i
in comparatorList:
69 current = getDist(target, i)
70 if current < finalDist:
75@dependsOnPackage('Point', 'Point')
76def collidePoint(topLeft:
'Point', size: Union[tuple, list,
'Size'], target, inclusive=
True):
77 """ Returns true if target is within the rectangle given by topLeft and size """
78 return isBetween(target.x, topLeft.x, size[0], beginInclusive=inclusive, endInclusive=inclusive)
and \
79 isBetween(target.y, topLeft.y, size[1], beginInclusive=inclusive, endInclusive=inclusive)
81@dependsOnPackage('Point', 'Point')
82def getPointDist(a:
'Point', b:
'Point'):
83 return math.sqrt(((b.x - a.x)**2) + ((b.y - a.y)**2))