
import numpy as np
from scipy.interpolate import pchip, Akima1DInterpolator
from scipy.linalg import norm
from openmdao.main.api import Component, Assembly
from openmdao.lib.datatypes.api import Instance, Array, VarTree, Enum, Int, List, Str, Float, Bool

from fusedwind.lib.distfunc import distfunc
from fusedwind.lib.cubicspline import NaturalCubicSpline
from fusedwind.lib.geom_tools import RotMat, dotXC, calculate_length, curvature
from fusedwind.lib.bezier import BezierCurve
from fusedwind.turbine.geometry_vt import Curve, BladePlanformVT, BladeSurfaceVT, BlendAirfoilShapes, AirfoilShape
from fusedwind.interface import base, implement_base


class SplineBase(object):
    """
    base for 1-D splines

    if the spline requires it, implement a fitting procedure in __init__

    place the main call to the spline in __call__ 
    """

    def initialize(self, Cx, xp, yp):

        pass

    def normdist(self, xp):
        """normalize x distribution"""

        return (xp - xp[0]) / (xp[-1] - xp[0])

    def __call__(self, x, Cx, C):
        """
        params:
        ----------
        x: array
            array with new x-distribution
        xp: array
            array with x-coordinates of spline control points
        yp: array
            array with y-coordinates of spline control points