GEOS 3.14.0dev
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#include <cmath>
21
22namespace geos {
23namespace index { // geos::index
24namespace strtree { // geos::index::strtree
25
27//
30class GEOS_DLL Interval {
31public:
32 Interval(double newMin, double newMax) : imin(newMin), imax(newMax) {
33 assert(std::isnan(newMin) || std::isnan(newMax) || imin <= imax);
34 }
35
36 double getMin() const { return imin; }
37 double getMax() const { return imax; }
38 double getWidth() const { return imax - imin; }
39 double getCentre() const { return (imin + imax) / 2; }
40 Interval* expandToInclude(const Interval* other) {
41 imax = std::max(imax, other->imax);
42 imin = std::min(imin, other->imin);
43 return this;
44 }
45 bool intersects(const Interval* other) const {
46 return !(other->imin > imax || other->imax < imin);
47 }
48 bool equals(const Interval* other) const {
49 return imin == other->imin && imax == other->imax;
50 }
51private:
52 double imin;
53 double imax;
54};
55
56
57} // namespace geos::index::strtree
58} // namespace geos::index
59} // namespace geos
60
A contiguous portion of 1D-space. Used internally by SIRtree.
Definition strtree/Interval.h:30
Basic namespace for all GEOS functionalities.
Definition geos.h:39