From: Darafei Praliaskouski Date: Thu, 6 Sep 2018 18:16:18 +0000 (+0000) Subject: Inline 2D squared distance. X-Git-Tag: 3.0.0alpha1~467 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5eb3014e6c550b127f1484a7e2226bfcf0970ecc;p=postgis Inline 2D squared distance. This allows loops with distance2d_sqr_pt_pt to be optimized better. Closes https://github.com/postgis/postgis/pull/290 git-svn-id: http://svn.osgeo.org/postgis/trunk@16715 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 0291c1b2b..457b57474 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -1179,7 +1179,16 @@ extern float next_float_up(double d); /* 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); diff --git a/liblwgeom/measures.c b/liblwgeom/measures.c index a570102b9..1349d4ea7 100644 --- a/liblwgeom/measures.c +++ b/liblwgeom/measures.c @@ -2318,15 +2318,6 @@ distance2d_pt_pt(const POINT2D *p1, const POINT2D *p2) 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) {