Changeset 2053

Show
Ignore:
Timestamp:
11/22/05 13:29:41 (6 years ago)
Author:
strk
Message:

Fixed a bug in getPoint{3dm,3dz,4d}_p() api calls automatically
fixing bugs in force_{3dm,3dz,4d}() user functions, for which
tests have been added in regress dir.
Wrapped paranoid checks in PARANOIA_LEVEL preprocessor blocks.
Updated release notes and CHANGES file.

Location:
trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/CHANGES

    r2040 r2053  
    3636        - Fixed memory alignment problems 
    3737        - Speedup of serializer functions 
     38        - Bug fix in force_4d, force_3dm and force_3dz functions 
    3839 
    3940PostGIS 1.0.4 
  • trunk/doc/postgis.xml

    r2041 r2053  
    50175017        <para>Fixed a small bug in the getPoint4d_p() low-level function</para> 
    50185018        <para>Speedup of serializer functions</para> 
     5019        <para>Fixed a bug in force_3dm(), force_3dz() and force_4d()</para> 
    50195020                        </sect2> 
    50205021 
  • trunk/lwgeom/liblwgeom.h

    r2037 r2053  
    270270// copies a point from the point array into the parameter point 
    271271// will set point's z=0 (or NaN) if pa is 2d 
    272 // will set point's m=0 (or NaN( if pa is 3d or 2d 
     272// will set point's m=0 (or NaN) if pa is 3d or 2d 
    273273// NOTE: point is a real POINT3D *not* a pointer 
    274274extern POINT4D getPoint4d(const POINTARRAY *pa, int n); 
  • trunk/lwgeom/lwgeom_api.c

    r2020 r2053  
    88#include "liblwgeom.h" 
    99#include "wktparse.h" 
     10 
     11/* 
     12 * Lower this to reduce integrity checks 
     13 */ 
     14#define PARANOIA_LEVEL 1 
    1015 
    1116//#define PGIS_DEBUG 1 
     
    428433 
    429434// copies a point from the point array into the parameter point 
    430 // will set point's z=0 (or NaN) if pa is 2d 
    431 // will set point's m=0 (or NaN( if pa is 3d or 2d 
     435// will set point's z=NO_Z_VALUE if pa is 2d 
     436// will set point's m=NO_M_VALUE if pa is 3d or 2d 
    432437// NOTE: this will modify the point4d pointed to by 'point'. 
    433438int 
    434 getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *point) 
    435 { 
    436         int size; 
    437  
     439getPoint4d_p(const POINTARRAY *pa, int n, POINT4D *op) 
     440{ 
     441        uchar *ptr; 
     442        int zmflag; 
     443 
     444#if PARANOIA_LEVEL > 0 
    438445        if ( ! pa ) return 0; 
    439446 
     
    443450                return 0; //error 
    444451        } 
    445  
    446         memset(point, 0, sizeof(POINT4D)); 
    447         size = pointArray_ptsize(pa); 
    448         memcpy(point, getPoint_internal(pa, n), size); 
     452#endif 
     453 
     454        /* Get a pointer to nth point offset and zmflag */ 
     455        ptr=getPoint_internal(pa, n); 
     456        zmflag=TYPE_GETZM(pa->dims); 
     457 
     458        switch (zmflag) 
     459        { 
     460                case 0: // 2d  
     461                        memcpy(op, ptr, sizeof(POINT2D)); 
     462                        op->m=NO_M_VALUE; 
     463                        op->z=NO_Z_VALUE; 
     464                        break; 
     465 
     466                case 3: // ZM 
     467                        memcpy(op, ptr, sizeof(POINT4D)); 
     468                        break; 
     469 
     470                case 2: // Z 
     471                        memcpy(op, ptr, sizeof(POINT3DZ)); 
     472                        op->m=NO_M_VALUE; 
     473                        break; 
     474 
     475                case 1: // M 
     476                        memcpy(op, ptr, sizeof(POINT3DM)); 
     477                        op->m=op->z; // we use Z as temporary storage 
     478                        op->z=NO_Z_VALUE; 
     479                        break; 
     480 
     481                default: 
     482                        lwerror("Unkown ZM flag ??"); 
     483        } 
     484 
    449485        return 1; 
     486 
    450487} 
    451488 
     
    480517getPoint3dz_p(const POINTARRAY *pa, int n, POINT3DZ *op) 
    481518{ 
    482         int size; 
    483  
     519        uchar *ptr; 
     520 
     521#if PARANOIA_LEVEL > 0 
    484522        if ( ! pa ) return 0; 
     523 
     524        if ( (n<0) || (n>=pa->npoints)) 
     525        { 
     526                lwnotice("%d out of numpoint range (%d)", n, pa->npoints); 
     527                return 0; //error 
     528        } 
     529#endif 
    485530 
    486531#ifdef PGIS_DEBUG 
     
    489534#endif 
    490535 
    491         if ( (n<0) || (n>=pa->npoints)) 
    492         { 
    493                 lwnotice("%d out of numpoint range (%d)", n, pa->npoints); 
    494                 return 0; //error 
    495         } 
    496  
    497         /* initialize point */ 
    498         memset(op, 0, sizeof(POINT3DZ)); 
    499  
    500         /* copy */ 
    501         size = pointArray_ptsize(pa); 
    502 #ifdef PGIS_DEBUG 
    503         lwnotice("getPoint3dz_p: point size: %d", size); 
    504 #endif 
    505         memcpy(op, getPoint_internal(pa, n), size); 
     536        /* Get a pointer to nth point offset */ 
     537        ptr=getPoint_internal(pa, n); 
     538 
     539        /* 
     540         * if input POINTARRAY has the Z, it is always 
     541         * at third position so make a single copy 
     542         */ 
     543        if ( TYPE_HASZ(pa->dims) ) 
     544        { 
     545                memcpy(op, ptr, sizeof(POINT3DZ)); 
     546        } 
     547 
     548        /* 
     549         * Otherwise copy the 2d part and initialize 
     550         * Z to NO_Z_VALUE 
     551         */ 
     552        else 
     553        { 
     554                memcpy(op, ptr, sizeof(POINT2D)); 
     555                op->z=NO_Z_VALUE; 
     556        } 
     557 
    506558        return 1; 
    507559 
     
    509561 
    510562// copies a point from the point array into the parameter point 
    511 // will set point's m=NO_Z_VALUE if pa has no M 
     563// will set point's m=NO_M_VALUE if pa has no M 
    512564// NOTE: this will modify the point3dm pointed to by 'point'. 
    513565int 
    514566getPoint3dm_p(const POINTARRAY *pa, int n, POINT3DM *op) 
    515567{ 
    516         int size; 
    517  
     568        uchar *ptr; 
     569        int zmflag; 
     570 
     571#if PARANOIA_LEVEL > 0 
    518572        if ( ! pa ) return 0; 
     573 
     574        if ( (n<0) || (n>=pa->npoints)) 
     575        { 
     576                lwerror("%d out of numpoint range (%d)", n, pa->npoints); 
     577                return 0; //error 
     578        } 
     579#endif  
    519580 
    520581#ifdef PGIS_DEBUG 
     
    523584#endif 
    524585 
    525         if ( (n<0) || (n>=pa->npoints)) 
    526         { 
    527                 lwerror("%d out of numpoint range (%d)", n, pa->npoints); 
    528                 return 0; //error 
    529         } 
    530  
    531         /* initialize point */ 
    532         memset(op, 0, sizeof(POINT3DM)); 
    533  
    534         /* copy */ 
    535         size = pointArray_ptsize(pa); 
    536 #ifdef PGIS_DEBUG 
    537         lwnotice("getPoint3dz_p: point size: %d", size); 
    538 #endif 
    539         memcpy(op, getPoint_internal(pa, n), size); 
     586 
     587        /* Get a pointer to nth point offset and zmflag */ 
     588        ptr=getPoint_internal(pa, n); 
     589        zmflag=TYPE_GETZM(pa->dims); 
     590 
     591        /* 
     592         * if input POINTARRAY has the M and NO Z, 
     593         * we can issue a single memcpy 
     594         */ 
     595        if ( zmflag == 1 ) 
     596        { 
     597                memcpy(op, ptr, sizeof(POINT3DM)); 
     598                return 1; 
     599        } 
     600 
     601        /* 
     602         * Otherwise copy the 2d part and  
     603         * initialize M to NO_M_VALUE 
     604         */ 
     605        memcpy(op, ptr, sizeof(POINT2D)); 
     606 
     607        /* 
     608         * Then, if input has Z skip it and 
     609         * copy next double, otherwise initialize 
     610         * M to NO_M_VALUE 
     611         */ 
     612        if ( zmflag == 3 ) 
     613        { 
     614                ptr+=sizeof(POINT3DZ); 
     615                memcpy(&(op->m), ptr, sizeof(double)); 
     616        } 
     617        else 
     618        { 
     619                op->m=NO_M_VALUE; 
     620        } 
     621 
    540622        return 1; 
    541623} 
     
    549631{ 
    550632        POINT2D result; 
    551         int size; 
    552  
    553         if ( (n<0) || (n>=pa->npoints)) 
    554         { 
    555                 return result; //error 
    556         } 
    557  
    558         size = pointArray_ptsize(pa); 
    559  
    560         // this does x,y 
    561         memcpy(&result.x, &pa->serialized_pointlist[size*n],sizeof(double)*2 ); 
     633        getPoint2d_p(pa, n, &result); 
    562634        return result; 
    563635} 
     
    569641getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point) 
    570642{ 
    571          int size; 
    572  
     643#if PARANOIA_LEVEL > 0 
    573644        if ( ! pa ) return 0; 
    574645 
    575          if ( (n<0) || (n>=pa->npoints)) 
    576          { 
    577                  lwerror("getPoint2d_p: point offset out of range"); 
    578                  return 0; //error 
    579          } 
    580  
    581          size = pointArray_ptsize(pa); 
    582  
    583          // this does x,y 
    584          memcpy(point, &pa->serialized_pointlist[size*n],sizeof(double)*2 ); 
    585          return 1; 
     646        if ( (n<0) || (n>=pa->npoints)) 
     647        { 
     648                lwerror("getPoint2d_p: point offset out of range"); 
     649                return 0; //error 
     650        } 
     651#endif 
     652 
     653        // this does x,y 
     654        memcpy(point, getPoint_internal(pa, n), sizeof(POINT2D)); 
     655        return 1; 
    586656} 
    587657 
     
    594664        int size; 
    595665 
     666#if PARANOIA_LEVEL > 0 
    596667        if ( pa == NULL ) { 
    597668                lwerror("getPoint got NULL pointarray"); 
     
    603674                return NULL; //error 
    604675        } 
     676#endif 
    605677 
    606678        size = pointArray_ptsize(pa); 
  • trunk/regress/regress_expected

    r2026 r2053  
    144144142|SRID=5;MULTILINESTRING((2 2,3 3)) 
    145145143|SRID=6;MULTIPOLYGON(((0 0,1 0,1 1,0 1,0 0))) 
     146144|POINTM(1 2 0) 
     147145|POINT(1 2 0) 
     148146|POINT(1 2 0 3) 
     149147|POINT(1 2 3 0) 
    146150144|LINESTRING(-5 -5,0 0,1 1,4 4) 
  • trunk/regress/regress.sql

    r2026 r2053  
    239239select '143', asewkt(multi(setsrid('POLYGON((0 0, 1 0, 1 1, 0 1, 0 0))'::geometry, 6))); 
    240240 
     241select '144', asewkt(force_3dm('POINT(1 2 3)')); 
     242select '145', asewkt(force_3dz('POINTM(1 2 3)')); 
     243select '146', asewkt(force_4d('POINTM(1 2 3)')); 
     244select '147', asewkt(force_4d('POINT(1 2 3)')); 
     245 
    241246select '144', asewkt(linemerge('GEOMETRYCOLLECTION(LINESTRING(0 0, 1 1), LINESTRING(4 4, 1 1), LINESTRING(-5 -5, 0 0))'::geometry));