def drawCurve(self):
     cp=ControlPoints(self.points) #instacia os pontos de controle
     curve=deCasteljau.bezier_curve_generator(cp) #curve eh uma funcao que eh retornada pelo generator
     n=[x * (float(1)/self.numero_de_avaliacao) for x in range(0, self.numero_de_avaliacao+1)] #iteracao 0,....,1
     pointsCurve=[] #lista para os pontos da curva
     for i in n:
         p=curve(i)
         pointsCurve.append(p)
     for i in range(1,len(pointsCurve)):
         cv2.line(self.img,(int(pointsCurve[i-1].X),int(pointsCurve[i-1].Y)),(int(pointsCurve[i].X),int(pointsCurve[i].Y)),(255,255,255),1)
    def testMiddleSubdiv(self):
        """
        Tests the algorithm when the parameter passed is zero
        """
        point1 = Point2D(x=0, y=0)
        point2 = Point2D(x=15, y=85)
        point3 = Point2D(x=-96, y=14)
        point4 = Point2D(x=-89.6, y=784.666)

        as_control_points = ControlPoints([point1, point2, point3,point4])
        (curve1,curve2) = subdivide(as_control_points,0.5)
        middle_point = bezier_curve_generator(ControlPoints([point1, point2, point3,point4]))(0.5)

        assert curve1[0] == point1 #Starts at the first control point
		assert curve1[3] == middle_point #Ends at the middle of the curve
		assert curve2[0] == middle_point #Starts at the middle of the curve
		assert curve2[3] == point4 #Ends at the last control point
    if not curve1: curve1 = [points[0]]
    if not curve2:curve2 = [points[len(points)-1]]
    if len(points) <= 1:
        return False, [curve1,curve2] #End of the recursion
    else:
        new_points = []

        for i in range(0,len(points)-1):
            new_points.append(points[i].linear_interpolation(points[i+1],t))
        curve1.append(new_points[0])
        curve2.insert(0,new_points[len(new_points)-1]) #Add at the start of the list

        return True, (new_points,curve1,curve2,t)



if __name__ == '__main__':

    point1 = Point2D(x=0, y=0)
    point2 = Point2D(x=15, y=85)
    point3 = Point2D(x=-96, y=14)
    point4 = Point2D(x=-89.6, y=784.666)

    as_control_points = ControlPoints([point1, point2, point3,point4])
    (curve1,curve2) = subdivide(as_control_points,0.5)
    middle_point = bezier_curve_generator(ControlPoints([point1, point2, point3, point4]))(0.5)

    assert curve1[0] == point1 #Starts at the first control point
    assert curve1[3] == middle_point #Ends at the middle of the curve
    assert curve2[0] == middle_point #Starts at the middle of the curve
    assert curve2[3] == point4 #Ends at the last control point