GEOS 3.16.0dev
DirectedHausdorffDistance.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2026 Martin Davis
7 * Copyright (C) 2026 Jeroen Bloemscheer
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: algorithm/distance/DirectedHausdorffDistance.java (aff11591)
17 *
18 **********************************************************************/
19
20#pragma once
21
22#include <geos/export.h>
23#include <geos/geom/Coordinate.h>
24
25#include <array>
26#include <memory>
27#include <optional>
28
29#ifdef _MSC_VER
30#pragma warning(push)
31#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
32#endif
33
34namespace geos {
35namespace geom {
36class Envelope;
37class Geometry;
38}
39}
40
41namespace geos {
42namespace algorithm {
43namespace distance {
44
97public:
99 using PointPair = std::array<geom::CoordinateXY, 2>;
100
110 static double distance(const geom::Geometry& a, const geom::Geometry& b);
111
123 static double distance(const geom::Geometry& a, const geom::Geometry& b,
124 double tolerance);
125
135 static std::optional<PointPair> distancePoints(
136 const geom::Geometry& a, const geom::Geometry& b);
137
148 static std::optional<PointPair> distancePoints(
149 const geom::Geometry& a, const geom::Geometry& b, double tolerance);
150
159 static double hausdorffDistance(const geom::Geometry& a, const geom::Geometry& b);
160
171 static std::optional<PointPair> hausdorffDistancePoints(
172 const geom::Geometry& a, const geom::Geometry& b);
173
186 const geom::Geometry& a, const geom::Geometry& b, double maxDistance);
187
202 const geom::Geometry& a, const geom::Geometry& b,
203 double maxDistance, double tolerance);
204
211
213 DirectedHausdorffDistance& operator=(const DirectedHausdorffDistance&) = delete;
214
216
226 std::optional<PointPair> farthestPoints(const geom::Geometry& geom) const;
227
239 std::optional<PointPair> farthestPoints(const geom::Geometry& geom, double tolerance) const;
240
251 bool isFullyWithinDistance(const geom::Geometry& geom, double maxDistance) const;
252
266 const geom::Geometry& geom, double maxDistance, double tolerance) const;
267
268private:
269 class TargetDistance;
270 friend class DHDSegment;
271
272 static double pairDistance(const std::optional<PointPair>& pts);
273 static PointPair pair(const geom::CoordinateXY& p0, const geom::CoordinateXY& p1);
274 static double computeTolerance(const geom::Geometry& geom);
275 static bool isBeyond(
276 const geom::Envelope& envA, const geom::Envelope& envB, double maxDistance);
277 static bool isValidLimit(double limit);
278 static bool isBeyondLimit(double maxDist, double maxDistanceLimit);
279 static bool isWithinLimit(double maxDist, double maxDistanceLimit);
280
281 std::optional<PointPair> computeDistancePoints(
282 const geom::Geometry& geom, double tolerance, double maxDistanceLimit) const;
283 std::optional<PointPair> computeForPoints(
284 const geom::Geometry& geom, double maxDistanceLimit) const;
285 std::optional<PointPair> computeForEdges(
286 const geom::Geometry& geom, double tolerance, double maxDistanceLimit) const;
287 std::optional<PointPair> computeForAreaInterior(
288 const geom::Geometry& geom, double tolerance) const;
289
290 const geom::Geometry& target;
291 std::unique_ptr<TargetDistance> targetDistance;
292};
293
294} // namespace distance
295} // namespace algorithm
296} // namespace geos
297
298#ifdef _MSC_VER
299#pragma warning(pop)
300#endif
Definition DirectedHausdorffDistance.h:96
static bool isFullyWithinDistance(const geom::Geometry &a, const geom::Geometry &b, double maxDistance, double tolerance)
static std::optional< PointPair > distancePoints(const geom::Geometry &a, const geom::Geometry &b, double tolerance)
static std::optional< PointPair > distancePoints(const geom::Geometry &a, const geom::Geometry &b)
bool isFullyWithinDistance(const geom::Geometry &geom, double maxDistance) const
static double distance(const geom::Geometry &a, const geom::Geometry &b)
static std::optional< PointPair > hausdorffDistancePoints(const geom::Geometry &a, const geom::Geometry &b)
static bool isFullyWithinDistance(const geom::Geometry &a, const geom::Geometry &b, double maxDistance)
std::optional< PointPair > farthestPoints(const geom::Geometry &geom, double tolerance) const
std::array< geom::CoordinateXY, 2 > PointPair
JTS returns Coordinate[]; std::array is the C++ equivalent pair.
Definition DirectedHausdorffDistance.h:99
static double hausdorffDistance(const geom::Geometry &a, const geom::Geometry &b)
static double distance(const geom::Geometry &a, const geom::Geometry &b, double tolerance)
bool isFullyWithinDistance(const geom::Geometry &geom, double maxDistance, double tolerance) const
std::optional< PointPair > farthestPoints(const geom::Geometry &geom) const
DirectedHausdorffDistance(const geom::Geometry &geom)
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:201
Basic namespace for all GEOS functionalities.
Definition geos.h:38