17#include <geos/export.h>
18#include <geos/constants.h>
20#include <unordered_set>
29#pragma warning(disable: 4251)
36struct CoordinateLessThan;
41enum class CoordinateType : std::uint8_t {
48enum class Ordinate : std::uint8_t {
55GEOS_DLL std::ostream& operator<< (std::ostream&,
const CoordinateType);
57class GEOS_DLL CoordinateXY {
59 const static CoordinateXY _nullCoord;
62 constexpr const static double DEFAULT_X = 0.0;
63 constexpr const static double DEFAULT_Y = 0.0;
64 constexpr const static double DEFAULT_Z = DoubleNotANumber;
65 constexpr const static double DEFAULT_M = DoubleNotANumber;
73 CoordinateXY(
double xNew,
double yNew)
88 GEOS_DLL
friend bool operator==(
const CoordinateXY& a,
const CoordinateXY& b)
94 GEOS_DLL
friend bool operator!=(
const CoordinateXY& a,
const CoordinateXY& b)
96 return ! a.equals2D(b);
101 return std::isfinite(x) && std::isfinite(y);
104 bool equals2D(
const CoordinateXY& other)
const
115 bool equals2D(
const CoordinateXY& other,
double tolerance)
const
117 if (std::abs(x - other.x) > tolerance) {
120 if (std::abs(y - other.y) > tolerance) {
127 bool equals(
const CoordinateXY& other)
const
129 return equals2D(other);
133 inline int compareTo(
const CoordinateXY& other)
const
150 static const CoordinateXY& getNull();
152 double distance(
const CoordinateXY& p)
const
156 return std::sqrt(dx * dx + dy * dy);
159 double distanceSquared(
const CoordinateXY& p)
const
163 return dx * dx + dy * dy;
168 return (std::isnan(x) && std::isnan(y));
173 x = DoubleNotANumber;
174 y = DoubleNotANumber;
177 struct GEOS_DLL HashCode
179 inline std::size_t operator()(
const CoordinateXY& c)
const
181 size_t h = std::hash<double>{}(c.x);
182 h ^= std::hash<double>{}(c.y) << 1;
188 using UnorderedSet = std::unordered_set<Coordinate, HashCode>;
191 std::string toString()
const;
225 typedef std::set<const Coordinate*, CoordinateLessThan>
ConstSet;
226 typedef std::set<const CoordinateXY*, CoordinateLessThan> ConstXYSet;
235 typedef std::vector<Coordinate>
Vect;
238 typedef std::map<const CoordinateXY*, int, CoordinateLessThan>
ConstIntMap;
248 Coordinate(
double xNew,
double yNew,
double zNew = DEFAULT_Z)
249 : CoordinateXY(xNew, yNew)
253 explicit Coordinate(
const CoordinateXY& other)
254 : CoordinateXY(other)
263 CoordinateXY::setNull();
264 z = DoubleNotANumber;
267 static const Coordinate& getNull();
271 return CoordinateXY::isNull() && std::isnan(z);
277 return (x == other.x) && (y == other.y) &&
278 ((z == other.
z) || (std::isnan(z) && std::isnan(other.
z)));
284 Coordinate& operator=(
const CoordinateXY& other){
294class GEOS_DLL CoordinateXYM :
public CoordinateXY {
296 static const CoordinateXYM _nullCoord;
299 CoordinateXYM() : CoordinateXYM(DEFAULT_X, DEFAULT_Y, DEFAULT_M) {}
301 explicit CoordinateXYM(
const CoordinateXY& c)
305 CoordinateXYM(
double x_,
double y_,
double m_)
306 : CoordinateXY(x_, y_)
314 static const CoordinateXYM& getNull();
318 CoordinateXY::setNull();
319 m = DoubleNotANumber;
324 return CoordinateXY::isNull() && std::isnan(m);
326 bool equals3D(
const CoordinateXYM& other)
const {
327 return x == other.x && y == other.y && (m == other.m || (std::isnan(m) && std::isnan(other.m)));
330 CoordinateXYM& operator=(
const CoordinateXYZM& other);
332 CoordinateXYM& operator=(
const CoordinateXY& other) {
340 std::string toString()
const;
344class GEOS_DLL CoordinateXYZM :
public Coordinate {
346 static const CoordinateXYZM _nullCoord;
349 CoordinateXYZM() : CoordinateXYZM(DEFAULT_X, DEFAULT_Y, DEFAULT_Z, DEFAULT_M) {}
351 explicit CoordinateXYZM(
const CoordinateXY& c)
355 explicit CoordinateXYZM(
const CoordinateXYM& c)
359 explicit CoordinateXYZM(
const Coordinate& c)
363 CoordinateXYZM(
double x_,
double y_,
double z_,
double m_)
364 : Coordinate(x_, y_, z_)
372 static const CoordinateXYZM& getNull();
376 Coordinate::setNull();
377 m = DoubleNotANumber;
383 return Coordinate::isNull() && std::isnan(m);
386 bool equals4D(
const CoordinateXYZM& other)
const {
387 return x == other.x && y == other.y &&
388 (z == other.z || (std::isnan(z) && std::isnan(other.z))) &&
389 (m == other.m || (std::isnan(m) && std::isnan(other.m)));
392 CoordinateXYZM& operator=(
const CoordinateXY& other) {
401 CoordinateXYZM& operator=(
const Coordinate& other) {
410 CoordinateXYZM& operator=(
const CoordinateXYM& other) {
419 std::string toString()
const;
423CoordinateXYM::operator=(
const CoordinateXYZM& other) {
435 bool operator()(
const CoordinateXY* a,
const CoordinateXY* b)
const
437 if(a->compareTo(*b) < 0) {
445 bool operator()(
const CoordinateXY& a,
const CoordinateXY& b)
const
447 if(a.compareTo(b) < 0) {
458inline bool operator<(
const CoordinateXY& a,
const CoordinateXY& b)
467inline double CoordinateXY::get<Ordinate::X>()
const
473inline double CoordinateXY::get<Ordinate::Y>()
const
479inline double CoordinateXY::get<Ordinate::Z>()
const
485inline double CoordinateXY::get<Ordinate::M>()
const
493inline double Coordinate::get<Ordinate::X>()
const
499inline double Coordinate::get<Ordinate::Y>()
const
505inline double Coordinate::get<Ordinate::Z>()
const
511inline double Coordinate::get<Ordinate::M>()
const
519inline double CoordinateXYM::get<Ordinate::X>()
const
525inline double CoordinateXYM::get<Ordinate::Y>()
const
531inline double CoordinateXYM::get<Ordinate::Z>()
const
537inline double CoordinateXYM::get<Ordinate::M>()
const
545inline double CoordinateXYZM::get<Ordinate::X>()
const
551inline double CoordinateXYZM::get<Ordinate::Y>()
const
557inline double CoordinateXYZM::get<Ordinate::Z>()
const
563inline double CoordinateXYZM::get<Ordinate::M>()
const
568GEOS_DLL std::ostream& operator<< (std::ostream& os,
const CoordinateXY& c);
569GEOS_DLL std::ostream& operator<< (std::ostream& os,
const Coordinate& c);
570GEOS_DLL std::ostream& operator<< (std::ostream& os,
const CoordinateXYM& c);
571GEOS_DLL std::ostream& operator<< (std::ostream& os,
const CoordinateXYZM& c);
578 template<>
struct common_type<
geos::geom::CoordinateXY, geos::geom::CoordinateXY> {
using type = geos::geom::CoordinateXY; };
580 template<>
struct common_type<
geos::geom::CoordinateXY, geos::geom::CoordinateXYM> {
using type = geos::geom::CoordinateXYM; };
581 template<>
struct common_type<
geos::geom::CoordinateXY, geos::geom::CoordinateXYZM> {
using type = geos::geom::CoordinateXYZM; };
585 template<>
struct common_type<
geos::geom::Coordinate, geos::geom::CoordinateXYM> {
using type = geos::geom::CoordinateXYZM; };
586 template<>
struct common_type<
geos::geom::Coordinate, geos::geom::CoordinateXYZM> {
using type = geos::geom::CoordinateXYZM; };
588 template<>
struct common_type<
geos::geom::CoordinateXYM, geos::geom::CoordinateXY> {
using type = geos::geom::CoordinateXYM; };
589 template<>
struct common_type<
geos::geom::CoordinateXYM,
geos::geom::Coordinate> {
using type = geos::geom::CoordinateXYZM; };
590 template<>
struct common_type<
geos::geom::CoordinateXYM, geos::geom::CoordinateXYM> {
using type = geos::geom::CoordinateXYM; };
591 template<>
struct common_type<
geos::geom::CoordinateXYM, geos::geom::CoordinateXYZM> {
using type = geos::geom::CoordinateXYZM; };
593 template<>
struct common_type<
geos::geom::CoordinateXYZM, geos::geom::CoordinateXY> {
using type = geos::geom::CoordinateXYZM; };
594 template<>
struct common_type<
geos::geom::CoordinateXYZM,
geos::geom::Coordinate> {
using type = geos::geom::CoordinateXYZM; };
595 template<>
struct common_type<
geos::geom::CoordinateXYZM, geos::geom::CoordinateXYM> {
using type = geos::geom::CoordinateXYZM; };
596 template<>
struct common_type<
geos::geom::CoordinateXYZM, geos::geom::CoordinateXYZM> {
using type = geos::geom::CoordinateXYZM; };
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
std::string toString() const
Returns a string of the form (x,y,z) .
std::map< const CoordinateXY *, int, CoordinateLessThan > ConstIntMap
A map of const Coordinate pointers to integers.
Definition Coordinate.h:238
std::set< const Coordinate *, CoordinateLessThan > ConstSet
A set of const Coordinate pointers.
Definition Coordinate.h:225
std::vector< Coordinate > Vect
A vector of Coordinate objects (real object, not pointers)
Definition Coordinate.h:235
std::vector< const Coordinate * > ConstVect
A vector of const Coordinate pointers.
Definition Coordinate.h:229
std::stack< const Coordinate * > ConstStack
A stack of const Coordinate pointers.
Definition Coordinate.h:232
bool equals3D(const Coordinate &other) const
3D comparison
Definition Coordinate.h:275
double z
z-coordinate
Definition Coordinate.h:241
bool operator<(const CoordinateXY &a, const CoordinateXY &b)
Strict weak ordering operator for Coordinate.
Definition Coordinate.h:458
Basic namespace for all GEOS functionalities.
Definition geos.h:39
Strict weak ordering Functor for Coordinate.
Definition Coordinate.h:433