GEOS  3.10.1
Coordinate.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 #ifndef GEOS_GEOM_COORDINATE_H
16 #define GEOS_GEOM_COORDINATE_H
17 
18 #include <geos/export.h>
19 #include <geos/constants.h> // for DoubleNotANumber
20 #include <geos/inline.h>
21 #include <set>
22 #include <stack>
23 #include <vector> // for typedefs
24 #include <string>
25 #include <limits>
26 
27 #ifdef _MSC_VER
28 #pragma warning(push)
29 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
30 #endif
31 
32 namespace geos {
33 namespace geom { // geos.geom
34 
35 struct CoordinateLessThen;
36 
57 // Define the following to make assignments and copy constructions
58 // NON-inline (will let profilers report usages)
59 //#define PROFILE_COORDINATE_COPIES 1
60 class GEOS_DLL Coordinate {
61 
62 private:
63 
64  static Coordinate _nullCoord;
65 
66 public:
68  typedef std::set<const Coordinate*, CoordinateLessThen> ConstSet;
69 
71  typedef std::vector<const Coordinate*> ConstVect;
72 
74  typedef std::stack<const Coordinate*> ConstStack;
75 
77  typedef std::vector<Coordinate> Vect;
78 
80  double x;
81 
83  double y;
84 
86  double z;
87 
88  void setNull();
89 
90  static Coordinate& getNull();
91 
92  bool isNull() const;
93 
94  bool isValid() const;
95 
96  Coordinate();
97 
98  Coordinate(double xNew, double yNew, double zNew = DoubleNotANumber);
99 
100  bool equals2D(const Coordinate& other) const;
101 
102  bool equals2D(const Coordinate& other, double tolerance) const;
103 
105  bool equals(const Coordinate& other) const;
106 
108  int compareTo(const Coordinate& other) const;
109 
111  bool equals3D(const Coordinate& other) const;
112 
114  std::string toString() const;
115 
118  //void makePrecise(const PrecisionModel *pm);
119 
120  double distance(const Coordinate& p) const;
121 
122  double distanceSquared(const Coordinate& p) const;
123 
124  struct GEOS_DLL HashCode {
125  std::size_t operator()(const Coordinate & c) const;
126  };
127 
128 };
129 
131 struct GEOS_DLL CoordinateLessThen {
132 
133  bool operator()(const Coordinate* a, const Coordinate* b) const;
134  bool operator()(const Coordinate& a, const Coordinate& b) const;
135 
136 };
137 
139 inline bool
140 operator<(const Coordinate& a, const Coordinate& b)
141 {
142  return CoordinateLessThen()(a, b);
143 }
144 
146 GEOS_DLL std::ostream& operator<< (std::ostream& os, const Coordinate& c);
147 
149 GEOS_DLL bool operator==(const Coordinate& a, const Coordinate& b);
150 
152 GEOS_DLL bool operator!=(const Coordinate& a, const Coordinate& b);
153 
154 
155 
156 } // namespace geos.geom
157 } // namespace geos
158 
159 #ifdef _MSC_VER
160 #pragma warning(pop)
161 #endif
162 
163 #ifdef GEOS_INLINE
164 # include "geos/geom/Coordinate.inl"
165 #endif
166 
167 #endif // ndef GEOS_GEOM_COORDINATE_H
168 
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
bool equals(const Coordinate &other) const
2D only
std::string toString() const
Returns a string of the form (x,y,z) .
std::vector< Coordinate > Vect
A vector of Coordinate objects (real object, not pointers)
Definition: Coordinate.h:77
std::vector< const Coordinate * > ConstVect
A vector of const Coordinate pointers.
Definition: Coordinate.h:71
std::set< const Coordinate *, CoordinateLessThen > ConstSet
A set of const Coordinate pointers.
Definition: Coordinate.h:68
std::stack< const Coordinate * > ConstStack
A stack of const Coordinate pointers.
Definition: Coordinate.h:74
double distance(const Coordinate &p) const
double y
y-coordinate
Definition: Coordinate.h:83
double x
x-coordinate
Definition: Coordinate.h:80
int compareTo(const Coordinate &other) const
TODO: deprecate this, move logic to CoordinateLessThen instead.
bool equals3D(const Coordinate &other) const
3D comparison
double z
z-coordinate
Definition: Coordinate.h:86
bool operator<(const Coordinate &a, const Coordinate &b)
Strict weak ordering operator for Coordinate.
Definition: Coordinate.h:140
std::ostream & operator<<(std::ostream &os, const Coordinate &c)
Output function.
bool operator!=(const Coordinate &a, const Coordinate &b)
Inequality operator for Coordinate. 2D only.
bool operator==(const Coordinate &a, const Coordinate &b)
Equality operator for Coordinate. 2D only.
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26
Strict weak ordering Functor for Coordinate.
Definition: Coordinate.h:131