From 93451957c2bdcbce285fab4ae487001248e4bea0 Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Fri, 28 Sep 2012 21:48:53 +0000 Subject: [PATCH] Add new pointer-based coordinate access method, now that aligned storage is the new normal. git-svn-id: http://svn.osgeo.org/postgis/trunk@10340 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/liblwgeom.h.in | 8 ++++++++ liblwgeom/lwgeom_api.c | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index d80b9d0a8..147d2da1f 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -765,6 +765,14 @@ extern POINT2D getPoint2d(const POINTARRAY *pa, int n); */ extern int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point); +/** +* Returns a pointer into the POINTARRAY serialized_ptlist, +* suitable for reading from. This is very high performance +* and declared const because you aren't allowed to muck with the +* values, only read them. +*/ +extern const POINT2D* getPoint2d_cp(const POINTARRAY *pa, int n); + /* * set point N to the given value * NOTE that the pointarray can be of any diff --git a/liblwgeom/lwgeom_api.c b/liblwgeom/lwgeom_api.c index 8c46bd166..c3cff2001 100644 --- a/liblwgeom/lwgeom_api.c +++ b/liblwgeom/lwgeom_api.c @@ -448,6 +448,27 @@ getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point) return 1; } +/** +* Returns a pointer into the POINTARRAY serialized_ptlist, +* suitable for reading from. This is very high performance +* and declared const because you aren't allowed to muck with the +* values, only read them. +*/ +const POINT2D* +getPoint2d_cp(const POINTARRAY *pa, int n) +{ + if ( ! pa ) return 0; + + if ( (n<0) || (n>=pa->npoints)) + { + lwerror("getPoint2D_const_p: point offset out of range"); + return 0; /*error */ + } + + return (const POINT2D*)getPoint_internal(pa, n); +} + + /* * set point N to the given value * NOTE that the pointarray can be of any -- 2.50.1