-
Notifications
You must be signed in to change notification settings - Fork 1
/
geometricfunctions.py
39 lines (31 loc) · 1000 Bytes
/
geometricfunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import math
import sys
def pp_distance(pointA, pointB):
xA = pointA[0]
yA = pointA[1]
xB = pointB[0]
yB = pointB[1]
return int(round(math.sqrt(math.pow(yB - yA, 2) + math.pow(xB - xA, 2))))
def get_closest_point(listOfPoints, point):
if len(listOfPoints) == 0:
return None
closestPoint = (0, 0)
minDistance = sys.maxsize
for p in listOfPoints:
newDistance = pp_distance(p, point)
if newDistance < minDistance:
minDistance = newDistance
closestPoint = p
if minDistance < 10:
break
return (closestPoint, minDistance)
def is_within_hex(hexObject, point):
disFromCenter = pp_distance(hexObject.coordinates, point)
if disFromCenter < hexObject.radius:
return True
return False
def is_within_rect(rectObject, point):
if rectObject.left < point[0] < rectObject.right:
if rectObject.top < point[1] < rectObject.bottom:
return True
return False