00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef GEOS_OP_INTERSECTION_RECTANGLE_H
00016 #define GEOS_OP_INTERSECTION_RECTANGLE_H
00017
00018 #include <geos/export.h>
00019
00020 #ifdef _MSC_VER
00021 #pragma warning(push)
00022 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00023 #endif
00024
00025
00026 namespace geos {
00027 namespace geom {
00028 class GeometryFactory;
00029 class Geometry;
00030 class Polygon;
00031 class LinearRing;
00032 }
00033 }
00034
00035 namespace geos {
00036 namespace operation {
00037 namespace intersection {
00038
00051 class GEOS_DLL Rectangle
00052 {
00053 public:
00054
00065 Rectangle(double x1, double y1, double x2, double y2);
00066
00070 double xmin() const { return xMin; }
00071
00076 double ymin() const { return yMin; }
00077
00078
00083 double xmax() const { return xMax; }
00084
00085
00090 double ymax() const { return yMax; }
00091
00097 geom::Polygon* toPolygon(const geom::GeometryFactory &f) const;
00098
00099 geom::LinearRing* toLinearRing(const geom::GeometryFactory &f) const;
00100
00105 enum Position
00106 {
00107 Inside = 1,
00108 Outside = 2,
00109
00110 Left = 4,
00111 Top = 8,
00112 Right = 16,
00113 Bottom = 32,
00114
00115 TopLeft = Top|Left,
00116 TopRight = Top|Right,
00117 BottomLeft = Bottom|Left,
00118 BottomRight = Bottom|Right
00119 };
00120
00127 static bool onEdge(Position pos)
00128 {
00129 return (pos > Outside);
00130 }
00131
00139 static bool onSameEdge(Position pos1, Position pos2)
00140 {
00141 return onEdge(Position(pos1 & pos2));
00142 }
00143
00151 Position position(double x, double y) const
00152 {
00153
00154 if(x>xMin && x<xMax && y>yMin && y<yMax)
00155 return Inside;
00156
00157 if(x<xMin || x>xMax || y<yMin || y>yMax)
00158 return Outside;
00159
00160 unsigned int pos = 0;
00161 if(x==xMin)
00162 pos |= Left;
00163 else if(x==xMax)
00164 pos |= Right;
00165 if(y==yMin)
00166 pos |= Bottom;
00167 else if(y==yMax)
00168 pos |= Top;
00169 return Position(pos);
00170 }
00171
00178 static Position nextEdge(Position pos)
00179 {
00180 switch(pos)
00181 {
00182 case BottomLeft:
00183 case Left: return Top;
00184 case TopLeft:
00185 case Top: return Right;
00186 case TopRight:
00187 case Right: return Bottom;
00188 case BottomRight:
00189 case Bottom: return Left;
00190
00191 default: return pos;
00192 }
00193 }
00194
00195 private:
00196
00197 Rectangle();
00198 double xMin;
00199 double yMin;
00200 double xMax;
00201 double yMax;
00202
00203 };
00204
00205 }
00206 }
00207 }
00208
00209 #endif // GEOS_OP_INTERSECTION_RECTANGLE_H