#include <stdio.h>
#include "pslib.h"
#include "stac.h"

#define PS_INT_CHECK_NON_NEGATIVE(NAME, RVAL) \
if (NAME < 0) { \
    psError("pslib.badValue", \
            "Error: %s is less than 0.", #NAME); \
    return(RVAL); \
}

static void planeTransformFree(psPlaneTransform *pt)
{
    psFree(pt->x);
    psFree(pt->y);
}

psPlaneTransform* psPlaneTransformAlloc(psS32 n1, psS32 n2)
{
    PS_INT_CHECK_NON_NEGATIVE(n1, NULL);
    PS_INT_CHECK_NON_NEGATIVE(n2, NULL);

    psPlaneTransform *pt = psAlloc(sizeof(psPlaneTransform));
    pt->x = psDPolynomial2DAlloc(n1, n2, PS_POLYNOMIAL_ORD);
    pt->y = psDPolynomial2DAlloc(n1, n2, PS_POLYNOMIAL_ORD);

    p_psMemSetDeallocator(pt, (psFreeFcn) planeTransformFree);
    return(pt);
}

