class PiecewiseLinearInterpolator(Interpolator):
    def __init__(self,path,times=None,geodesic=None):
        Interpolator.__init__(self,path[0],path[-1])
        if geodesic != None:
            self.geodesic = geodesic
        else:
            self.geodesic = GeodesicSpace()
        if times != None:
            self.path = path
            self.trajectory = trajectory.Trajectory(times,path)
            if times[0] != 0 or times[-1] != 1:
                raise ValueError("PiecewiseLinearInterpolator must have time range [0,1]")
        else:
            self.path = path
            self.trajectory = None
    def length(self):
        l = 0
        for i in range(len(self.path)-1):
            l += self.geodesic.distance(self.path[i],self.path[i+1])
        return l
    def eval(self,u):
        if self.trajectory != None:
            return self.trajectory.eval(u)
        else:
            if u <= 0: return self.path[0]
            if u >= 1: return self.path[-1]
            k = u*(len(self.path)-1)
            s = k-math.floor(k)
            i = int(math.floor(k))
            return self.geodesic.interpolate(self.path[i],self.path[i+1],s)
class PiecewiseLinearInterpolator(Interpolator):
    def __init__(self, path, times=None, geodesic=None):
        Interpolator.__init__(self, path[0], path[-1])
        if geodesic != None:
            self.geodesic = geodesic
        else:
            self.geodesic = GeodesicSpace()
        if times != None:
            self.path = path
            self.trajectory = trajectory.Trajectory(times, path)
            if times[0] != 0 or times[-1] != 1:
                raise ValueError(
                    "PiecewiseLinearInterpolator must have time range [0,1]")
        else:
            self.path = path
            self.trajectory = None

    def length(self):
        l = 0
        for i in range(len(self.path) - 1):
            l += self.geodesic.distance(self.path[i], self.path[i + 1])
        return l

    def eval(self, u):
        if self.trajectory != None:
            return self.trajectory.eval(u)
        else:
            if u <= 0: return self.path[0]
            if u >= 1: return self.path[-1]
            k = u * (len(self.path) - 1)
            s = k - math.floor(k)
            i = int(math.floor(k))
            return self.geodesic.interpolate(self.path[i], self.path[i + 1], s)
 def __init__(self, path, times=None, geodesic=None):
     Interpolator.__init__(self, path[0], path[-1])
     if geodesic != None:
         self.geodesic = geodesic
     else:
         self.geodesic = GeodesicSpace()
     if times != None:
         self.path = path
         self.trajectory = trajectory.Trajectory(times, path)
         if times[0] != 0 or times[-1] != 1:
             raise ValueError(
                 "PiecewiseLinearInterpolator must have time range [0,1]")
     else:
         self.path = path
         self.trajectory = None
 def __init__(self,path,times=None,geodesic=None):
     Interpolator.__init__(self,path[0],path[-1])
     if geodesic != None:
         self.geodesic = geodesic
     else:
         self.geodesic = GeodesicSpace()
     if times != None:
         self.path = path
         self.trajectory = trajectory.Trajectory(times,path)
         if times[0] != 0 or times[-1] != 1:
             raise ValueError("PiecewiseLinearInterpolator must have time range [0,1]")
     else:
         self.path = path
         self.trajectory = None