Coverage Report

Created: 2026-02-14 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/src/geomgraph/EdgeEnd.cpp
Line
Count
Source
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7
 * Copyright (C) 2005-2006 Refractions Research Inc.
8
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9
 *
10
 * This is free software; you can redistribute and/or modify it under
11
 * the terms of the GNU Lesser General Public Licence as published
12
 * by the Free Software Foundation.
13
 * See the COPYING file for more information.
14
 *
15
 **********************************************************************
16
 *
17
 * Last port: geomgraph/EdgeEnd.java r428 (JTS-1.12+)
18
 *
19
 **********************************************************************/
20
21
#include <geos/geomgraph/EdgeEnd.h>
22
#include <geos/geomgraph/Node.h> // for assertions
23
#include <geos/algorithm/Orientation.h>
24
#include <geos/geomgraph/Label.h>
25
#include <geos/geom/Quadrant.h>
26
#include <geos/geom/Coordinate.h>
27
28
#include <typeinfo>
29
#include <cmath>
30
#include <sstream>
31
#include <iostream>
32
#include <string>
33
#include <cassert>
34
35
using namespace geos::geom;
36
37
namespace geos {
38
namespace geomgraph { // geos.geomgraph
39
40
using namespace geos::algorithm;
41
42
/*public*/
43
EdgeEnd::EdgeEnd()
44
    :
45
0
    edge(nullptr),
46
0
    label(),
47
0
    node(nullptr),
48
0
    dx(0.0),
49
0
    dy(0.0),
50
0
    quadrant(0)
51
0
{
52
0
}
53
54
/*protected*/
55
EdgeEnd::EdgeEnd(Edge* newEdge)
56
    :
57
0
    edge(newEdge),
58
0
    label(),
59
0
    node(nullptr),
60
0
    dx(0.0),
61
0
    dy(0.0),
62
0
    quadrant(0)
63
0
{
64
0
}
65
66
/*public*/
67
EdgeEnd::EdgeEnd(Edge* newEdge, const Coordinate& newP0,
68
                 const Coordinate& newP1, const Label& newLabel)
69
    :
70
0
    edge(newEdge),
71
0
    label(newLabel),
72
0
    node(nullptr),
73
0
    dx(0.0),
74
0
    dy(0.0),
75
0
    quadrant(0)
76
0
{
77
0
    init(newP0, newP1);
78
0
}
79
80
/*public*/
81
EdgeEnd::EdgeEnd(Edge* newEdge, const Coordinate& newP0,
82
                 const Coordinate& newP1)
83
    :
84
0
    edge(newEdge),
85
0
    label(),
86
0
    node(nullptr),
87
0
    dx(0.0),
88
0
    dy(0.0),
89
0
    quadrant(0)
90
0
{
91
0
    init(newP0, newP1);
92
0
}
93
94
/*public*/
95
void
96
EdgeEnd::init(const Coordinate& newP0, const Coordinate& newP1)
97
0
{
98
0
    p0 = newP0;
99
0
    p1 = newP1;
100
0
    dx = p1.x - p0.x;
101
0
    dy = p1.y - p0.y;
102
0
    quadrant = Quadrant::quadrant(dx, dy);
103
104
    // "EdgeEnd with identical endpoints found");
105
0
    assert(!(dx == 0 && dy == 0));
106
0
}
107
108
/*public*/
109
Coordinate&
110
EdgeEnd::getDirectedCoordinate()
111
0
{
112
0
    return p1;
113
0
}
114
115
/*public*/
116
int
117
EdgeEnd::getQuadrant()
118
0
{
119
0
    return quadrant;
120
0
}
121
122
/*public*/
123
double
124
EdgeEnd::getDx()
125
0
{
126
0
    return dx;
127
0
}
128
129
/*public*/
130
double
131
EdgeEnd::getDy()
132
0
{
133
0
    return dy;
134
0
}
135
136
/*public*/
137
void
138
EdgeEnd::setNode(Node* newNode)
139
0
{
140
0
    node = newNode;
141
0
    assert(node->getCoordinate().equals2D(p0));
142
0
}
143
144
/*public*/
145
Node*
146
EdgeEnd::getNode()
147
0
{
148
0
    return node;
149
0
}
150
151
/*public*/
152
int
153
EdgeEnd::compareTo(const EdgeEnd* e) const
154
0
{
155
0
    return compareDirection(e);
156
0
}
157
158
/*public*/
159
int
160
EdgeEnd::compareDirection(const EdgeEnd* e) const
161
0
{
162
0
    assert(e);
163
0
    if(dx == e->dx && dy == e->dy) {
164
0
        return 0;
165
0
    }
166
167
    // if the rays are in different quadrants,
168
    // determining the ordering is trivial
169
0
    if(quadrant > e->quadrant) {
170
0
        return 1;
171
0
    }
172
0
    if(quadrant < e->quadrant) {
173
0
        return -1;
174
0
    }
175
176
    // vectors are in the same quadrant - check relative
177
    // orientation of direction vectors
178
    // this is > e if it is CCW of e
179
0
    return Orientation::index(e->p0, e->p1, p1);
180
0
}
181
182
/*public*/
183
void
184
EdgeEnd::computeLabel(const algorithm::BoundaryNodeRule& /*boundaryNodeRule*/)
185
0
{
186
    // subclasses should override this if they are using labels
187
0
}
188
189
/*public*/
190
std::string
191
EdgeEnd::print() const
192
0
{
193
0
    std::ostringstream s;
194
195
0
    s << *this;
196
197
0
    return s.str();
198
0
}
199
200
std::ostream&
201
operator<< (std::ostream& os, const EdgeEnd& ee)
202
0
{
203
0
    os << "EdgeEnd: ";
204
0
    os << ee.p0;
205
0
    os << " - ";
206
0
    os << ee.p1;
207
0
    os << " ";
208
0
    os << ee.quadrant << ":" << std::atan2(ee.dy, ee.dx);
209
0
    os << "  ";
210
0
    os << ee.label;
211
212
0
    return os;
213
0
}
214
215
216
} // namespace geos.geomgraph
217
} // namespace geos
218