GEOS 3.11.1
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
21namespace geos {
22namespace index { // geos::index
23namespace strtree { // geos::index::strtree
24
26//
29class GEOS_DLL Interval {
30public:
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 }
50private:
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: geos.h:39