[postgis-tickets] [SCM] PostGIS; Spatial objects for PostgreSQL. branch master updated. 866b3c800e5881d7123a545a693c207f12de37ca

git at osgeo.org git at osgeo.org
Mon Nov 11 22:15:16 PST 2019


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS; Spatial objects for PostgreSQL.".

The branch, master has been updated
       via  866b3c800e5881d7123a545a693c207f12de37ca (commit)
       via  cc500d1bfddf46c1f2c1942372e0ea976c07ed1f (commit)
      from  0cbdd4d61558320575c6ec9f7e775ed785bdcfee (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 866b3c800e5881d7123a545a693c207f12de37ca
Author: Darafei Praliaskouski <me at komzpa.net>
Date:   Thu Oct 31 17:56:19 2019 +0300

    ptarray_snap_to_grid: write to ptarray only once per point.

diff --git a/NEWS b/NEWS
index 169371b..6f80c2d 100644
--- a/NEWS
+++ b/NEWS
@@ -14,7 +14,8 @@ PostGIS 3.1.0
   - #4539, Unify libm includes (Raúl Marín)
   - #4569, Allow unknown SRID geometry insertion into typmod SRID column (Paul Ramsey)
   - #4149, ST_Simplify(geom, 0) is now O(N).
-           ST_Affine (ST_Translate, ST_TransScale, ST_Rotate) optimized. (Darafei Praliaskouski)
+           ST_Affine (ST_Translate, ST_TransScale, ST_Rotate) optimized. 
+           ST_SnapToGrid optimized. (Darafei Praliaskouski)
   - #4574, Link Time Optimizations enabled (Darafei Praliaskouski)
 
 * Bug fixes *
diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c
index 8b1858b..1a12fca 100644
--- a/liblwgeom/ptarray.c
+++ b/liblwgeom/ptarray.c
@@ -2007,63 +2007,58 @@ ptarray_startpoint(const POINTARRAY *pa, POINT4D *pt)
 void
 ptarray_grid_in_place(POINTARRAY *pa, const gridspec *grid)
 {
-	uint32_t i, j = 0;
+	uint32_t j = 0;
 	POINT4D *p, *p_out = NULL;
-	int ndims = FLAGS_NDIMS(pa->flags);
-	int has_z = FLAGS_GET_Z(pa->flags);
-	int has_m = FLAGS_GET_M(pa->flags);
-
-	LWDEBUGF(2, "%s called on %p", __func__, pa);
+	double x, y, z = 0, m = 0;
+	uint32_t ndims = FLAGS_NDIMS(pa->flags);
+	uint32_t has_z = FLAGS_GET_Z(pa->flags);
+	uint32_t has_m = FLAGS_GET_M(pa->flags);
 
-	for (i = 0; i < pa->npoints; i++)
+	for (uint32_t i = 0; i < pa->npoints; i++)
 	{
 		/* Look straight into the abyss */
-		p = (POINT4D*)(getPoint_internal(pa, i));
+		p = (POINT4D *)(getPoint_internal(pa, i));
+		x = p->x;
+		y = p->y;
+		if (ndims > 2)
+			z = p->z;
+		if (ndims > 3)
+			m = p->m;
 
 		if (grid->xsize > 0)
-		{
-			p->x = rint((p->x - grid->ipx)/grid->xsize) * grid->xsize + grid->ipx;
-		}
+			x = rint((x - grid->ipx) / grid->xsize) * grid->xsize + grid->ipx;
 
 		if (grid->ysize > 0)
-		{
-			p->y = rint((p->y - grid->ipy)/grid->ysize) * grid->ysize + grid->ipy;
-		}
+			y = rint((y - grid->ipy) / grid->ysize) * grid->ysize + grid->ipy;
 
 		/* Read and round this point */
 		/* Z is always in third position */
-		if (has_z)
-		{
-			if (grid->zsize > 0)
-				p->z = rint((p->z - grid->ipz)/grid->zsize) * grid->zsize + grid->ipz;
-		}
+		if (has_z && grid->zsize > 0)
+			z = rint((z - grid->ipz) / grid->zsize) * grid->zsize + grid->ipz;
+
 		/* M might be in 3rd or 4th position */
-		if (has_m)
+		if (has_m && grid->msize > 0)
 		{
-			/* In POINT M, M is in 3rd position */
-			if (grid->msize > 0 && !has_z)
-				p->z = rint((p->z - grid->ipm)/grid->msize) * grid->msize + grid->ipm;
-			/* In POINT ZM, M is in 4th position */
-			if (grid->msize > 0 && has_z)
-				p->m = rint((p->m - grid->ipm)/grid->msize) * grid->msize + grid->ipm;
+			/* In POINT ZM, M is in 4th position, in POINT M, M is in 3rd position which is Z in POINT4D */
+			if (has_z)
+				m = rint((m - grid->ipm) / grid->msize) * grid->msize + grid->ipm;
+			else
+				z = rint((z - grid->ipm) / grid->msize) * grid->msize + grid->ipm;
 		}
 
 		/* Skip duplicates */
-		if ( p_out && FP_EQUALS(p_out->x, p->x) && FP_EQUALS(p_out->y, p->y)
-		   && (ndims > 2 ? FP_EQUALS(p_out->z, p->z) : 1)
-		   && (ndims > 3 ? FP_EQUALS(p_out->m, p->m) : 1) )
-		{
+		if (p_out && p_out->x == x && p_out->y == y && (ndims > 2 ? p_out->z == z : 1) &&
+		    (ndims > 3 ? p_out->m == m : 1))
 			continue;
-		}
 
 		/* Write rounded values into the next available point */
-		p_out = (POINT4D*)(getPoint_internal(pa, j++));
-		p_out->x = p->x;
-		p_out->y = p->y;
+		p_out = (POINT4D *)(getPoint_internal(pa, j++));
+		p_out->x = x;
+		p_out->y = y;
 		if (ndims > 2)
-			p_out->z = p->z;
+			p_out->z = z;
 		if (ndims > 3)
-			p_out->m = p->m;
+			p_out->m = m;
 	}
 
 	/* Update output ptarray length */
@@ -2071,7 +2066,6 @@ ptarray_grid_in_place(POINTARRAY *pa, const gridspec *grid)
 	return;
 }
 
-
 int
 ptarray_npoints_in_rect(const POINTARRAY *pa, const GBOX *gbox)
 {

commit cc500d1bfddf46c1f2c1942372e0ea976c07ed1f
Author: Darafei Praliaskouski <me at komzpa.net>
Date:   Thu Oct 31 17:00:29 2019 +0300

    ptarray_affine: operate on ptarray directly.

diff --git a/NEWS b/NEWS
index 97c8bc4..169371b 100644
--- a/NEWS
+++ b/NEWS
@@ -13,7 +13,8 @@ PostGIS 3.1.0
 * Enhancements *
   - #4539, Unify libm includes (Raúl Marín)
   - #4569, Allow unknown SRID geometry insertion into typmod SRID column (Paul Ramsey)
-  - #4149, ST_Simplify(geom, 0) is now O(N) (Darafei Praliaskouski)
+  - #4149, ST_Simplify(geom, 0) is now O(N).
+           ST_Affine (ST_Translate, ST_TransScale, ST_Rotate) optimized. (Darafei Praliaskouski)
   - #4574, Link Time Optimizations enabled (Darafei Praliaskouski)
 
 * Bug fixes *
diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c
index 9894336..8b1858b 100644
--- a/liblwgeom/ptarray.c
+++ b/liblwgeom/ptarray.c
@@ -1806,49 +1806,30 @@ ptarray_length(const POINTARRAY *pts)
 void
 ptarray_affine(POINTARRAY *pa, const AFFINE *a)
 {
-	uint32_t i;
-	double x,y,z;
-	POINT4D p4d;
-
-	LWDEBUG(2, "lwgeom_affine_ptarray start");
-
-	if ( FLAGS_GET_Z(pa->flags) )
+	if (FLAGS_GET_Z(pa->flags))
 	{
-		LWDEBUG(3, " has z");
-
-		for (i=0; i<pa->npoints; i++)
+		for (uint32_t i = 0; i < pa->npoints; i++)
 		{
-			getPoint4d_p(pa, i, &p4d);
-			x = p4d.x;
-			y = p4d.y;
-			z = p4d.z;
-			p4d.x = a->afac * x + a->bfac * y + a->cfac * z + a->xoff;
-			p4d.y = a->dfac * x + a->efac * y + a->ffac * z + a->yoff;
-			p4d.z = a->gfac * x + a->hfac * y + a->ifac * z + a->zoff;
-			ptarray_set_point4d(pa, i, &p4d);
-
-			LWDEBUGF(3, " POINT %g %g %g => %g %g %g", x, y, z, p4d.x, p4d.y, p4d.z);
+			POINT4D *p4d = (POINT4D *)(getPoint_internal(pa, i));
+			double x = p4d->x;
+			double y = p4d->y;
+			double z = p4d->z;
+			p4d->x = a->afac * x + a->bfac * y + a->cfac * z + a->xoff;
+			p4d->y = a->dfac * x + a->efac * y + a->ffac * z + a->yoff;
+			p4d->z = a->gfac * x + a->hfac * y + a->ifac * z + a->zoff;
 		}
 	}
 	else
 	{
-		LWDEBUG(3, " doesn't have z");
-
-		for (i=0; i<pa->npoints; i++)
+		for (uint32_t i = 0; i < pa->npoints; i++)
 		{
-			getPoint4d_p(pa, i, &p4d);
-			x = p4d.x;
-			y = p4d.y;
-			p4d.x = a->afac * x + a->bfac * y + a->xoff;
-			p4d.y = a->dfac * x + a->efac * y + a->yoff;
-			ptarray_set_point4d(pa, i, &p4d);
-
-			LWDEBUGF(3, " POINT %g %g => %g %g", x, y, p4d.x, p4d.y);
+			POINT2D *pt = (POINT2D *)(getPoint_internal(pa, i));
+			double x = pt->x;
+			double y = pt->y;
+			pt->x = a->afac * x + a->bfac * y + a->xoff;
+			pt->y = a->dfac * x + a->efac * y + a->yoff;
 		}
 	}
-
-	LWDEBUG(3, "lwgeom_affine_ptarray end");
-
 }
 
 /**

-----------------------------------------------------------------------

Summary of changes:
 NEWS                |   4 +-
 liblwgeom/ptarray.c | 117 +++++++++++++++++++++-------------------------------
 2 files changed, 49 insertions(+), 72 deletions(-)


hooks/post-receive
-- 
PostGIS; Spatial objects for PostgreSQL.


More information about the postgis-tickets mailing list