GEOS  3.13.0dev
EnvelopeDistanceClusterFinder.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2020-2021 Daniel Baston
7  *
8  * This is free software; you can redistribute and/or modify it under
9  * the terms of the GNU Lesser General Public Licence as published
10  * by the Free Software Foundation.
11  * See the COPYING file for more information.
12  *
13  **********************************************************************/
14 
15 #ifndef GEOS_OPERATION_CLUSTER_ENVELOPEDISTANCECLUSTERFINDER
16 #define GEOS_OPERATION_CLUSTER_ENVELOPEDISTANCECLUSTERFINDER
17 
18 #include <geos/operation/cluster/AbstractClusterFinder.h>
19 #include <geos/geom/Envelope.h>
20 
21 namespace geos {
22 namespace operation {
23 namespace cluster {
24 
29 public:
30  explicit EnvelopeDistanceClusterFinder(double d) : m_distance(d), m_distance_squared(d*d) {}
31 
32 protected:
33  const geom::Envelope& queryEnvelope(const geom::Geometry* a) override {
34  m_envelope = *a->getEnvelopeInternal();
35  m_envelope.expandBy(m_distance);
36  return m_envelope;
37  }
38 
39  bool shouldJoin(const geom::Geometry* a, const geom::Geometry *b) override {
40  return a->getEnvelopeInternal()->distanceSquared(*b->getEnvelopeInternal()) <= m_distance_squared;
41  }
42 
43 private:
44  geom::Envelope m_envelope;
45  double m_distance;
46  double m_distance_squared;
47 };
48 
49 }
50 }
51 }
52 
53 #endif
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
double distanceSquared(const Envelope &env) const
Computes the square of the distance between this and another Envelope.
Definition: Envelope.h:694
void expandBy(double deltaX, double deltaY)
Expands this envelope by a given distance in all directions. Both positive and negative distances are...
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
virtual const Envelope * getEnvelopeInternal() const =0
Returns the minimum and maximum x and y values in this Geometry, or a null Envelope if this Geometry ...
Definition: AbstractClusterFinder.h:47
Definition: EnvelopeDistanceClusterFinder.h:28
bool shouldJoin(const geom::Geometry *a, const geom::Geometry *b) override
Definition: EnvelopeDistanceClusterFinder.h:39
const geom::Envelope & queryEnvelope(const geom::Geometry *a) override
Definition: EnvelopeDistanceClusterFinder.h:33
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25