GEOS 3.14.0dev
EdgeKey.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
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#pragma once
16
17#include <geos/operation/overlayng/OverlayLabel.h>
18#include <geos/operation/overlayng/EdgeKey.h>
19#include <geos/operation/overlayng/Edge.h>
20#include <geos/geom/Coordinate.h>
21#include <geos/export.h>
22
23
24
25namespace geos { // geos.
26namespace operation { // geos.operation
27namespace overlayng { // geos.operation.overlayng
28
38class GEOS_DLL EdgeKey {
40
41private:
42
43 // Members
44 double p0x;
45 double p0y;
46 double p1x;
47 double p1y;
48
49 // Methods
50 void initPoints(const Edge* edge)
51 {
52 bool direction = edge->direction();
53 if (direction) {
54 init(edge->getCoordinate(0),
55 edge->getCoordinate(1));
56 }
57 else {
58 std::size_t len = edge->size();
59 init(edge->getCoordinate(len - 1),
60 edge->getCoordinate(len - 2));
61 }
62 }
63
64 void init(const geom::Coordinate& p0, const geom::Coordinate& p1)
65 {
66 p0x = p0.x;
67 p0y = p0.y;
68 p1x = p1.x;
69 p1y = p1.y;
70 }
71
72
73public:
74
75 EdgeKey(const Edge* edge)
76 {
77 initPoints(edge);
78 }
79
80 int compareTo(const EdgeKey* ek) const
81 {
82 if (p0x < ek->p0x) return -1;
83 if (p0x > ek->p0x) return 1;
84 if (p0y < ek->p0y) return -1;
85 if (p0y > ek->p0y) return 1;
86 // first points are equal, compare second
87 if (p1x < ek->p1x) return -1;
88 if (p1x > ek->p1x) return 1;
89 if (p1y < ek->p1y) return -1;
90 if (p1y > ek->p1y) return 1;
91 return 0;
92 }
93
94 bool equals(const EdgeKey* ek) const
95 {
96 return p0x == ek->p0x
97 && p0y == ek->p0y
98 && p1x == ek->p1x
99 && p1y == ek->p1y;
100 }
101
102 friend bool operator<(const EdgeKey& ek1, const EdgeKey& ek2)
103 {
104 return ek1.compareTo(&ek2) < 0;
105 };
106
107 friend bool operator==(const EdgeKey& ek1, const EdgeKey& ek2)
108 {
109 return ek1.equals(&ek2);
110 };
111
112};
113
114
115} // namespace geos.operation.overlayng
116} // namespace geos.operation
117} // namespace geos
118
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
Definition operation/overlayng/Edge.h:55
Basic namespace for all GEOS functionalities.
Definition geos.h:39