GEOS  3.10.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 
69  Envelope();
70 
79  Envelope(double x1, double x2, double y1, double y2);
80 
87  Envelope(const Coordinate& p1, const Coordinate& p2);
88 
94  explicit Envelope(const Coordinate& p);
95 
100  explicit Envelope(const std::string& str);
101 
111  static bool intersects(const Coordinate& p1, const Coordinate& p2,
112  const Coordinate& q);
113 
125  static bool intersects(const Coordinate& p1, const Coordinate& p2,
126  const Coordinate& q1, const Coordinate& q2);
127 
136  bool intersects(const Coordinate& a, const Coordinate& b) const;
137 
141  void init();
142 
151  void init(double x1, double x2, double y1, double y2);
152 
159  void init(const Coordinate& p1, const Coordinate& p2);
160 
166  void init(const Coordinate& p);
167 
168  // use assignment operator instead
169  //void init(Envelope env);
170 
175  void setToNull();
176 
183  bool isNull() const;
184 
190  double getWidth() const;
191 
197  double getHeight() const;
198 
205  double
206  getArea() const
207  {
208  return getWidth() * getHeight();
209  }
210 
215  double getMaxY() const;
216 
221  double getMaxX() const;
222 
227  double getMinY() const;
228 
233  double getMinX() const;
234 
242  bool centre(Coordinate& centre) const;
243 
253  bool intersection(const Envelope& env, Envelope& result) const;
254 
261  void translate(double transX, double transY);
262 
270  void expandBy(double deltaX, double deltaY);
271 
279  void
280  expandBy(double p_distance)
281  {
282  expandBy(p_distance, p_distance);
283  }
284 
285 
292  void expandToInclude(const Coordinate& p);
293 
304  void expandToInclude(double x, double y);
305 
313  void expandToInclude(const Envelope* other);
314  void expandToInclude(const Envelope& other);
315 
328  bool
329  contains(const Envelope& other) const
330  {
331  return covers(other);
332  }
333 
334  bool
335  contains(const Envelope* other) const
336  {
337  return contains(*other);
338  }
339 
347  bool
348  contains(const Coordinate& p) const
349  {
350  return covers(p.x, p.y);
351  }
352 
363  bool
364  contains(double x, double y) const
365  {
366  return covers(x, y);
367  }
368 
375  bool intersects(const Coordinate& p) const;
376 
384  bool intersects(double x, double y) const;
385 
392  bool intersects(const Envelope* other) const;
393 
394  bool intersects(const Envelope& other) const;
395 
403  bool disjoint(const Envelope* other) const;
404 
405  bool disjoint(const Envelope& other) const;
406 
414  bool covers(double x, double y) const;
415 
422  bool covers(const Coordinate* p) const;
423 
430  bool covers(const Envelope& other) const;
431 
432  bool
433  covers(const Envelope* other) const
434  {
435  return covers(*other);
436  }
437 
438 
445  bool equals(const Envelope* other) const;
446 
452  std::string toString() const;
453 
460  double distance(const Envelope& env) const;
461 
468  double distanceSquared(const Envelope& env) const;
469 
479  static double distanceToCoordinate(const Coordinate & c, const Coordinate & p1, const Coordinate & p2);
480 
490  static double distanceSquaredToCoordinate(const Coordinate & c, const Coordinate & p1, const Coordinate & p2);
491 
492  std::size_t hashCode() const;
493 
494 private:
495 
502  static std::vector<std::string> split(const std::string& str,
503  const std::string& delimiters = " ");
504 
505  static double distance(double x0, double y0, double x1, double y1);
506 
508  double minx;
509 
511  double maxx;
512 
514  double miny;
515 
517  double maxy;
518 };
519 
521 GEOS_DLL bool operator==(const Envelope& a, const Envelope& b);
522 
523 GEOS_DLL bool operator!=(const Envelope& a, const Envelope& b);
524 
527 GEOS_DLL bool operator< (const Envelope& a, const Envelope& b);
528 
529 
530 } // namespace geos::geom
531 } // namespace geos
532 
533 #ifdef GEOS_INLINE
534 # include "geos/geom/Envelope.inl"
535 #endif
536 
537 #endif // ndef GEOS_GEOM_ENVELOPE_H
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
double getArea() const
Gets the area of this envelope.
Definition: Envelope.h:206
bool contains(const Coordinate &p) const
Returns true if the given point lies in or on the envelope.
Definition: Envelope.h:348
double y
y-coordinate
Definition: Coordinate.h:83
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
bool operator<(const Coordinate &a, const Coordinate &b)
Strict weak ordering operator for Coordinate.
Definition: Coordinate.h:140
bool contains(const Envelope &other) const
Tests if the Envelope other lies wholly inside this Envelope (inclusive of the boundary).
Definition: Envelope.h:329
std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26
bool operator!=(const Coordinate &a, const Coordinate &b)
Inequality operator for Coordinate. 2D only.
double x
x-coordinate
Definition: Coordinate.h:80
bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
bool contains(double x, double y) const
Returns true if the given point lies in or on the envelope.
Definition: Envelope.h:364
void expandBy(double p_distance)
Expands this envelope by a given distance in all directions.
Definition: Envelope.h:280