## @file TriangleADT.py
#  @author Sepehr
#  @brief Provides the Triangle CLass for Perimeter Area and existence of triangle
#  @date 25 Jan 2018

from pointT import  *


##@brief An ADT that respresents a 2D point
class Triangle:


    ## @brief Triangle constructor
    #  @details Initializes a Triangle with three points a,b,c
    #  @param a One side of triangle
    #  @param b One side of triangle
    #  @param c One side of triangle
    def __init__(self, p1, p2,p3):
        self.__a = p1
        self.__b = p2
        self.__c = p3

    ## @brief Gets the sides
    #  @return The sides of the triangle
    def sides(self):
        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):
        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;
        else:
            return False;

    ## @brief perimeter
    #  @return the perimeter of the triangle
    def perimeter_of_triangle(self):
        seq = self.sides()
        if self.inequality_theorem():
            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 = (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")