in check_interaction, use Point operations

This commit is contained in:
Ian Jauslin 2021-09-28 10:50:09 -04:00
parent b3949e25f2
commit 66e3808a3e

28
main.py
View File

@ -135,7 +135,7 @@ class Cross():
# check whether a cross at pos interacts with cross # check whether a cross at pos interacts with cross
def check_interaction(self,pos): def check_interaction(self,pos):
return int((pos.x-self.pos.x)/self.size)**2+int((pos.y-self.pos.y)/self.size)**2>=5 return ((pos-self.pos)/self.size).int()**2>=5
# find position along a line that comes in contact with the line # find position along a line that comes in contact with the line
#def move_on_line_to_stick(self,x,v): #def move_on_line_to_stick(self,x,v):
@ -148,9 +148,31 @@ class Point:
def __add__(self,point): def __add__(self,point):
return Point(self.x+point.x,self.y+point.y) return Point(self.x+point.x,self.y+point.y)
def __neg__(self): def __sub__(self,point):
return Point(-self.x,self.y) return Point(self.x-point.x,self.y-point.y)
def __neg__(self):
return Point(-self.x,-self.y)
def __mul__(self,a):
return Point(a*self.x,a*self.y)
def __truediv__(self,a):
return Point(self.x/a,self.y/a)
def __pow__(self,a):
if a==2:
return self.dot(self)
# dot product
def dot(self,x):
return self.x*x.x+self.y*x.y
# integer part
def int(self):
return Point(int(self.x),int(self.y))
# set position
def setpos(self,x,y): def setpos(self,x,y):
self.x=x self.x=x
self.y=y self.y=y