From 66e3808a3eaa57cf0583d95f93fc71ec710fcda7 Mon Sep 17 00:00:00 2001 From: Ian Jauslin Date: Tue, 28 Sep 2021 10:50:09 -0400 Subject: [PATCH] in check_interaction, use Point operations --- main.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 2ef4987..b780f44 100644 --- a/main.py +++ b/main.py @@ -135,7 +135,7 @@ class Cross(): # check whether a cross at pos interacts with cross 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 #def move_on_line_to_stick(self,x,v): @@ -148,9 +148,31 @@ class Point: def __add__(self,point): return Point(self.x+point.x,self.y+point.y) - def __neg__(self): - return Point(-self.x,self.y) + def __sub__(self,point): + 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): self.x=x self.y=y