GEOS
3.6.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2014 Mika Heiskanen <mika.heiskanen@fmi.fi> 00007 * 00008 * This is free software; you can redistribute and/or modify it under 00009 * the terms of the GNU Lesser General Public Licence as published 00010 * by the Free Software Foundation. 00011 * See the COPYING file for more information. 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 // Forward declarations 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 { // geos::operation 00037 namespace intersection { // geos::operation::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, // 12 00116 TopRight = Top|Right, // 24 00117 BottomLeft = Bottom|Left, // 36 00118 BottomRight = Bottom|Right // 48 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 // We assume the point to be inside and test it first 00154 if(x>xMin && x<xMax && y>yMin && y<yMax) 00155 return Inside; 00156 // Next we assume the point to be outside and test it next 00157 if(x<xMin || x>xMax || y<yMin || y>yMax) 00158 return Outside; 00159 // Slower cases 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 /* silences compiler warnings, Inside & Outside are not handled explicitly */ 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 }; // class RectangleIntersection 00204 00205 } // namespace geos::operation::intersection 00206 } // namespace geos::operation 00207 } // namespace geos 00208 00209 #endif // GEOS_OP_INTERSECTION_RECTANGLE_H