GEOS  3.3.3
Envelope.h
1 /**********************************************************************
2  * $Id: Envelope.h 3255 2011-03-01 17:56:10Z mloskot $
3  *
4  * GEOS - Geometry Engine Open Source
5  * http://geos.refractions.net
6  *
7  * Copyright (C) 2006 Refractions Research Inc.
8  *
9  * This is free software; you can redistribute and/or modify it under
10  * the terms of the GNU Lesser General Public Licence as published
11  * by the Free Software Foundation.
12  * See the COPYING file for more information.
13  *
14  **********************************************************************
15  *
16  * Last port: geom/Envelope.java rev 1.46 (JTS-1.10)
17  *
18  **********************************************************************/
19 
20 #ifndef GEOS_GEOM_ENVELOPE_H
21 #define GEOS_GEOM_ENVELOPE_H
22 
23 
24 #include <geos/export.h>
25 #include <geos/inline.h>
26 #include <geos/geom/Coordinate.h>
27 
28 #include <string>
29 #include <vector>
30 #include <memory>
31 
32 namespace geos {
33 namespace geom { // geos::geom
34 
35 class Coordinate;
36 
54 class GEOS_DLL Envelope {
55 
56 public:
57 
58  typedef std::auto_ptr<Envelope> AutoPtr;
59 
63  Envelope(void);
64 
74  Envelope(double x1, double x2, double y1, double y2);
75 
83  Envelope(const Coordinate& p1, const Coordinate& p2);
84 
90  Envelope(const Coordinate& p);
91 
93  Envelope(const Envelope &env);
94 
96  Envelope& operator=(const Envelope& e);
97 
102  Envelope(const std::string &str);
103 
104  ~Envelope(void);
105 
115  static bool intersects(const Coordinate& p1, const Coordinate& p2,
116  const Coordinate& q);
117 
129  static bool intersects(const Coordinate& p1, const Coordinate& p2,
130  const Coordinate& q1, const Coordinate& q2);
131 
135  void init(void);
136 
146  void init(double x1, double x2, double y1, double y2);
147 
155  void init(const Coordinate& p1, const Coordinate& p2);
156 
163  void init(const Coordinate& p);
164 
165  // use assignment operator instead
166  //void init(Envelope env);
167 
172  void setToNull(void);
173 
182  bool isNull(void) const;
183 
189  double getWidth(void) const;
190 
196  double getHeight(void) const;
197 
204  double getArea() const
205  {
206  return getWidth() * getHeight();
207  }
208 
213  double getMaxY() const;
214 
219  double getMaxX() const;
220 
225  double getMinY() const;
226 
231  double getMinX() const;
232 
241  bool centre(Coordinate& centre) const;
242 
252  bool intersection(const Envelope& env, Envelope& result) const;
253 
260  void translate(double transX, double transY);
261 
271  void expandBy(double deltaX, double deltaY);
272 
280  void expandBy(double distance) { expandBy(distance, distance); }
281 
282 
289  void expandToInclude(const Coordinate& p);
290 
300  void expandToInclude(double x, double y);
301 
309  void expandToInclude(const Envelope* other);
310 
324  bool contains(const Envelope& other) const {
325  return covers(other);
326  }
327 
328  bool contains(const Envelope* other) const {
329  return contains(*other);
330  }
331 
341  bool contains(const Coordinate& p) const {
342  return covers(p.x, p.y);
343  }
344 
360  bool contains(double x, double y) const {
361  return covers(x, y);
362  }
363 
371  bool intersects(const Coordinate& p) const;
372 
381  bool intersects(double x, double y) const;
382 
392  bool intersects(const Envelope* other) const;
393 
394  bool intersects(const Envelope& other) const;
395 
406  bool covers(double x, double y) const;
407 
416  bool covers(const Coordinate *p) const;
417 
426  bool covers(const Envelope& other) const;
427 
428  bool covers(const Envelope* other) const {
429  return covers(*other);
430  }
431 
432 
443  bool equals(const Envelope* other) const;
444 
452  std::string toString(void) const;
453 
461  double distance(const Envelope* env) const;
462 
463  int hashCode() const;
464 
465 private:
466 
473  std::vector<std::string> split(const std::string &str,
474  const std::string &delimiters = " ");
475 
476  static double distance(double x0,double y0,double x1,double y1);
477 
479  double minx;
480 
482  double maxx;
483 
485  double miny;
486 
488  double maxy;
489 };
490 
492 GEOS_DLL bool operator==(const Envelope& a, const Envelope& b);
493 
494 } // namespace geos::geom
495 } // namespace geos
496 
497 #ifdef GEOS_INLINE
498 # include "geos/geom/Envelope.inl"
499 #endif
500 
501 #endif // ndef GEOS_GEOM_ENVELOPE_H
502 
503 /**********************************************************************
504  * $Log$
505  * Revision 1.4 2006/04/10 18:15:09 strk
506  * Changed Geometry::envelope member to be of type auto_ptr<Envelope>.
507  * Changed computeEnvelopeInternal() signater to return auto_ptr<Envelope>
508  *
509  * Revision 1.3 2006/04/05 14:04:25 strk
510  * Fixed copy ctor to support "Null" Envelope copies.
511  * Drop init(Envelope&) method.
512  * Port info and various cleanups.
513  *
514  * Revision 1.2 2006/03/24 09:52:41 strk
515  * USE_INLINE => GEOS_INLINE
516  *
517  * Revision 1.1 2006/03/09 16:46:49 strk
518  * geos::geom namespace definition, first pass at headers split
519  *
520  **********************************************************************/