Coverage Report

Created: 2025-11-12 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/src/planargraph/DirectedEdge.cpp
Line
Count
Source
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
7
 *
8
 * This is free software; you can redistribute and/or modify it under
9
 * the terms of the GNU Lesser General Licence as published
10
 * by the Free Software Foundation.
11
 * See the COPYING file for more information.
12
 *
13
 **********************************************************************/
14
15
#include <geos/planargraph/DirectedEdge.h>
16
#include <geos/planargraph/Node.h>
17
#include <geos/geom/Quadrant.h>
18
#include <geos/algorithm/Orientation.h>
19
20
#include <cmath>
21
#include <sstream>
22
#include <vector>
23
#include <typeinfo>
24
25
26
using namespace geos::geom;
27
28
namespace geos {
29
namespace planargraph {
30
31
/*public*/
32
void
33
DirectedEdge::toEdges(std::vector<DirectedEdge*>& dirEdges, std::vector<Edge*>& edges)
34
0
{
35
0
    for(std::size_t i = 0, n = dirEdges.size(); i < n; ++i) {
36
0
        edges.push_back(dirEdges[i]->parentEdge);
37
0
    }
38
0
}
39
40
/*public*/
41
std::vector<Edge*>*
42
DirectedEdge::toEdges(std::vector<DirectedEdge*>& dirEdges)
43
0
{
44
0
    std::vector<Edge*>* edges = new std::vector<Edge*>();
45
0
    toEdges(dirEdges, *edges);
46
0
    return edges;
47
0
}
48
49
/*public*/
50
DirectedEdge::DirectedEdge(Node* newFrom, Node* newTo,
51
                           const Coordinate& directionPt, bool newEdgeDirection)
52
0
{
53
0
    from = newFrom;
54
0
    to = newTo;
55
0
    edgeDirection = newEdgeDirection;
56
0
    p0 = from->getCoordinate();
57
0
    p1 = directionPt;
58
0
    double dx = p1.x - p0.x;
59
0
    double dy = p1.y - p0.y;
60
0
    quadrant = geom::Quadrant::quadrant(dx, dy);
61
0
    angle = atan2(dy, dx);
62
    //Assert.isTrue(! (dx == 0 && dy == 0), "EdgeEnd with identical endpoints found");
63
0
}
64
65
/*public*/
66
Edge*
67
DirectedEdge::getEdge() const
68
0
{
69
0
    return parentEdge;
70
0
}
71
72
/*public*/
73
void
74
DirectedEdge::setEdge(Edge* newParentEdge)
75
0
{
76
0
    parentEdge = newParentEdge;
77
0
}
78
79
/*public*/
80
int
81
DirectedEdge::getQuadrant() const
82
0
{
83
0
    return quadrant;
84
0
}
85
86
/*public*/
87
const Coordinate&
88
DirectedEdge::getDirectionPt() const
89
0
{
90
0
    return p1;
91
0
}
92
93
/*public*/
94
bool
95
DirectedEdge::getEdgeDirection() const
96
0
{
97
0
    return edgeDirection;
98
0
}
99
100
/*public*/
101
Node*
102
DirectedEdge::getFromNode() const
103
0
{
104
0
    return from;
105
0
}
106
107
/*public*/
108
Node*
109
DirectedEdge::getToNode() const
110
0
{
111
0
    return to;
112
0
}
113
114
/*public*/
115
Coordinate&
116
DirectedEdge::getCoordinate() const
117
0
{
118
0
    return from->getCoordinate();
119
0
}
120
121
/*public*/
122
double
123
DirectedEdge::getAngle() const
124
0
{
125
0
    return angle;
126
0
}
127
128
/*public*/
129
DirectedEdge*
130
DirectedEdge::getSym() const
131
0
{
132
0
    return sym;
133
0
}
134
135
/*
136
 * Sets this DirectedEdge's symmetric DirectedEdge,
137
 * which runs in the opposite direction.
138
 */
139
void
140
DirectedEdge::setSym(DirectedEdge* newSym)
141
0
{
142
0
    sym = newSym;
143
0
}
144
145
/*public*/
146
int
147
DirectedEdge::compareTo(const DirectedEdge* de) const
148
0
{
149
0
    return compareDirection(de);
150
0
}
151
152
/*public*/
153
int
154
DirectedEdge::compareDirection(const DirectedEdge* e) const
155
0
{
156
// if the rays are in different quadrants, determining the ordering is trivial
157
0
    if(quadrant > e->quadrant) {
158
0
        return 1;
159
0
    }
160
0
    if(quadrant < e->quadrant) {
161
0
        return -1;
162
0
    }
163
    // vectors are in the same quadrant - check relative orientation of direction vectors
164
    // this is > e if it is CCW of e
165
0
    return algorithm::Orientation::index(e->p0, e->p1, p1);
166
0
}
167
168
/*public*/
169
std::string
170
DirectedEdge::print() const
171
0
{
172
0
    std::ostringstream s;
173
0
    s << *this;
174
0
    return s.str();
175
0
}
176
177
std::ostream&
178
operator << (std::ostream& s, const DirectedEdge& de)
179
0
{
180
0
    s << typeid(de).name() << ": " << de.p0 << " - " << de.p1;
181
0
    s << " " << de.quadrant << ":" << de.angle;
182
0
    return s;
183
0
}
184
185
} // namespace planargraph
186
} // namespace geos
187