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 37 /** 38 * \class Coordinate geom.h geos.h 39 * 40 * \brief 41 * Coordinate is the lightweight class used to store coordinates. 42 * 43 * It is distinct from Point, which is a subclass of Geometry. 44 * Unlike objects of type Point (which contain additional 45 * information such as an envelope, a precision model, and spatial 46 * reference system information), a Coordinate only contains 47 * ordinate values and accessor methods. 48 * 49 * Coordinate objects are two-dimensional points, with an additional 50 * z-ordinate. JTS does not support any operations on the z-ordinate except 51 * the basic accessor functions. 52 * 53 * Constructed coordinates will have a z-ordinate of DoubleNotANumber. 54 * The standard comparison functions will ignore the z-ordinate. 55 * 56 */ 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: 67 /// A set of const Coordinate pointers 68 typedef std::set<const Coordinate*, CoordinateLessThen> ConstSet; 69 70 /// A vector of const Coordinate pointers 71 typedef std::vector<const Coordinate*> ConstVect; 72 73 /// A stack of const Coordinate pointers 74 typedef std::stack<const Coordinate*> ConstStack; 75 76 /// A vector of Coordinate objects (real object, not pointers) 77 typedef std::vector<Coordinate> Vect; 78 79 /// x-coordinate 80 double x; 81 82 /// y-coordinate 83 double y; 84 85 /// z-coordinate 86 double z; 87 88 void setNull(); 89 90 static Coordinate& getNull(); 91 92 bool isNull() const; 93 94 Coordinate(double xNew = 0.0, double yNew = 0.0, double zNew = DoubleNotANumber); 95 96 bool equals2D(const Coordinate& other) const; 97 98 /// 2D only 99 bool equals(const Coordinate& other) const; 100 101 /// TODO: deprecate this, move logic to CoordinateLessThen instead 102 int compareTo(const Coordinate& other) const; 103 104 /// 3D comparison 105 bool equals3D(const Coordinate& other) const; 106 107 /// Returns a string of the form <I>(x,y,z)</I> . 108 std::string toString() const; 109 110 /// TODO: obsoleted this, can use PrecisionModel::makePrecise(Coordinate*) 111 /// instead 112 //void makePrecise(const PrecisionModel *pm); 113 114 double distance(const Coordinate& p) const; 115 116 double distanceSquared(const Coordinate& p) const; 117 118 struct GEOS_DLL HashCode { 119 size_t operator()(const Coordinate & c) const; 120 }; 121 122 }; 123 124 /// Strict weak ordering Functor for Coordinate 125 struct GEOS_DLL CoordinateLessThen { 126 127 bool operator()(const Coordinate* a, const Coordinate* b) const; 128 bool operator()(const Coordinate& a, const Coordinate& b) const; 129 130 }; 131 132 /// Strict weak ordering operator for Coordinate 133 inline bool 134 operator<(const Coordinate& a, const Coordinate& b) 135 { 136 return CoordinateLessThen()(a, b); 137 } 138 139 /// Output function 140 GEOS_DLL std::ostream& operator<< (std::ostream& os, const Coordinate& c); 141 142 /// Equality operator for Coordinate. 2D only. 143 GEOS_DLL bool operator==(const Coordinate& a, const Coordinate& b); 144 145 /// Inequality operator for Coordinate. 2D only. 146 GEOS_DLL bool operator!=(const Coordinate& a, const Coordinate& b); 147 148 149 150 } // namespace geos.geom 151 } // namespace geos 152 153 #ifdef _MSC_VER 154 #pragma warning(pop) 155 #endif 156 157 #ifdef GEOS_INLINE 158 # include "geos/geom/Coordinate.inl" 159 #endif 160 161 #endif // ndef GEOS_GEOM_COORDINATE_H 162 163