Changeset f0befc in git


Ignore:
Timestamp:
Aug 20, 2013, 3:09:33 PM (10 years ago)
Author:
Martin Lee <martinlee84@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
Children:
ffae30a2130f2ca69e796b942659b22f5597fc03
Parents:
e57b47470cc03176f0e7bd90cf0e54c36433d44a
git-author:
Martin Lee <martinlee84@web.de>2013-08-20 15:09:33+02:00
git-committer:
Martin Lee <martinlee84@web.de>2013-08-30 13:48:36+02:00
Message:
fix: memory leak
chg: less stupid way to compute bounds
File:
1 edited

Legend:

Unmodified
Added
Removed
  • factory/facFqBivarUtil.cc

    re57b47 rf0befc  
    745745  maxX= minX;
    746746  maxY= minY;
     747  int indZero= 0;
    747748  for (int i= 1; i < sizeOfNewtonPolygon; i++)
    748749  {
     750    if (newtonPolyg[i][1] == 0)
     751    {
     752      if (newtonPolyg[indZero][1] == 0)
     753      {
     754        if (newtonPolyg[indZero][0] < newtonPolyg[i][0])
     755          indZero= i;
     756      }
     757      else
     758        indZero= i;
     759    }
    749760    if (minX > newtonPolyg [i] [0])
    750761      minX= newtonPolyg [i] [0];
     
    757768  }
    758769
    759   int k= maxX;
     770  int slopeNum, slopeDen, constTerm;
     771  bool negativeSlope=false;
     772  if (indZero != sizeOfNewtonPolygon - 1)
     773  {
     774    slopeNum= newtonPolyg[indZero+1][0]-newtonPolyg[indZero][0];
     775    slopeDen= newtonPolyg[indZero+1][1];
     776    constTerm= newtonPolyg[indZero][0];
     777  }
     778  else
     779  {
     780    slopeNum= newtonPolyg[0][0]-newtonPolyg[indZero][0];
     781    slopeDen= newtonPolyg[0][1];
     782    constTerm= newtonPolyg[indZero][0];
     783  }
     784  if (slopeNum < 0)
     785  {
     786    slopeNum= -slopeNum;
     787    negativeSlope= true;
     788  }
     789  int k= 0;
    760790  for (int i= 0; i < n; i++)
    761791  {
     792    if (((indZero+1) < sizeOfNewtonPolygon && (i+1) > newtonPolyg[indZero+1][1])
     793        || ((indZero+1) >= sizeOfNewtonPolygon && (i+1) > newtonPolyg[0][1]))
     794    {
     795      if (indZero + 1 != sizeOfNewtonPolygon)
     796        indZero++;
     797      else
     798        indZero= 0;
     799      if (indZero != sizeOfNewtonPolygon - 1)
     800      {
     801        slopeNum= newtonPolyg[indZero+1][0]-newtonPolyg[indZero][0];
     802        slopeDen= newtonPolyg[indZero+1][1]-newtonPolyg[indZero][1];
     803        constTerm= newtonPolyg[indZero][0];
     804      }
     805      else
     806      {
     807        slopeNum= newtonPolyg[0][0]-newtonPolyg[indZero][0];
     808        slopeDen= newtonPolyg[0][1]-newtonPolyg[indZero][1];
     809        constTerm= newtonPolyg[indZero][0];
     810      }
     811      if (slopeNum < 0)
     812      {
     813        negativeSlope= true;
     814        slopeNum= - slopeNum;
     815        k= (int) -(((long) slopeNum*((i+1)-newtonPolyg[indZero][1])+slopeDen-1)/
     816                   slopeDen) + constTerm;
     817      }
     818      else
     819        k= (int) (((long) slopeNum*((i+1)-newtonPolyg[indZero][1])) / slopeDen)
     820                  + constTerm;
     821    }
     822    else
     823    {
     824      if (negativeSlope)
     825        k= (int) -(((long) slopeNum*((i+1)-newtonPolyg[indZero][1])+slopeDen-1)/
     826                   slopeDen) + constTerm;
     827      else
     828        k= (int) ((long) slopeNum*((i+1)-newtonPolyg[indZero][1])) / slopeDen
     829                  + constTerm;
     830    }
    762831    if (i + 1 > maxY || i + 1 < minY)
    763832    {
     
    768837    point [0]= k;
    769838    point [1]= i + 1;
    770     while (!isInPolygon (newtonPolyg, sizeOfNewtonPolygon, point) && k > 0)
    771     {
    772       k--;
    773       point [0]= k;
    774     }
     839    if (!isInPolygon (newtonPolyg, sizeOfNewtonPolygon, point) && k > 0)
     840      k= 0;
    775841    result [i]= k;
    776     k= maxX;
    777842    delete [] point;
    778843  }
     844
     845  for (int i= 0; i < sizeOfNewtonPolygon; i++)
     846    delete [] newtonPolyg[i];
     847  delete [] newtonPolyg;
    779848
    780849  return result;
     
    830899  maxX= minX;
    831900  maxY= minY;
     901  int indZero= 0;
    832902  for (int i= 1; i < sizeOfNewtonPolygon; i++)
    833903  {
     904    if (newtonPolyg[i][0] == 0)
     905    {
     906      if (newtonPolyg[indZero][0] == 0)
     907      {
     908        if (newtonPolyg[indZero][1] < newtonPolyg[i][1])
     909          indZero= i;
     910      }
     911      else
     912        indZero= i;
     913    }
    834914    if (minX > newtonPolyg [i] [0])
    835915      minX= newtonPolyg [i] [0];
     
    842922  }
    843923
    844   int k= maxY;
     924  int slopeNum, slopeDen, constTerm;
     925  bool negativeSlope=false;
     926  if (indZero != sizeOfNewtonPolygon - 1)
     927  {
     928    slopeNum= newtonPolyg[indZero+1][1]-newtonPolyg[indZero][1];
     929    slopeDen= newtonPolyg[indZero+1][0];
     930    constTerm= newtonPolyg[indZero][1];
     931  }
     932  else
     933  {
     934    slopeNum= newtonPolyg[0][1]-newtonPolyg[indZero][1];
     935    slopeDen= newtonPolyg[0][0];
     936    constTerm= newtonPolyg[indZero][1];
     937  }
     938  if (slopeNum < 0)
     939  {
     940    slopeNum= -slopeNum;
     941    negativeSlope= true;
     942  }
     943  int k= 0;
    845944  for (int i= 0; i < n; i++)
    846945  {
     946    if (((indZero+1) < sizeOfNewtonPolygon && (i+1) > newtonPolyg[indZero+1][0])
     947        || ((indZero+1) >= sizeOfNewtonPolygon && (i+1) > newtonPolyg[0][0]))
     948    {
     949      if (indZero + 1 != sizeOfNewtonPolygon)
     950        indZero++;
     951      else
     952        indZero= 0;
     953      if (indZero != sizeOfNewtonPolygon - 1)
     954      {
     955        slopeNum= newtonPolyg[indZero+1][1]-newtonPolyg[indZero][1];
     956        slopeDen= newtonPolyg[indZero+1][0]-newtonPolyg[indZero][0];
     957        constTerm= newtonPolyg[indZero][1];
     958      }
     959      else
     960      {
     961        slopeNum= newtonPolyg[0][1]-newtonPolyg[indZero][1];
     962        slopeDen= newtonPolyg[0][0]-newtonPolyg[indZero][0];
     963        constTerm= newtonPolyg[indZero][1];
     964      }
     965      if (slopeNum < 0)
     966      {
     967        negativeSlope= true;
     968        slopeNum= - slopeNum;
     969        k= (int) -(((long) slopeNum*((i+1)-newtonPolyg[indZero][0])+slopeDen-1)/
     970                   slopeDen) + constTerm;
     971      }
     972      else
     973        k= (int) (((long) slopeNum*((i+1)-newtonPolyg[indZero][0])) / slopeDen)
     974                  + constTerm;
     975    }
     976    else
     977    {
     978      if (negativeSlope)
     979        k= (int) -(((long) slopeNum*((i+1)-newtonPolyg[indZero][0])+slopeDen-1)/
     980                   slopeDen) + constTerm;
     981      else
     982        k= (int) ((long) slopeNum*((i+1)-newtonPolyg[indZero][0])) / slopeDen
     983                  + constTerm;
     984    }
    847985    if (i + 1 > maxX || i + 1 < minX)
    848986    {
     
    853991    point [0]= i + 1;
    854992    point [1]= k;
    855     while (!isInPolygon (newtonPolyg, sizeOfNewtonPolygon, point) && k > 0)
    856     {
    857       k--;
    858       point [1]= k;
    859     }
     993    if (!isInPolygon (newtonPolyg, sizeOfNewtonPolygon, point) && k > 0)
     994      k= 0;
    860995    result [i]= k;
    861     k= maxY;
    862996    delete [] point;
    863997  }
     998
     999  for (int i= 0; i < sizeOfNewtonPolygon; i++)
     1000    delete [] newtonPolyg[i];
     1001  delete [] newtonPolyg;
    8641002
    8651003  return result;
Note: See TracChangeset for help on using the changeset viewer.