GEOS
3.4.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2006 Refractions Research Inc. 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 * Last port: geom/Envelope.java rev 1.46 (JTS-1.10) 00016 * 00017 **********************************************************************/ 00018 00019 #ifndef GEOS_GEOM_ENVELOPE_H 00020 #define GEOS_GEOM_ENVELOPE_H 00021 00022 00023 #include <geos/export.h> 00024 #include <geos/inline.h> 00025 #include <geos/geom/Coordinate.h> 00026 00027 #include <string> 00028 #include <vector> 00029 #include <memory> 00030 00031 namespace geos { 00032 namespace geom { // geos::geom 00033 00034 class Coordinate; 00035 00053 class GEOS_DLL Envelope { 00054 00055 public: 00056 00057 typedef std::auto_ptr<Envelope> AutoPtr; 00058 00062 Envelope(void); 00063 00073 Envelope(double x1, double x2, double y1, double y2); 00074 00082 Envelope(const Coordinate& p1, const Coordinate& p2); 00083 00089 Envelope(const Coordinate& p); 00090 00092 Envelope(const Envelope &env); 00093 00095 Envelope& operator=(const Envelope& e); 00096 00101 Envelope(const std::string &str); 00102 00103 ~Envelope(void); 00104 00114 static bool intersects(const Coordinate& p1, const Coordinate& p2, 00115 const Coordinate& q); 00116 00128 static bool intersects(const Coordinate& p1, const Coordinate& p2, 00129 const Coordinate& q1, const Coordinate& q2); 00130 00134 void init(void); 00135 00145 void init(double x1, double x2, double y1, double y2); 00146 00154 void init(const Coordinate& p1, const Coordinate& p2); 00155 00162 void init(const Coordinate& p); 00163 00164 // use assignment operator instead 00165 //void init(Envelope env); 00166 00171 void setToNull(void); 00172 00181 bool isNull(void) const; 00182 00188 double getWidth(void) const; 00189 00195 double getHeight(void) const; 00196 00203 double getArea() const 00204 { 00205 return getWidth() * getHeight(); 00206 } 00207 00212 double getMaxY() const; 00213 00218 double getMaxX() const; 00219 00224 double getMinY() const; 00225 00230 double getMinX() const; 00231 00240 bool centre(Coordinate& centre) const; 00241 00251 bool intersection(const Envelope& env, Envelope& result) const; 00252 00259 void translate(double transX, double transY); 00260 00270 void expandBy(double deltaX, double deltaY); 00271 00279 void expandBy(double distance) { expandBy(distance, distance); } 00280 00281 00288 void expandToInclude(const Coordinate& p); 00289 00299 void expandToInclude(double x, double y); 00300 00308 void expandToInclude(const Envelope* other); 00309 00323 bool contains(const Envelope& other) const { 00324 return covers(other); 00325 } 00326 00327 bool contains(const Envelope* other) const { 00328 return contains(*other); 00329 } 00330 00340 bool contains(const Coordinate& p) const { 00341 return covers(p.x, p.y); 00342 } 00343 00359 bool contains(double x, double y) const { 00360 return covers(x, y); 00361 } 00362 00370 bool intersects(const Coordinate& p) const; 00371 00380 bool intersects(double x, double y) const; 00381 00391 bool intersects(const Envelope* other) const; 00392 00393 bool intersects(const Envelope& other) const; 00394 00405 bool covers(double x, double y) const; 00406 00415 bool covers(const Coordinate *p) const; 00416 00425 bool covers(const Envelope& other) const; 00426 00427 bool covers(const Envelope* other) const { 00428 return covers(*other); 00429 } 00430 00431 00442 bool equals(const Envelope* other) const; 00443 00451 std::string toString(void) const; 00452 00460 double distance(const Envelope* env) const; 00461 00462 int hashCode() const; 00463 00464 private: 00465 00472 std::vector<std::string> split(const std::string &str, 00473 const std::string &delimiters = " "); 00474 00475 static double distance(double x0,double y0,double x1,double y1); 00476 00478 double minx; 00479 00481 double maxx; 00482 00484 double miny; 00485 00487 double maxy; 00488 }; 00489 00491 GEOS_DLL bool operator==(const Envelope& a, const Envelope& b); 00492 00493 } // namespace geos::geom 00494 } // namespace geos 00495 00496 #ifdef GEOS_INLINE 00497 # include "geos/geom/Envelope.inl" 00498 #endif 00499 00500 #endif // ndef GEOS_GEOM_ENVELOPE_H