GEOS  3.9.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.
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  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
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
333  bool
334  contains(const Envelope& other) const
335  {
336  return covers(other);
337  }
338
339  bool
340  contains(const Envelope* other) const
341  {
342  return contains(*other);
343  }
344
352  bool
353  contains(const Coordinate& p) const
354  {
355  return covers(p.x, p.y);
356  }
357
368  bool
369  contains(double x, double y) const
370  {
371  return covers(x, y);
372  }
373
380  bool intersects(const Coordinate& p) const;
381
389  bool intersects(double x, double y) const;
390
397  bool intersects(const Envelope* other) const;
398
399  bool intersects(const Envelope& other) const;
400
408  bool disjoint(const Envelope* other) const;
409
410  bool disjoint(const Envelope& other) const;
411
419  bool covers(double x, double y) const;
420
427  bool covers(const Coordinate* p) const;
428
435  bool covers(const Envelope& other) const;
436
437  bool
438  covers(const Envelope* other) const
439  {
440  return covers(*other);
441  }
442
443
450  bool equals(const Envelope* other) const;
451
457  std::string toString(void) const;
458
465  double distance(const Envelope& env) const;
466
473  double distanceSquared(const Envelope& env) const;
474
484  static double distanceToCoordinate(const Coordinate & c, const Coordinate & p1, const Coordinate & p2);
485
495  static double distanceSquaredToCoordinate(const Coordinate & c, const Coordinate & p1, const Coordinate & p2);
496
497  size_t hashCode() const;
498
499 private:
500
507  std::vector<std::string> split(const std::string& str,
508  const std::string& delimiters = " ");
509
510  static double distance(double x0, double y0, double x1, double y1);
511
513  double minx;
514
516  double maxx;
517
519  double miny;
520
522  double maxy;
523 };
524
526 GEOS_DLL bool operator==(const Envelope& a, const Envelope& b);
527
528 } // namespace geos::geom
529 } // namespace geos
530
531 #ifdef GEOS_INLINE
532 # include "geos/geom/Envelope.inl"
533 #endif
534
535 #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:334
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
bool contains(const Coordinate &p) const
Returns true if the given point lies in or on the envelope.
Definition: Envelope.h:353
double getArea() const
Gets the area of this envelope.
Definition: Envelope.h:212
bool contains(double x, double y) const
Returns true if the given point lies in or on the envelope.
Definition: Envelope.h:369
std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26
double x
x-coordinate
Definition: Coordinate.h:80
bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
void expandBy(double p_distance)
Expands this envelope by a given distance in all directions.
Definition: Envelope.h:286