GEOS  3.7.2
Envelope.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  * Last port: geom/Envelope.java rev 1.46 (JTS-1.10)
16  *
17  **********************************************************************/
18 
19 #ifndef GEOS_GEOM_ENVELOPE_H
20 #define GEOS_GEOM_ENVELOPE_H
21 
22 
23 #include <geos/export.h>
24 #include <geos/inline.h>
25 #include <geos/geom/Coordinate.h>
26 
27 #include <string>
28 #include <vector>
29 #include <ostream> // for operator<<
30 #include <memory>
31 
32 namespace geos {
33 namespace geom { // geos::geom
34 
35 class Envelope;
36 
38 GEOS_DLL std::ostream& operator<< (std::ostream& os, const Envelope& o);
39 
40 class Coordinate;
41 
59 class GEOS_DLL Envelope {
60 
61 public:
62 
63  friend std::ostream& operator<< (std::ostream& os, const Envelope& o);
64 
65  typedef std::unique_ptr<Envelope> Ptr;
66 
70  Envelope(void);
71 
81  Envelope(double x1, double x2, double y1, double y2);
82 
90  Envelope(const Coordinate& p1, const Coordinate& p2);
91 
97  Envelope(const Coordinate& p);
98 
100  Envelope(const Envelope &env);
101 
104 
109  Envelope(const std::string &str);
110 
111  ~Envelope(void);
112 
122  static bool intersects(const Coordinate& p1, const Coordinate& p2,
123  const Coordinate& q);
124 
136  static bool intersects(const Coordinate& p1, const Coordinate& p2,
137  const Coordinate& q1, const Coordinate& q2);
138 
142  void init(void);
143 
153  void init(double x1, double x2, double y1, double y2);
154 
162  void init(const Coordinate& p1, const Coordinate& p2);
163 
170  void init(const Coordinate& p);
171 
172  // use assignment operator instead
173  //void init(Envelope env);
174 
179  void setToNull(void);
180 
189  bool isNull(void) const;
190 
196  double getWidth(void) const;
197 
203  double getHeight(void) const;
204 
211  double getArea() const
212  {
213  return getWidth() * getHeight();
214  }
215 
220  double getMaxY() const;
221 
226  double getMaxX() const;
227 
232  double getMinY() const;
233 
238  double getMinX() const;
239 
248  bool centre(Coordinate& centre) const;
249 
259  bool intersection(const Envelope& env, Envelope& result) const;
260 
267  void translate(double transX, double transY);
268 
278  void expandBy(double deltaX, double deltaY);
279 
287  void expandBy(double distance) { expandBy(distance, distance); }
288 
289 
296  void expandToInclude(const Coordinate& p);
297 
307  void expandToInclude(double x, double y);
308 
316  void expandToInclude(const Envelope* other);
317 
331  bool contains(const Envelope& other) const {
332  return covers(other);
333  }
334 
335  bool contains(const Envelope* other) const {
336  return contains(*other);
337  }
338 
348  bool contains(const Coordinate& p) const {
349  return covers(p.x, p.y);
350  }
351 
367  bool contains(double x, double y) const {
368  return covers(x, y);
369  }
370 
378  bool intersects(const Coordinate& p) const;
379 
388  bool intersects(double x, double y) const;
389 
399  bool intersects(const Envelope* other) const;
400 
401  bool intersects(const Envelope& other) const;
402 
413  bool covers(double x, double y) const;
414 
423  bool covers(const Coordinate *p) const;
424 
433  bool covers(const Envelope& other) const;
434 
435  bool covers(const Envelope* other) const {
436  return covers(*other);
437  }
438 
439 
450  bool equals(const Envelope* other) const;
451 
459  std::string toString(void) const;
460 
468  double distance(const Envelope* env) const;
469 
470  int hashCode() const;
471 
472 private:
473 
480  std::vector<std::string> split(const std::string &str,
481  const std::string &delimiters = " ");
482 
483  static double distance(double x0,double y0,double x1,double y1);
484 
486  double minx;
487 
489  double maxx;
490 
492  double miny;
493 
495  double maxy;
496 };
497 
499 GEOS_DLL bool operator==(const Envelope& a, const Envelope& b);
500 
501 } // namespace geos::geom
502 } // namespace geos
503 
504 #ifdef GEOS_INLINE
505 # include "geos/geom/Envelope.inl"
506 #endif
507 
508 #endif // ndef GEOS_GEOM_ENVELOPE_H
geos::geom::Envelope::getMaxY
double getMaxY() const
geos::geom::Envelope::translate
void translate(double transX, double transY)
Translates this envelope by given amounts in the X and Y direction.
geos::geom::Envelope::operator=
Envelope & operator=(const Envelope &e)
Assignment operator.
geos::geom::Envelope::Envelope
Envelope(void)
Creates a null Envelope.
geos::geom::Envelope::intersects
bool intersects(const Envelope *other) const
geos::geom::Envelope::expandBy
void expandBy(double deltaX, double deltaY)
Expands this envelope by a given distance in all directions. Both positive and negative distances are...
geos
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
geos::geom::operator==
GEOS_DLL bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
geos::geom::Envelope::init
void init(const Coordinate &p)
Initialize an Envelope to a region defined by a single Coordinate.
geos::geom::Envelope::Envelope
Envelope(const Coordinate &p)
Creates an Envelope for a region defined by a single Coordinate.
geos::geom::Envelope::expandToInclude
void expandToInclude(const Envelope *other)
Enlarges the boundary of the Envelope so that it contains other. Does nothing if other is wholly on o...
geos::geom::Coordinate::y
double y
y-coordinate
Definition: Coordinate.h:83
geos::geom::Envelope::intersection
bool intersection(const Envelope &env, Envelope &result) const
geos::geom::Envelope::Envelope
Envelope(double x1, double x2, double y1, double y2)
Creates an Envelope for a region defined by maximum and minimum values.
geos::geom::Envelope::contains
bool contains(const Envelope &other) const
Tests if the Envelope other lies wholely inside this Envelope (inclusive of the boundary).
Definition: Envelope.h:331
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
geos::geom::Envelope::expandToInclude
void expandToInclude(const Coordinate &p)
Enlarges the boundary of the Envelope so that it contains p. Does nothing if p is already on or withi...
geos::geom::Envelope::Envelope
Envelope(const Coordinate &p1, const Coordinate &p2)
Creates an Envelope for a region defined by two Coordinates.
geos::geom::Envelope::centre
bool centre(Coordinate &centre) const
geos::geom::Envelope::Envelope
Envelope(const std::string &str)
Create an Envelope from an Envelope string representation produced by Envelope.toString()
geos::geom::Envelope::intersects
bool intersects(const Coordinate &p) const
geos::geom::Envelope::getWidth
double getWidth(void) const
Returns the difference between the maximum and minimum x values.
geos::geom::Envelope::distance
double distance(const Envelope *env) const
Computes the distance between this and another Envelope.
geos::geom::Envelope::toString
std::string toString(void) const
Returns a string of the form Env[minx:maxx,miny:maxy] .
geos::geom::Envelope::init
void init(const Coordinate &p1, const Coordinate &p2)
Initialize an Envelope to a region defined by two Coordinates.
geos::geom::Envelope::contains
bool contains(double x, double y) const
Returns true if the given point lies in or on the envelope.
Definition: Envelope.h:367
geos::geom::Envelope::intersects
static bool intersects(const Coordinate &p1, const Coordinate &p2, const Coordinate &q1, const Coordinate &q2)
Test the envelope defined by p1-p2 for intersection with the envelope defined by q1-q2.
geos::geom::Coordinate::x
double x
x-coordinate
Definition: Coordinate.h:80
geos::geom::Envelope::covers
bool covers(const Envelope &other) const
geos::geom::Envelope::getArea
double getArea() const
Definition: Envelope.h:211
geos::geom::operator<<
GEOS_DLL std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
geos::geom::Envelope::expandBy
void expandBy(double distance)
Expands this envelope by a given distance in all directions. Both positive and negative distances are...
Definition: Envelope.h:287
geos::geom::Envelope::getMaxX
double getMaxX() const
geos::geom::Envelope::getHeight
double getHeight(void) const
Returns the difference between the maximum and minimum y values.
geos::geom::Envelope::equals
bool equals(const Envelope *other) const
Returns true if the Envelope other spatially equals this Envelope.
geos::geom::Envelope::covers
bool covers(double x, double y) const
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
geos::geom::Envelope::intersects
bool intersects(double x, double y) const
geos::geom::Envelope::init
void init(double x1, double x2, double y1, double y2)
Initialize an Envelope for a region defined by maximum and minimum values.
geos::geom::Envelope::covers
bool covers(const Coordinate *p) const
geos::geom::Envelope::getMinY
double getMinY() const
geos::geom::Envelope::isNull
bool isNull(void) const
Returns true if this Envelope is a "null" envelope.
geos::geom::Envelope::intersects
static bool intersects(const Coordinate &p1, const Coordinate &p2, const Coordinate &q)
Test the point q to see whether it intersects the Envelope defined by p1-p2.
geos::geom::Envelope::getMinX
double getMinX() const
geos::geom::Envelope::contains
bool contains(const Coordinate &p) const
Returns true if the given point lies in or on the envelope.
Definition: Envelope.h:348
geos::geom::Envelope::setToNull
void setToNull(void)
Makes this Envelope a "null" envelope, that is, the envelope of the empty geometry.
geos::geom::Envelope::expandToInclude
void expandToInclude(double x, double y)
Enlarges the boundary of the Envelope so that it contains (x,y). Does nothing if (x,...
geos::geom::Envelope::init
void init(void)
Initialize to a null Envelope.
geos::geom::Envelope::Envelope
Envelope(const Envelope &env)
Copy constructor.