GEOS  3.11.0rc0
strtree/Interval.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2006 Refractions Research Inc.
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/export.h>
18 #include <algorithm>
19 #include <cassert>
20 
21 namespace geos {
22 namespace index { // geos::index
23 namespace strtree { // geos::index::strtree
24 
26 //
29 class GEOS_DLL Interval {
30 public:
31  Interval(double newMin, double newMax) : imin(newMin), imax(newMax) {
32  assert(imin <= imax);
33  }
34 
35  double getMin() const { return imin; }
36  double getMax() const { return imax; }
37  double getWidth() const { return imax - imin; }
38  double getCentre() const { return (imin + imax) / 2; }
39  Interval* expandToInclude(const Interval* other) {
40  imax = std::max(imax, other->imax);
41  imin = std::min(imin, other->imin);
42  return this;
43  }
44  bool intersects(const Interval* other) const {
45  return !(other->imin > imax || other->imax < imin);
46  }
47  bool equals(const Interval* other) const {
48  return imin == other->imin && imax == other->imax;
49  }
50 private:
51  double imin;
52  double imax;
53 };
54 
55 
56 } // namespace geos::index::strtree
57 } // namespace geos::index
58 } // namespace geos
59 
A contiguous portion of 1D-space. Used internally by SIRtree.
Definition: strtree/Interval.h:29
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25