Coverage Report

Created: 2025-11-16 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/src/simplify/LinkedRing.cpp
Line
Count
Source
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2022 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
#include <geos/simplify/LinkedRing.h>
16
17
#include <geos/geom/CoordinateSequence.h>
18
#include <cassert>
19
20
21
using geos::geom::Coordinate;
22
using geos::geom::CoordinateSequence;
23
24
25
namespace geos {
26
namespace simplify { // geos.simplify
27
28
29
/* private static */
30
std::vector<std::size_t>
31
LinkedRing::createNextLinks(std::size_t p_size)
32
0
{
33
0
    std::vector<std::size_t> next(p_size);
34
0
    for (std::size_t i = 0; i < p_size; i++) {
35
0
        next[i] = i + 1;
36
0
    }
37
0
    next[p_size - 1] = 0;
38
0
    return next;
39
0
}
40
41
/* private static */
42
std::vector<std::size_t>
43
LinkedRing::createPrevLinks(std::size_t p_size)
44
0
{
45
0
    assert(p_size>0);
46
0
    std::vector<std::size_t> prev(p_size);
47
0
    prev[0] = p_size - 1;
48
0
    for (std::size_t i = 1; i < p_size; i++) {
49
0
        prev[i] = i - 1;
50
0
    }
51
0
    return prev;
52
0
}
53
54
/* public */
55
std::size_t
56
LinkedRing::size() const
57
0
{
58
0
    return m_size;
59
0
}
60
61
/* public */
62
std::size_t
63
LinkedRing::next(std::size_t i) const
64
0
{
65
0
    return m_next[i];
66
0
}
67
68
/* public */
69
std::size_t
70
LinkedRing::prev(std::size_t i) const
71
0
{
72
0
    return m_prev[i];
73
0
}
74
75
/* public */
76
const Coordinate&
77
LinkedRing::getCoordinate(std::size_t index) const
78
0
{
79
0
    return m_coord[index];
80
0
}
81
82
/* public */
83
const Coordinate&
84
LinkedRing::prevCoordinate(std::size_t index) const
85
0
{
86
0
    return m_coord[prev(index)];
87
0
}
88
89
/* public */
90
const Coordinate&
91
LinkedRing::nextCoordinate(std::size_t index) const
92
0
{
93
0
    return m_coord[next(index)];
94
0
}
95
96
/* public */
97
bool
98
LinkedRing::hasCoordinate(std::size_t index) const
99
0
{
100
0
    return index < m_prev.size()
101
0
        && m_prev[index] != NO_COORD_INDEX;
102
0
}
103
104
/* public */
105
void
106
LinkedRing::remove(std::size_t index)
107
0
{
108
0
    std::size_t iprev = m_prev[index];
109
0
    std::size_t inext = m_next[index];
110
0
    m_next[iprev] = inext;
111
0
    m_prev[inext] = iprev;
112
0
    m_prev[index] = NO_COORD_INDEX;
113
0
    m_next[index] = NO_COORD_INDEX;
114
0
    m_size--;
115
0
}
116
117
/* public */
118
std::unique_ptr<CoordinateSequence>
119
LinkedRing::getCoordinates() const
120
0
{
121
0
    std::unique_ptr<CoordinateSequence> coords(new CoordinateSequence());
122
0
    for (std::size_t i = 0; i < m_coord.size() - 1; i++) {
123
0
        if (m_prev[i] != NO_COORD_INDEX) {
124
0
            coords->add(m_coord[i], false);
125
0
        }
126
0
    }
127
0
    coords->closeRing();
128
0
    return coords;
129
0
}
130
131
132
} // namespace geos.simplify
133
} // namespace geos
134