From 9f1e041ad246e3e993c6f9569850d05133fb383d Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Tue, 9 Jan 2024 12:47:44 -0800 Subject: [PATCH] Fix logic mistake in ST_Covers for geography --- NEWS | 1 + liblwgeom/lwgeodetic.c | 19 +++---------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index 613539f6652..b01e9fa4619 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ Proj 6.1+, and PostgreSQL 14+. - #5629, Handling EMPTY components in repeated point removal (Paul Ramsey) - #5604, Handle distance between collections with empty elements (Paul Ramsey) - #5635, Handle NaN points in ST_Split (Regina Obe) + - Logic error in ST_Covers(geography) (Paul Ramsey) PostGIS 3.2.6 diff --git a/liblwgeom/lwgeodetic.c b/liblwgeom/lwgeodetic.c index 87b4c1316a5..dea725c7d7c 100644 --- a/liblwgeom/lwgeodetic.c +++ b/liblwgeom/lwgeodetic.c @@ -2625,23 +2625,10 @@ int lwpoly_covers_lwpoly(const LWPOLY *poly1, const LWPOLY *poly2) /* check if all vertices of poly2 are inside poly1 */ for (i = 0; i < poly2->nrings; i++) { - - /* every other ring is a hole, check if point is inside the actual polygon */ - if ( i % 2 == 0) - { - if (LW_FALSE == lwpoly_covers_pointarray(poly1, poly2->rings[i])) - { - LWDEBUG(4,"returning false, geometry2 has point outside of geometry1"); - return LW_FALSE; - } - } - else + if (LW_FALSE == lwpoly_covers_pointarray(poly1, poly2->rings[i])) { - if (LW_TRUE == lwpoly_covers_pointarray(poly1, poly2->rings[i])) - { - LWDEBUG(4,"returning false, geometry2 has point inside a hole of geometry1"); - return LW_FALSE; - } + LWDEBUG(4,"returning false, geometry2 has point outside of geometry1"); + return LW_FALSE; } }