# L-33 MCS 260 Monday 6 April 2015 : class_line.py
"""
We define a line as a point and a direction,
inheriting from the class Point.
The line is a callable object,
evaluating the line yields a point on the line.
The main program illustrates instantiations and the call method.
"""

from math import cos, sin
from class_point import Point

class Line(Point):
    """
    A line is a base point and
    a direction angle.
    """
    def __init__(self, x=0, y=0, a=0):
        """
        Defines base point and angle.
        """
        Point.__init__(self, x, y)
        self.angle = a

    def __str__(self):
        """
        Returns the string representation.
        """
        strp = Point.__str__(self)
        stra = ', angle = ' + str(self.angle)
        return strp + stra

    def __repr__(self):
        """
        Returns the representation.
        """
        return self.__str__()

    def __call__(self, argt):
        """
        Returns a new point on the line.
        """
        rxt = self.xpt + argt*cos(self.angle)
        ryt = self.ypt + argt*sin(self.angle)
        return Point(rxt, ryt)

def main():
    """
    Defining a line.
    """
    print('defining a line ...')
    first = Line()
    print('the default line :', first)
    print('some point on it :', first(5))
    from math import pi
    second = Line(3, 4, pi/2)
    print('a vertical line :', second)
    print('   that passes through', second(0))
    apt = second(4)
    print('another point on it is', apt)

if __name__ == "__main__":
    main()
