[geos-commits] [SCM] GEOS branch main updated. 9e2348082d2ecd02f8241a90e62954a17f8773af
git at osgeo.org
git at osgeo.org
Tue Jan 6 08:41:48 PST 2026
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 "GEOS".
The branch, main has been updated
via 9e2348082d2ecd02f8241a90e62954a17f8773af (commit)
from 02cbfe81143f6303f234f8a9ce3d9694ddcec381 (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 9e2348082d2ecd02f8241a90e62954a17f8773af
Author: Sven Jensen <sven at analysis.net>
Date: Tue Jan 6 08:41:28 2026 -0800
Add new CAPI functions for Hausdorff distance (#1352)
* Add new CAPI functions for Hausdorff distance
Introduce two new CAPI functions:
- GEOSHausdorffDistanceWithPoints
- GEOSHausdorffDistanceDensifyWithPoints
These functions take four additional double pointers
(pt1_x, pt1_y, pt2_x, pt2_y) and fill them with the
coordinates used in the Hausdorff distance calculation
via getCoordinates().
Also add a unit test verifying the new function behavior.
* typo in function out parameter documentation
* GEOSHausdorffDistanceWithPoints: simplify implementation
---------
Co-authored-by: Dan Baston <dbaston at gmail.com>
diff --git a/capi/geos_c.cpp b/capi/geos_c.cpp
index d26db0966..9a832a64b 100644
--- a/capi/geos_c.cpp
+++ b/capi/geos_c.cpp
@@ -317,12 +317,24 @@ extern "C" {
return GEOSHausdorffDistance_r(handle, g1, g2, dist);
}
+ int
+ GEOSHausdorffDistanceWithPoints(const Geometry* g1, const Geometry* g2, double* dist, double* p1x, double* p1y, double* p2x, double* p2y)
+ {
+ return GEOSHausdorffDistanceWithPoints_r(handle, g1, g2, dist, p1x, p1y, p2x, p2y);
+ }
+
int
GEOSHausdorffDistanceDensify(const Geometry* g1, const Geometry* g2, double densifyFrac, double* dist)
{
return GEOSHausdorffDistanceDensify_r(handle, g1, g2, densifyFrac, dist);
}
+ int
+ GEOSHausdorffDistanceDensifyWithPoints(const Geometry* g1, const Geometry* g2, double densifyFrac, double* dist, double* p1x, double* p1y, double* p2x, double* p2y)
+ {
+ return GEOSHausdorffDistanceDensifyWithPoints_r(handle, g1, g2, densifyFrac, dist, p1x, p1y, p2x, p2y);
+ }
+
int
GEOSFrechetDistance(const Geometry* g1, const Geometry* g2, double* dist)
{
diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index 942663671..44bb6d3ed 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -1954,6 +1954,15 @@ extern int GEOS_DLL GEOSHausdorffDistance_r(
const GEOSGeometry *g2,
double *dist);
+/** \see GEOSHausdorffDistanceWithPoints */
+extern int GEOS_DLL GEOSHausdorffDistanceWithPoints_r(
+ GEOSContextHandle_t handle,
+ const GEOSGeometry *g1,
+ const GEOSGeometry *g2,
+ double *dist,
+ double *p1x, double *p1y,
+ double *p2x, double *p2y);
+
/** \see GEOSHausdorffDistanceDensify */
extern int GEOS_DLL GEOSHausdorffDistanceDensify_r(
GEOSContextHandle_t handle,
@@ -1961,6 +1970,15 @@ extern int GEOS_DLL GEOSHausdorffDistanceDensify_r(
const GEOSGeometry *g2,
double densifyFrac, double *dist);
+/** \see GEOSHausdorffDistanceDensifyWithPoints */
+extern int GEOS_DLL GEOSHausdorffDistanceDensifyWithPoints_r(
+ GEOSContextHandle_t handle,
+ const GEOSGeometry *g1,
+ const GEOSGeometry *g2,
+ double densifyFrac, double* dist,
+ double *p1x, double *p1y,
+ double *p2x, double *p2y);
+
/** \see GEOSFrechetDistance */
extern int GEOS_DLL GEOSFrechetDistance_r(
GEOSContextHandle_t handle,
@@ -3704,6 +3722,30 @@ extern int GEOS_DLL GEOSHausdorffDistance(
const GEOSGeometry *g2,
double *dist);
+
+/**
+* Calculate the Hausdorff distance between two geometries and return
+* the coordinates of the points that determine the distance.
+* \param[in] g1 Input geometry
+* \param[in] g2 Input geometry
+* \param[out] dist Pointer to be filled in with distance result
+* \param[out] p1x X coordinate of point on g1
+* \param[out] p1y Y coordinate of point on g1
+* \param[out] p2x X coordinate of point on g2
+* \param[out] p2y Y coordinate of point on g2
+* \return 1 on success, 0 on exception.
+* \see geos::algorithm::distance::DiscreteHausdorffDistance
+* \since 3.15
+*/
+extern int GEOS_DLL GEOSHausdorffDistanceWithPoints(
+ const GEOSGeometry *g1,
+ const GEOSGeometry *g2,
+ double *dist,
+ double *p1x, double *p1y,
+ double *p2x, double *p2y);
+
+
+
/**
* Calculate a more precise Hausdorff distance between two geometries,
* by densifying the inputs before computation.
@@ -3724,6 +3766,33 @@ extern int GEOS_DLL GEOSHausdorffDistanceDensify(
double densifyFrac,
double *dist);
+/**
+ * Calculate a more precise Hausdorff distance between two geometries,
+ * by densifying the inputs before computation and return the points
+ * that determine the distance.
+ * [Hausdorff distance](https://en.wikipedia.org/wiki/Hausdorff_distance)
+ * is the largest distance between two geometries.
+ * \param[in] g1 Input geometry
+ * \param[in] g2 Input geometry
+ * \param[in] densifyFrac The largest % of the overall line length that
+ * any given two point segment should be.
+ * \param[out] dist Pointer to be filled in with distance result
+ * \param[out] p1x X coordinate of point on g1
+ * \param[out] p1y Y coordinate of point on g1
+ * \param[out] p2x X coordinate of point on g2
+ * \param[out] p2y Y coordinate of point on g2
+ * \return 1 on success, 0 on exception.
+ * \see goes::algorithm::distance::DiscreteHausdorffDistance
+ * \since 3.15
+ */
+extern int GEOS_DLL GEOSHausdorffDistanceDensifyWithPoints(
+ const GEOSGeometry *g1,
+ const GEOSGeometry *g2,
+ double densifyFrac,
+ double *dist,
+ double* p1x, double* p1y,
+ double* p2x, double* p2y);
+
/**
* Calculate the
* [Frechet distance](https://en.wikipedia.org/wiki/Fr%C3%A9chet_distance)
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index d8b57fd87..e082f799c 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -968,6 +968,24 @@ extern "C" {
});
}
+ int
+ GEOSHausdorffDistanceWithPoints_r(GEOSContextHandle_t extHandle,
+ const Geometry* g1, const Geometry* g2,
+ double* dist, double* p1x, double* p1y,
+ double* p2x, double* p2y)
+ {
+ return execute(extHandle, 0, [&]() {
+ DiscreteHausdorffDistance dhd(*g1, *g2);
+ *dist = dhd.distance();
+ const auto& pts = dhd.getCoordinates();
+ *p1x = pts[0].x;
+ *p1y = pts[0].y;
+ *p2x = pts[1].x;
+ *p2y = pts[1].y;
+ return 1;
+ });
+ }
+
int
GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2,
double densifyFrac, double* dist)
@@ -978,6 +996,23 @@ extern "C" {
});
}
+ int
+ GEOSHausdorffDistanceDensifyWithPoints_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2,
+ double densifyFrac, double* dist, double* p1x, double* p1y, double* p2x, double* p2y)
+ {
+ return execute(extHandle, 0, [&]() {
+ DiscreteHausdorffDistance dhd(*g1, *g2);
+ dhd.setDensifyFraction(densifyFrac);
+ *dist = dhd.distance();
+ const auto& pts = dhd.getCoordinates();
+ *p1x = pts[0].x;
+ *p1y = pts[0].y;
+ *p2x = pts[1].x;
+ *p2y = pts[1].y;
+ return 1;
+ });
+ }
+
int
GEOSFrechetDistance_r(GEOSContextHandle_t extHandle, const Geometry* g1, const Geometry* g2, double* dist)
{
diff --git a/include/geos/algorithm/distance/DiscreteHausdorffDistance.h b/include/geos/algorithm/distance/DiscreteHausdorffDistance.h
index be136edee..74876ec7b 100644
--- a/include/geos/algorithm/distance/DiscreteHausdorffDistance.h
+++ b/include/geos/algorithm/distance/DiscreteHausdorffDistance.h
@@ -96,7 +96,7 @@ public:
static double distance(const geom::Geometry& g0,
const geom::Geometry& g1, double densifyFrac);
-
+
DiscreteHausdorffDistance(const geom::Geometry& p_g0,
const geom::Geometry& p_g1)
:
@@ -130,7 +130,7 @@ public:
return ptDist.getDistance();
}
- const std::array<geom::CoordinateXY, 2>
+ const std::array<geom::CoordinateXY, 2>&
getCoordinates() const
{
return ptDist.getCoordinates();
diff --git a/src/algorithm/distance/DiscreteHausdorffDistance.cpp b/src/algorithm/distance/DiscreteHausdorffDistance.cpp
index 3712b0a40..6b0e7914d 100644
--- a/src/algorithm/distance/DiscreteHausdorffDistance.cpp
+++ b/src/algorithm/distance/DiscreteHausdorffDistance.cpp
@@ -79,8 +79,8 @@ DiscreteHausdorffDistance::distance(const geom::Geometry& g0,
return dist.distance();
}
-/* public */
+/* public */
void DiscreteHausdorffDistance::setDensifyFraction(double dFrac)
{
// !(dFrac > 0) written that way to catch NaN
diff --git a/tests/unit/capi/GEOSHausdorffDistanceTest.cpp b/tests/unit/capi/GEOSHausdorffDistanceTest.cpp
index eb569c60a..747d2a9df 100644
--- a/tests/unit/capi/GEOSHausdorffDistanceTest.cpp
+++ b/tests/unit/capi/GEOSHausdorffDistanceTest.cpp
@@ -72,4 +72,45 @@ void object::test<3>()
ensure_equals("curved geometry not supported", GEOSHausdorffDistance(geom2_, geom1_, &dist), 0);
}
+template<>
+template<>
+void object::test<4>()
+{
+ set_test_name("GEOSHausdorffDistanceWithPoints");
+
+ geom1_ = fromWKT("LINEARRING (1 1, 1 2, 5 1, 1 1)");
+ geom2_ = fromWKT("LINEARRING (0 0, -5 0, 0 -1, 0 0)");
+
+ double dist;
+ double p1x, p1y, p2x, p2y;
+ ensure_equals(GEOSHausdorffDistanceWithPoints(geom1_, geom2_, &dist, &p1x, &p1y, &p2x, &p2y), 1);
+
+ ensure_equals("dist", dist, 6.082763, 1e-5);
+ ensure_equals(p1x, 1);
+ ensure_equals(p1y, 1);
+ ensure_equals(p2x, -5);
+ ensure_equals(p2y, 0);
+}
+
+template<>
+template<>
+void object::test<5>()
+{
+ set_test_name("GEOSHausdorffDistanceDensifyWithPoints");
+
+ constexpr double densifyFrac = 0.001;
+ geom1_ = fromWKT("LINEARRING (1 1, 1 2, 5 1, 1 1)");
+ geom2_ = fromWKT("LINEARRING (0 0, -5 0, 0 -1, 0 0)");
+
+ double dist;
+ double p1x, p1y, p2x, p2y;
+ ensure_equals(GEOSHausdorffDistanceDensifyWithPoints(geom1_, geom2_, densifyFrac, &dist, &p1x, &p1y, &p2x, &p2y), 1);
+
+ ensure_equals("dist", dist, 6.082763, 1e-5);
+ ensure_equals(p1x, 1);
+ ensure_equals(p1y, 1);
+ ensure_equals(p2x, -5);
+ ensure_equals(p2y, 0);
+}
+
} // namespace tut
-----------------------------------------------------------------------
Summary of changes:
capi/geos_c.cpp | 12 ++++
capi/geos_c.h.in | 69 ++++++++++++++++++++++
capi/geos_ts_c.cpp | 35 +++++++++++
.../algorithm/distance/DiscreteHausdorffDistance.h | 4 +-
.../distance/DiscreteHausdorffDistance.cpp | 2 +-
tests/unit/capi/GEOSHausdorffDistanceTest.cpp | 41 +++++++++++++
6 files changed, 160 insertions(+), 3 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list