GEOS  3.14.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 #pragma once
16 
17 #include <geos/operation/cluster/AbstractClusterFinder.h>
18 #include <geos/geom/Envelope.h>
19 
20 namespace geos {
21 namespace operation {
22 namespace cluster {
23 
28 public:
29  explicit EnvelopeDistanceClusterFinder(double d) : m_distance(d), m_distance_squared(d*d) {}
30 
31 protected:
32  const geom::Envelope& queryEnvelope(const geom::Geometry* a) override {
33  m_envelope = *a->getEnvelopeInternal();
34  m_envelope.expandBy(m_distance);
35  return m_envelope;
36  }
37 
38  bool shouldJoin(const geom::Geometry* a, const geom::Geometry *b) override {
39  return a->getEnvelopeInternal()->distanceSquared(*b->getEnvelopeInternal()) <= m_distance_squared;
40  }
41 
42 private:
43  geom::Envelope m_envelope;
44  double m_distance;
45  double m_distance_squared;
46 };
47 
48 }
49 }
50 }
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
double distanceSquared(const Envelope &env) const
Computes the square of the distance between this and another Envelope.
Definition: Envelope.h:695
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:197
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:45
Definition: EnvelopeDistanceClusterFinder.h:27
bool shouldJoin(const geom::Geometry *a, const geom::Geometry *b) override
Definition: EnvelopeDistanceClusterFinder.h:38
const geom::Envelope & queryEnvelope(const geom::Geometry *a) override
Definition: EnvelopeDistanceClusterFinder.h:32
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25