~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to ogr/ogrlinearring.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: ogrlinearring.cpp 18676 2010-01-27 23:18:08Z rouault $
 
2
 * $Id: ogrlinearring.cpp 22555 2011-06-22 12:16:54Z rouault $
3
3
 *
4
4
 * Project:  OpenGIS Simple Features Reference Implementation
5
5
 * Purpose:  The OGRLinearRing geometry class.
30
30
#include "ogr_geometry.h"
31
31
#include "ogr_p.h"
32
32
 
33
 
CPL_CVSID("$Id: ogrlinearring.cpp 18676 2010-01-27 23:18:08Z rouault $");
 
33
CPL_CVSID("$Id: ogrlinearring.cpp 22555 2011-06-22 12:16:54Z rouault $");
34
34
 
35
35
/************************************************************************/
36
36
/*                           OGRLinearRing()                            */
335
335
 
336
336
{
337
337
    int    i, v, next;
338
 
    double  dx0, dy0, dx1, dy1, crossproduct; 
 
338
    double  dx0, dy0, dx1, dy1, crossproduct;
 
339
    int    bUseFallback = FALSE;
339
340
 
340
341
    if( nPointCount < 2 )
341
342
        return TRUE;
352
353
            v = i;
353
354
        }
354
355
    }
355
 
    
356
 
    /* Vertices may be duplicate, we have to go to nearest different in each direction */
357
 
    /* preceding */
 
356
 
 
357
    /* previous */
358
358
    next = v - 1;
359
 
    while ( 1 )
360
 
    {
361
 
        if ( next < 0 ) 
362
 
        {
363
 
            next = nPointCount - 1 - 1; 
364
 
        }
365
 
 
366
 
        if( !epsilonEqual(paoPoints[next].x, paoPoints[v].x, EPSILON) 
367
 
            || !epsilonEqual(paoPoints[next].y, paoPoints[v].y, EPSILON) )
368
 
        {
369
 
            break;
370
 
        }
371
 
 
372
 
        if ( next == v ) /* So we cannot get into endless loop */
373
 
        {
374
 
            break;
375
 
        }
376
 
 
377
 
        next--;
378
 
    }
379
 
            
 
359
    if ( next < 0 )
 
360
    {
 
361
        next = nPointCount - 1 - 1;
 
362
    }
 
363
 
 
364
    if( epsilonEqual(paoPoints[next].x, paoPoints[v].x, EPSILON) &&
 
365
        epsilonEqual(paoPoints[next].y, paoPoints[v].y, EPSILON) )
 
366
    {
 
367
        /* Don't try to be too clever by retrying with a next point */
 
368
        /* This can lead to false results as in the case of #3356 */
 
369
        bUseFallback = TRUE;
 
370
    }
 
371
 
380
372
    dx0 = paoPoints[next].x - paoPoints[v].x;
381
373
    dy0 = paoPoints[next].y - paoPoints[v].y;
382
374
    
383
375
    
384
376
    /* following */
385
377
    next = v + 1;
386
 
    while ( 1 )
387
 
    {
388
 
        if ( next >= nPointCount - 1 ) 
389
 
        {
390
 
            next = 0; 
391
 
        }
392
 
 
393
 
        if ( !epsilonEqual(paoPoints[next].x, paoPoints[v].x, EPSILON) 
394
 
             || !epsilonEqual(paoPoints[next].y, paoPoints[v].y, EPSILON) )
395
 
        {
396
 
            break;
397
 
        }
398
 
 
399
 
        if ( next == v ) /* So we cannot get into endless loop */
400
 
        {
401
 
            break;
402
 
        }
403
 
 
404
 
        next++;
 
378
    if ( next >= nPointCount - 1 )
 
379
    {
 
380
        next = 0;
 
381
    }
 
382
 
 
383
    if( epsilonEqual(paoPoints[next].x, paoPoints[v].x, EPSILON) &&
 
384
        epsilonEqual(paoPoints[next].y, paoPoints[v].y, EPSILON) )
 
385
    {
 
386
        /* Don't try to be too clever by retrying with a next point */
 
387
        /* This can lead to false results as in the case of #3356 */
 
388
        bUseFallback = TRUE;
405
389
    }
406
390
 
407
391
    dx1 = paoPoints[next].x - paoPoints[v].x;
408
392
    dy1 = paoPoints[next].y - paoPoints[v].y;
409
393
 
410
394
    crossproduct = dx1 * dy0 - dx0 * dy1;
411
 
    
412
 
    if ( crossproduct > 0 )      /* CCW */
413
 
        return FALSE;
414
 
    else if ( crossproduct < 0 )  /* CW */
415
 
        return TRUE;
 
395
 
 
396
    if (!bUseFallback)
 
397
    {
 
398
        if ( crossproduct > 0 )      /* CCW */
 
399
            return FALSE;
 
400
        else if ( crossproduct < 0 )  /* CW */
 
401
            return TRUE;
 
402
    }
416
403
    
417
404
    /* ok, this is a degenerate case : the extent of the polygon is less than EPSILON */
 
405
    /* or 2 nearly identical points were found */
418
406
    /* Try with Green Formula as a fallback, but this is not a guarantee */
419
407
    /* as we'll probably be affected by numerical instabilities */
420
408