From a1784957490773151d68e919e13bac68e252e305 Mon Sep 17 00:00:00 2001 From: Sepehr Bayat <bayats1@mcmaster.ca> Date: Mon, 29 Jan 2018 09:48:58 -0500 Subject: [PATCH] Update TriangleADT.py --- Tutorials/T04-A2Example/src/TriangleADT.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Tutorials/T04-A2Example/src/TriangleADT.py b/Tutorials/T04-A2Example/src/TriangleADT.py index 70614937..75e8a17b 100644 --- a/Tutorials/T04-A2Example/src/TriangleADT.py +++ b/Tutorials/T04-A2Example/src/TriangleADT.py @@ -19,21 +19,21 @@ class Triangle: self.__a = p1 self.__b = p2 self.__c = p3 - self.seq = [0,0,0] - self.sides() ## @brief Gets the sides # @return The sides of the triangle def sides(self): - self.seq[0] = PointT.dist(self.__b,self.__b) - self.seq[1] = PointT.dist(self.__a,self.__c) - self.seq[2] = PointT.dist(self.__b,self.__c) + seq = [0,0,0] + seq[0] = self.__a.dist(self.__b) + seq[1] = self.__a.dist(self.__c) + seq[2] = self.__b.dist(self.__c) + return seq; ## @brief Inequality theorem # @return the existence of a triangle def inequality_theorem(self): - self.sides() - if (self.seq[0] +self.seq[1] > self.seq[2] and self.seq[0]+self.seq[2] > self.seq[1] and self.seq[1]+self.seq[2] >self.seq[1]): + seq = self.sides() + if (seq[0] +seq[1] > seq[2] and seq[0]+seq[2] > seq[1] and seq[1]+seq[2] >seq[1]): return True; elif (self.__a.xcoord()==self.__b.xcoord()==self.__c.xcoord() or self.__a.ycoord()==self.__b.ycoord()==self.__c.ycoord()): return False; @@ -43,17 +43,19 @@ class Triangle: ## @brief perimeter # @return the perimeter of the triangle def perimeter_of_triangle(self): + seq = self.sides() if self.inequality_theorem(): - return self.seq[0]+self.seq[1]+self.seq[2] + return seq[0]+seq[1]+seq[2] else: print("You can't have a triangle with the points") ## @brief area # @return the area of the triangle def area_of_triangle(self): + seq = self.sides() if self.inequality_theorem(): - P = (self.seq[0]+self.seq[1]+self.seq[2])/2 - return sqrt(P*(P-self.seq[0])*(P-self.seq[1])*(P-self.seq[2])) + P = (seq[0]+seq[1]+seq[2])/2 + return sqrt(P*(P-self.seq[0])*(P-seq[1])*(P-seq[2])) else: print("You can't have a triangle with the points") -- GitLab