Coverage Report

Created: 2026-04-01 06:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/src/linearref/LinearIterator.cpp
Line
Count
Source
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2005-2006 Refractions Research Inc.
7
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
8
 *
9
 * This is free software; you can redistribute and/or modify it under
10
 * the terms of the GNU Lesser General Public Licence as published
11
 * by the Free Software Foundation.
12
 * See the COPYING file for more information.
13
 *
14
 **********************************************************************
15
 *
16
 * Last port: linearref/LinearIterator.java r463
17
 *
18
 **********************************************************************/
19
20
21
#include <geos/geom/LineString.h>
22
#include <geos/linearref/LinearIterator.h>
23
#include <geos/linearref/LinearLocation.h>
24
#include <geos/linearref/LengthLocationMap.h>
25
#include <geos/util/IllegalArgumentException.h>
26
27
using namespace geos::geom;
28
29
namespace geos {
30
namespace linearref { // geos.linearref
31
32
size_t
33
LinearIterator::segmentEndVertexIndex(const LinearLocation& loc)
34
0
{
35
0
    if(loc.getSegmentFraction() > 0.0) {
36
0
        return loc.getSegmentIndex() + 1;
37
0
    }
38
0
    return loc.getSegmentIndex();
39
0
}
40
41
LinearIterator::LinearIterator(const Geometry* p_linear) :
42
0
    vertexIndex(0),
43
0
    componentIndex(0),
44
0
    linear(p_linear),
45
0
    numLines(p_linear->getNumGeometries())
46
0
{
47
0
    loadCurrentLine();
48
0
}
49
50
51
LinearIterator::LinearIterator(const Geometry* p_linear, const LinearLocation& start):
52
0
    vertexIndex(segmentEndVertexIndex(start)),
53
0
    componentIndex(start.getComponentIndex()),
54
0
    linear(p_linear),
55
0
    numLines(p_linear->getNumGeometries())
56
0
{
57
0
    loadCurrentLine();
58
0
}
59
60
LinearIterator::LinearIterator(const Geometry* p_linear, std::size_t p_componentIndex, std::size_t p_vertexIndex) :
61
0
    vertexIndex(p_vertexIndex),
62
0
    componentIndex(p_componentIndex),
63
0
    linear(p_linear),
64
0
    numLines(p_linear->getNumGeometries())
65
0
{
66
0
    loadCurrentLine();
67
0
}
68
69
void
70
LinearIterator::loadCurrentLine()
71
0
{
72
0
    if(componentIndex >= numLines) {
73
0
        currentLine = nullptr;
74
0
        return;
75
0
    }
76
0
    currentLine = dynamic_cast<const LineString*>(linear->getGeometryN(componentIndex));
77
0
    if(! currentLine) {
78
0
        throw util::IllegalArgumentException("LinearIterator only supports lineal geometry components");
79
0
    }
80
0
}
81
82
bool
83
LinearIterator::hasNext() const
84
0
{
85
0
    if(componentIndex >= numLines) {
86
0
        return false;
87
0
    }
88
0
    if(componentIndex == numLines - 1
89
0
            && vertexIndex >= currentLine->getNumPoints()) {
90
0
        return false;
91
0
    }
92
0
    return true;
93
0
}
94
95
void
96
LinearIterator::next()
97
0
{
98
0
    if(! hasNext()) {
99
0
        return;
100
0
    }
101
102
0
    vertexIndex++;
103
0
    if(vertexIndex >= currentLine->getNumPoints()) {
104
0
        componentIndex++;
105
0
        loadCurrentLine();
106
0
        vertexIndex = 0;
107
0
    }
108
0
}
109
110
bool
111
LinearIterator::isEndOfLine() const
112
0
{
113
0
    if(componentIndex >= numLines) {
114
0
        return false;
115
0
    }
116
    //LineString currentLine = (LineString) linear.getGeometryN(componentIndex);
117
0
    if(!currentLine) {
118
0
        return false;
119
0
    }
120
0
    if(vertexIndex < currentLine->getNumPoints() - 1) {
121
0
        return false;
122
0
    }
123
0
    return true;
124
0
}
125
126
size_t
127
LinearIterator::getComponentIndex() const
128
0
{
129
0
    return componentIndex;
130
0
}
131
132
size_t
133
LinearIterator::getVertexIndex() const
134
0
{
135
0
    return vertexIndex;
136
0
}
137
138
const LineString*
139
LinearIterator::getLine() const
140
0
{
141
0
    return currentLine;
142
0
}
143
144
Coordinate
145
LinearIterator::getSegmentStart() const
146
0
{
147
0
    return currentLine->getCoordinateN(vertexIndex);
148
0
}
149
150
Coordinate
151
LinearIterator::getSegmentEnd() const
152
0
{
153
0
    if(vertexIndex < getLine()->getNumPoints() - 1) {
154
0
        return currentLine->getCoordinateN(vertexIndex + 1);
155
0
    }
156
0
    Coordinate c;
157
0
    c.setNull();
158
0
    return c;
159
0
}
160
}
161
}