from gk_shape import *
from gk_shape_modifier import *
from numpy import *


class shape_bezier(gds_shape_modifier):
    """ polynomial bezier curve based on a shape with control points """
    def __init__(self, original_shape, steps = 100):
        #if angle_step == None:
            #angle_step = get_angle_step()
        gds_shape_modifier.__init__(self, original_shape)
        self.steps = steps

    def __calc__(self):
        # perform decasteljau ieteration
        step = 1.0/self.steps
        t = arange(0.0, 1.0 +0.5*step, step)
        P = array(self.original_shape.points)
        Px = outer(P[:, 0], ones(size(t)))
        Py = outer(P[:, 1], ones(size(t)))
        for j in range(len(self.original_shape)-1,  0, -1):
            Px = Px[0:j, :] + diff(Px, 1, 0) * t
            Py = Py[0:j, :] + diff(Py, 1, 0) * t

        self.__points__ = transpose(row_stack((Px, Py)))
