GEOS 3.11.1
Rectangle.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2014 Mika Heiskanen <mika.heiskanen@fmi.fi>
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
19#ifdef _MSC_VER
20#pragma warning(push)
21#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
22#endif
23
24// Forward declarations
25namespace geos {
26namespace geom {
27class GeometryFactory;
28class Geometry;
29class Polygon;
30class LinearRing;
31}
32}
33
34namespace geos {
35namespace operation { // geos::operation
36namespace intersection { // geos::operation::intersection
37
50class GEOS_DLL Rectangle {
51public:
52
63 Rectangle(double x1, double y1, double x2, double y2);
64
68 double
69 xmin() const
70 {
71 return xMin;
72 }
73
78 double
79 ymin() const
80 {
81 return yMin;
82 }
83
84
89 double
90 xmax() const
91 {
92 return xMax;
93 }
94
95
100 double
101 ymax() const
102 {
103 return yMax;
104 }
105
112
113 geom::LinearRing* toLinearRing(const geom::GeometryFactory& f) const;
114
119 enum Position {
120 Inside = 1,
121 Outside = 2,
122
123 Left = 4,
124 Top = 8,
125 Right = 16,
126 Bottom = 32,
127
128 TopLeft = Top | Left, // 12
129 TopRight = Top | Right, // 24
130 BottomLeft = Bottom | Left, // 36
131 BottomRight = Bottom | Right // 48
132 };
133
140 static bool
142 {
143 return (pos > Outside);
144 }
145
153 static bool
155 {
156 return onEdge(Position(pos1 & pos2));
157 }
158
166 Position
167 position(double x, double y) const
168 {
169 // We assume the point to be inside and test it first
170 if(x > xMin && x < xMax && y > yMin && y < yMax) {
171 return Inside;
172 }
173 // Next we assume the point to be outside and test it next
174 if(x < xMin || x > xMax || y < yMin || y > yMax) {
175 return Outside;
176 }
177 // Slower cases
178 unsigned int pos = 0;
179 if(x == xMin) {
180 pos |= Left;
181 }
182 else if(x == xMax) {
183 pos |= Right;
184 }
185 if(y == yMin) {
186 pos |= Bottom;
187 }
188 else if(y == yMax) {
189 pos |= Top;
190 }
191 return Position(pos);
192 }
193
200 static Position
202 {
203 switch(pos) {
204 case BottomLeft:
205 case Left:
206 return Top;
207 case TopLeft:
208 case Top:
209 return Right;
210 case TopRight:
211 case Right:
212 return Bottom;
213 case BottomRight:
214 case Bottom:
215 return Left;
216 /* silences compiler warnings, Inside & Outside are not handled explicitly */
217 default:
218 return pos;
219 }
220 }
221
222private:
223
224 Rectangle();
225 double xMin;
226 double yMin;
227 double xMax;
228 double yMax;
229
230}; // class RectangleIntersection
231
232} // namespace geos::operation::intersection
233} // namespace geos::operation
234} // namespace geos
235
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition: LinearRing.h:55
Represents a linear polygon, which may include holes.
Definition: Polygon.h:61
Clipping rectangle.
Definition: Rectangle.h:50
double xmax() const
Definition: Rectangle.h:90
Rectangle(double x1, double y1, double x2, double y2)
Construct a clipping rectangle.
geom::Polygon * toPolygon(const geom::GeometryFactory &f) const
static Position nextEdge(Position pos)
Next edge in clock-wise direction.
Definition: Rectangle.h:201
static bool onEdge(Position pos)
Test if the given position is on a Rectangle edge.
Definition: Rectangle.h:141
Position position(double x, double y) const
Establish position of coordinate with respect to a Rectangle.
Definition: Rectangle.h:167
static bool onSameEdge(Position pos1, Position pos2)
Test if the given positions are on the same Rectangle edge.
Definition: Rectangle.h:154
double xmin() const
Definition: Rectangle.h:69
double ymin() const
Definition: Rectangle.h:79
double ymax() const
Definition: Rectangle.h:101
Position
Position with respect to a clipping rectangle.
Definition: Rectangle.h:119
Basic namespace for all GEOS functionalities.
Definition: geos.h:39