GEOS  3.9.1
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 
58 class GEOS_DLL Envelope {
59 
60 public:
61 
62  friend std::ostream& operator<< (std::ostream& os, const Envelope& o);
63 
64  typedef std::unique_ptr<Envelope> Ptr;
65 
70 
79  Envelope(double x1, double x2, double y1, double y2);
80 
87  Envelope(const Coordinate& p1, const Coordinate& p2);
88 
94  Envelope(const Coordinate& p);
95 
97  Envelope(const Envelope& env);
98 
101 
106  Envelope(const std::string& str);
107 
117  static bool intersects(const Coordinate& p1, const Coordinate& p2,
118  const Coordinate& q);
119 
131  static bool intersects(const Coordinate& p1, const Coordinate& p2,
132  const Coordinate& q1, const Coordinate& q2);
133 
142  bool intersects(const Coordinate& a, const Coordinate& b) const;
143 
147  void init(void);
148 
157  void init(double x1, double x2, double y1, double y2);
158 
165  void init(const Coordinate& p1, const Coordinate& p2);
166 
172  void init(const Coordinate& p);
173 
174  // use assignment operator instead
175  //void init(Envelope env);
176 
181  void setToNull(void);
182 
189  bool isNull(void) const;
190 
196  double getWidth(void) const;
197 
203  double getHeight(void) const;
204 
211  double
212  getArea() const
213  {
214  return getWidth() * getHeight();
215  }
216 
221  double getMaxY() const;
222 
227  double getMaxX() const;
228 
233  double getMinY() const;
234 
239  double getMinX() const;
240 
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 
276  void expandBy(double deltaX, double deltaY);
277 
285  void
286  expandBy(double p_distance)
287  {
288  expandBy(p_distance, p_distance);
289  }
290 
291 
298  void expandToInclude(const Coordinate& p);
299 
310  void expandToInclude(double x, double y);
311 
319  void expandToInclude(const Envelope* other);
320  void expandToInclude(const Envelope& other);
321 
334  bool
335  contains(const Envelope& other) const
336  {
337  return covers(other);
338  }
339 
340  bool
341  contains(const Envelope* other) const
342  {
343  return contains(*other);
344  }
345 
353  bool
354  contains(const Coordinate& p) const
355  {
356  return covers(p.x, p.y);
357  }
358 
369  bool
370  contains(double x, double y) const
371  {
372  return covers(x, y);
373  }
374 
381  bool intersects(const Coordinate& p) const;
382 
390  bool intersects(double x, double y) const;
391 
398  bool intersects(const Envelope* other) const;
399 
400  bool intersects(const Envelope& other) const;
401 
409  bool disjoint(const Envelope* other) const;
410 
411  bool disjoint(const Envelope& other) const;
412 
420  bool covers(double x, double y) const;
421 
428  bool covers(const Coordinate* p) const;
429 
436  bool covers(const Envelope& other) const;
437 
438  bool
439  covers(const Envelope* other) const
440  {
441  return covers(*other);
442  }
443 
444 
451  bool equals(const Envelope* other) const;
452 
458  std::string toString(void) const;
459 
466  double distance(const Envelope& env) const;
467 
474  double distanceSquared(const Envelope& env) const;
475 
485  static double distanceToCoordinate(const Coordinate & c, const Coordinate & p1, const Coordinate & p2);
486 
496  static double distanceSquaredToCoordinate(const Coordinate & c, const Coordinate & p1, const Coordinate & p2);
497 
498  size_t hashCode() const;
499 
500 private:
501 
508  std::vector<std::string> split(const std::string& str,
509  const std::string& delimiters = " ");
510 
511  static double distance(double x0, double y0, double x1, double y1);
512 
514  double minx;
515 
517  double maxx;
518 
520  double miny;
521 
523  double maxy;
524 };
525 
527 GEOS_DLL bool operator==(const Envelope& a, const Envelope& b);
528 
529 } // namespace geos::geom
530 } // namespace geos
531 
532 #ifdef GEOS_INLINE
533 # include "geos/geom/Envelope.inl"
534 #endif
535 
536 #endif // ndef GEOS_GEOM_ENVELOPE_H
geos::geom::Envelope::distance
double distance(const Envelope &env) const
Computes the distance between this and another Envelope.
geos::geom::Envelope::getMaxY
double getMaxY() const
Returns the Envelope maximum y-value. min y > max y indicates that this is a null Envelope.
geos::geom::Envelope::translate
void translate(double transX, double transY)
Translates this envelope by given amounts in the X and Y direction.
geos::geom::operator<<
std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
geos::geom::Envelope::operator=
Envelope & operator=(const Envelope &e)
Assignment operator.
geos::geom::Envelope::intersects
bool intersects(const Envelope *other) const
Check if the region defined by other Envelope intersects the region of this Envelope.
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:26
geos::geom::Envelope::intersects
bool intersects(const Coordinate &a, const Coordinate &b) const
Check if the extent defined by two extremal points intersects the extent of this Envelope.
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.
geos::geom::operator==
bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
geos::geom::Envelope::distanceSquaredToCoordinate
static double distanceSquaredToCoordinate(const Coordinate &c, const Coordinate &p1, const Coordinate &p2)
Computes the squared distance between one Coordinate and an Envelope defined by two other Coordinates...
geos::geom::Coordinate::y
double y
y-coordinate
Definition: Coordinate.h:83
geos::geom::Envelope::intersection
bool intersection(const Envelope &env, Envelope &result) const
Computes the intersection of two Envelopes.
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::distanceSquared
double distanceSquared(const Envelope &env) const
Computes the square of the distance between this and another Envelope.
geos::geom::Envelope::contains
bool contains(const Envelope &other) const
Tests if the Envelope other lies wholly inside this Envelope (inclusive of the boundary).
Definition: Envelope.h:335
geos::geom::Envelope::Envelope
Envelope()
Creates a null Envelope.
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
Computes the coordinate of the centre of this envelope (as long as it is non-null).
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
Check if the point p intersects (lies inside) the region of this Envelope.
geos::geom::Envelope::getWidth
double getWidth(void) const
Returns the difference between the maximum and minimum x values.
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:370
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
Tests if the Envelope other lies wholly inside this Envelope (inclusive of the boundary).
geos::geom::Envelope::getArea
double getArea() const
Gets the area of this envelope.
Definition: Envelope.h:212
geos::geom::Envelope::expandBy
void expandBy(double p_distance)
Expands this envelope by a given distance in all directions.
Definition: Envelope.h:286
geos::geom::Envelope::getMaxX
double getMaxX() const
Returns the Envelope maximum x-value. min x > max x indicates that this is a null Envelope.
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::disjoint
bool disjoint(const Envelope *other) const
geos::geom::Envelope::distanceToCoordinate
static double distanceToCoordinate(const Coordinate &c, const Coordinate &p1, const Coordinate &p2)
Computes the distance between one Coordinate and an Envelope defined by two other Coordinates....
geos::geom::Envelope::covers
bool covers(double x, double y) const
Tests if the given point lies in or on the envelope.
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
geos::geom::Envelope::intersects
bool intersects(double x, double y) const
Check if the point (x, y) intersects (lies inside) the region of this Envelope.
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
Tests if the given point lies in or on the envelope.
geos::geom::Envelope::getMinY
double getMinY() const
Returns the Envelope minimum y-value. min y > max y indicates that this is a null Envelope.
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
Returns the Envelope minimum x-value. min x > max x indicates that this is a null Envelope.
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:354
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).
geos::geom::Envelope::init
void init(void)
Initialize to a null Envelope.
geos::geom::Envelope::Envelope
Envelope(const Envelope &env)
Copy constructor.