IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 9, 2006, 6:13:25 PM (20 years ago)
Author:
magnier
Message:

added polynomial copy, recycle, derivative functions, derivative tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psPolynomialUtils.c

    r10598 r10605  
    180180psPolynomial2D *psPolynomial2D_dX (psPolynomial2D *out, psPolynomial2D *poly)
    181181{
     182    psPolynomial2D *dest = NULL;
    182183    int nXout = poly->nX - 1;
    183184    int nYout = poly->nY;
    184185
     186    if (poly->nX == 0)
     187        return NULL;
     188
     189    bool inPlace = false;
     190
    185191    if (out == NULL) {
    186         out = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout);
    187     } else {
    188         psPolynomial2DRecycle (out, poly->type, nXout, nYout);
     192        dest = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout);
     193        out = dest;
     194    } else {
     195        if (out == poly) {
     196            inPlace = true;
     197            dest = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout);
     198        } else {
     199            dest = out;
     200            psPolynomial2DRecycle (dest, poly->type, nXout, nYout);
     201        }
    189202    }
    190203
    191204    for (int i = 0; i < nXout + 1; i++) {
    192205        for (int j = 0; j < nYout + 1; j++) {
    193             out->mask[i][j] = poly->mask[i+1][j];
    194             out->coeff[i][j] = poly->coeff[i+1][j] * (i+1);
    195         }
     206            dest->mask[i][j] = poly->mask[i+1][j];
     207            dest->coeff[i][j] = poly->coeff[i+1][j] * (i+1);
     208        }
     209    }
     210
     211    if (inPlace) {
     212        psFree (poly);
     213        out = dest;
    196214    }
    197215    return out;
     
    200218psPolynomial2D *psPolynomial2D_dY (psPolynomial2D *out, psPolynomial2D *poly)
    201219{
    202 
    203     int nXout = poly->nX - 1;
    204     int nYout = poly->nY;
     220    psPolynomial2D *dest = NULL;
     221    int nXout = poly->nX;
     222    int nYout = poly->nY - 1;
     223
     224    if (poly->nY == 0)
     225        return NULL;
     226
     227    bool inPlace = false;
    205228
    206229    if (out == NULL) {
    207         out = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout);
    208     } else {
    209         psPolynomial2DRecycle (out, poly->type, nXout, nYout);
     230        dest = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout);
     231        out = dest;
     232    } else {
     233        if (out == poly) {
     234            inPlace = true;
     235            dest = psPolynomial2DAlloc (PS_POLYNOMIAL_ORD, nXout, nYout);
     236        } else {
     237            dest = out;
     238            psPolynomial2DRecycle (dest, poly->type, nXout, nYout);
     239        }
    210240    }
    211241
    212242    for (int i = 0; i < nXout + 1; i++) {
    213243        for (int j = 0; j < nYout + 1; j++) {
    214             out->mask[i][j] = poly->mask[i][j+1];
    215             out->coeff[i][j] = poly->coeff[i][j+1] * (j+1);
    216         }
     244            dest->mask[i][j] = poly->mask[i][j+1];
     245            dest->coeff[i][j] = poly->coeff[i][j+1] * (j+1);
     246        }
     247    }
     248
     249    if (inPlace) {
     250        psFree (poly);
     251        out = dest;
    217252    }
    218253    return out;
Note: See TracChangeset for help on using the changeset viewer.