/*
 * Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD
 * All rights reserved.
 *
 * Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use
 * exclusively with CVA's microcontroller products. This file can be freely
 * distributed within development tools that are supporting such microcontroller
 * products.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
 * CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
 * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 */

#ifndef _INTERP2D_H_
#define _INTERP2D_H_

/*! \brief  Contains public interface to various functions related
 *          to the 2-D linear interpolation
 */

/*******************************************************************************
 * the includes
 ******************************************************************************/

#include "common/iqmath/iqmath.h"
#include "interp1d.h"

#ifdef __cplusplus
extern "C" {
#endif

/*******************************************************************************
 * the defines
 ******************************************************************************/

/*******************************************************************************
 * the typedefs
 ******************************************************************************/

/*******************************************************************************
 * the globals
 ******************************************************************************/

/*******************************************************************************
 * the function prototypes
 ******************************************************************************/

/*! \brief This is an 2-D linear interpolate calculation function using the row and column scale as input
 *
 * \param[in] x00 : the x value of (0, 0) point
 * \param[in] x01 : the x value of (0, 1) point
 * \param[in] x10 : the x value of (1, 0) point
 * \param[in] x11 : the x value of (1, 1) point
 * \param[in] rowScale : the scale of row
 * \param[in] columnScale : the scale of column
 * \return the x value of the target point
 */
static inline _iq Interp2d(_iq x00, _iq x01, _iq x10, _iq x11, _iq rowScale, _iq columnScale)
{
    return Interp1d(Interp1d(x00, x10, rowScale),
                    Interp1d(x01, x11, rowScale),
                    columnScale);
}

#ifdef __cplusplus
}
#endif /* extern "C" */

#endif /* _INTERP2D_H_ */
