GEOS  3.8.0dev
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 
103  Envelope& operator=(const Envelope& e);
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 
147  bool intersects(const Coordinate& a, const Coordinate& b) const;
148 
152  void init(void);
153 
163  void init(double x1, double x2, double y1, double y2);
164 
172  void init(const Coordinate& p1, const Coordinate& p2);
173 
180  void init(const Coordinate& p);
181 
182  // use assignment operator instead
183  //void init(Envelope env);
184 
189  void setToNull(void);
190 
199  bool isNull(void) const;
200 
206  double getWidth(void) const;
207 
213  double getHeight(void) const;
214 
221  double
222  getArea() const
223  {
224  return getWidth() * getHeight();
225  }
226 
231  double getMaxY() const;
232 
237  double getMaxX() const;
238 
243  double getMinY() const;
244 
249  double getMinX() const;
250 
259  bool centre(Coordinate& centre) const;
260 
270  bool intersection(const Envelope& env, Envelope& result) const;
271 
278  void translate(double transX, double transY);
279 
289  void expandBy(double deltaX, double deltaY);
290 
298  void
299  expandBy(double p_distance)
300  {
301  expandBy(p_distance, p_distance);
302  }
303 
304 
311  void expandToInclude(const Coordinate& p);
312 
322  void expandToInclude(double x, double y);
323 
331  void expandToInclude(const Envelope* other);
332 
346  bool
347  contains(const Envelope& other) const
348  {
349  return covers(other);
350  }
351 
352  bool
353  contains(const Envelope* other) const
354  {
355  return contains(*other);
356  }
357 
367  bool
368  contains(const Coordinate& p) const
369  {
370  return covers(p.x, p.y);
371  }
372 
388  bool
389  contains(double x, double y) const
390  {
391  return covers(x, y);
392  }
393 
401  bool intersects(const Coordinate& p) const;
402 
411  bool intersects(double x, double y) const;
412 
422  bool intersects(const Envelope* other) const;
423 
424  bool intersects(const Envelope& other) const;
425 
436  bool covers(double x, double y) const;
437 
446  bool covers(const Coordinate* p) const;
447 
456  bool covers(const Envelope& other) const;
457 
458  bool
459  covers(const Envelope* other) const
460  {
461  return covers(*other);
462  }
463 
464 
475  bool equals(const Envelope* other) const;
476 
484  std::string toString(void) const;
485 
493  double distance(const Envelope* env) const;
494 
495  int hashCode() const;
496 
497 private:
498 
505  std::vector<std::string> split(const std::string& str,
506  const std::string& delimiters = " ");
507 
508  static double distance(double x0, double y0, double x1, double y1);
509 
511  double minx;
512 
514  double maxx;
515 
517  double miny;
518 
520  double maxy;
521 };
522 
524 GEOS_DLL bool operator==(const Envelope& a, const Envelope& b);
525 
526 } // namespace geos::geom
527 } // namespace geos
528 
529 #ifdef GEOS_INLINE
530 # include "geos/geom/Envelope.inl"
531 #endif
532 
533 #endif // ndef GEOS_GEOM_ENVELOPE_H
bool contains(const Envelope &other) const
Tests if the Envelope other lies wholely inside this Envelope (inclusive of the boundary).
Definition: Envelope.h:347
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
double y
y-coordinate
Definition: Coordinate.h:83
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
GEOS_DLL std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
bool contains(const Coordinate &p) const
Returns true if the given point lies in or on the envelope.
Definition: Envelope.h:368
double getArea() const
Definition: Envelope.h:222
bool contains(double x, double y) const
Returns true if the given point lies in or on the envelope.
Definition: Envelope.h:389
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
GEOS_DLL bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
double x
x-coordinate
Definition: Coordinate.h:80
void expandBy(double p_distance)
Expands this envelope by a given distance in all directions. Both positive and negative distances are...
Definition: Envelope.h:299