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 
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(void);
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 
100  Envelope& operator=(const Envelope& e);
101 
106  Envelope(const std::string& str);
107 
108  ~Envelope(void);
109 
119  static bool intersects(const Coordinate& p1, const Coordinate& p2,
120  const Coordinate& q);
121 
133  static bool intersects(const Coordinate& p1, const Coordinate& p2,
134  const Coordinate& q1, const Coordinate& q2);
135 
144  bool intersects(const Coordinate& a, const Coordinate& b) const;
145 
149  void init(void);
150 
159  void init(double x1, double x2, double y1, double y2);
160 
167  void init(const Coordinate& p1, const Coordinate& p2);
168 
174  void init(const Coordinate& p);
175 
176  // use assignment operator instead
177  //void init(Envelope env);
178 
183  void setToNull(void);
184 
191  bool isNull(void) const;
192 
198  double getWidth(void) const;
199 
205  double getHeight(void) const;
206 
213  double
214  getArea() const
215  {
216  return getWidth() * getHeight();
217  }
218 
223  double getMaxY() const;
224 
229  double getMaxX() const;
230 
235  double getMinY() const;
236 
241  double getMinX() const;
242 
250  bool centre(Coordinate& centre) const;
251 
261  bool intersection(const Envelope& env, Envelope& result) const;
262 
269  void translate(double transX, double transY);
270 
278  void expandBy(double deltaX, double deltaY);
279 
287  void
288  expandBy(double p_distance)
289  {
290  expandBy(p_distance, p_distance);
291  }
292 
293 
300  void expandToInclude(const Coordinate& p);
301 
312  void expandToInclude(double x, double y);
313 
321  void expandToInclude(const Envelope* other);
322 
335  bool
336  contains(const Envelope& other) const
337  {
338  return covers(other);
339  }
340 
341  bool
342  contains(const Envelope* other) const
343  {
344  return contains(*other);
345  }
346 
354  bool
355  contains(const Coordinate& p) const
356  {
357  return covers(p.x, p.y);
358  }
359 
370  bool
371  contains(double x, double y) const
372  {
373  return covers(x, y);
374  }
375 
382  bool intersects(const Coordinate& p) const;
383 
391  bool intersects(double x, double y) const;
392 
399  bool intersects(const Envelope* other) const;
400 
401  bool intersects(const Envelope& other) const;
402 
410  bool covers(double x, double y) const;
411 
418  bool covers(const Coordinate* p) const;
419 
426  bool covers(const Envelope& other) const;
427 
428  bool
429  covers(const Envelope* other) const
430  {
431  return covers(*other);
432  }
433 
434 
441  bool equals(const Envelope* other) const;
442 
448  std::string toString(void) const;
449 
456  double distance(const Envelope* env) const;
457 
458  int hashCode() const;
459 
460 private:
461 
468  std::vector<std::string> split(const std::string& str,
469  const std::string& delimiters = " ");
470 
471  static double distance(double x0, double y0, double x1, double y1);
472 
474  double minx;
475 
477  double maxx;
478 
480  double miny;
481 
483  double maxy;
484 };
485 
487 GEOS_DLL bool operator==(const Envelope& a, const Envelope& b);
488 
489 } // namespace geos::geom
490 } // namespace geos
491 
492 #ifdef GEOS_INLINE
493 # include "geos/geom/Envelope.inl"
494 #endif
495 
496 #endif // ndef GEOS_GEOM_ENVELOPE_H
bool contains(const Envelope &other) const
Tests if the Envelope other lies wholly inside this Envelope (inclusive of the boundary).
Definition: Envelope.h:336
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
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:355
double getArea() const
Gets the area of this envelope.
Definition: Envelope.h:214
bool contains(double x, double y) const
Returns true if the given point lies in or on the envelope.
Definition: Envelope.h:371
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.
Definition: Envelope.h:288