[postgis-tickets] r16715 - Inline 2D squared distance.

Darafei komzpa at gmail.com
Thu Sep 6 11:16:20 PDT 2018


Author: komzpa
Date: 2018-09-06 11:16:18 -0700 (Thu, 06 Sep 2018)
New Revision: 16715

Modified:
   trunk/liblwgeom/liblwgeom.h.in
   trunk/liblwgeom/measures.c
Log:
Inline 2D squared distance.

This allows loops with distance2d_sqr_pt_pt to be optimized better.

Closes https://github.com/postgis/postgis/pull/290



Modified: trunk/liblwgeom/liblwgeom.h.in
===================================================================
--- trunk/liblwgeom/liblwgeom.h.in	2018-09-05 21:39:28 UTC (rev 16714)
+++ trunk/liblwgeom/liblwgeom.h.in	2018-09-06 18:16:18 UTC (rev 16715)
@@ -1179,7 +1179,16 @@
 
 /* general utilities 2D */
 extern double  distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2);
-extern double  distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2);
+
+inline static double
+distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
+{
+	double hside = p2->x - p1->x;
+	double vside = p2->y - p1->y;
+
+	return hside * hside + vside * vside;
+}
+
 extern double  distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
 extern double  distance2d_sqr_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B);
 extern LWGEOM* lwgeom_closest_line(const LWGEOM *lw1, const LWGEOM *lw2);

Modified: trunk/liblwgeom/measures.c
===================================================================
--- trunk/liblwgeom/measures.c	2018-09-05 21:39:28 UTC (rev 16714)
+++ trunk/liblwgeom/measures.c	2018-09-06 18:16:18 UTC (rev 16715)
@@ -2318,15 +2318,6 @@
 	return hypot(hside, vside);
 }
 
-inline double
-distance2d_sqr_pt_pt(const POINT2D *p1, const POINT2D *p2)
-{
-	double hside = p2->x - p1->x;
-	double vside = p2->y - p1->y;
-
-	return hside * hside + vside * vside;
-}
-
 double
 distance2d_pt_seg(const POINT2D *p, const POINT2D *A, const POINT2D *B)
 {



More information about the postgis-tickets mailing list