Coverage Report

Created: 2026-09-14 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/include/geos/noding/snapround/MCIndexSnapRounder.h
Line
Count
Source
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2006      Refractions Research Inc.
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
 * Last port: noding/snapround/MCIndexSnapRounder.java r486 (JTS-1.12+)
16
 *
17
 **********************************************************************/
18
19
#pragma once
20
21
#include <geos/export.h>
22
23
#include <geos/noding/Noder.h> // for inheritance
24
#include <geos/noding/NodedSegmentString.h> // for inlines
25
#include <geos/noding/snapround/MCIndexPointSnapper.h> // for inlines
26
#include <geos/algorithm/LineIntersector.h> // for composition
27
#include <geos/geom/Coordinate.h> // for use in vector
28
#include <geos/geom/PrecisionModel.h> // for inlines
29
30
#include <vector>
31
32
#ifdef _MSC_VER
33
#pragma warning(push)
34
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
35
#endif
36
37
// Forward declarations
38
namespace geos {
39
namespace algorithm {
40
class LineIntersector;
41
}
42
namespace noding {
43
class SegmentString;
44
class MCIndexNoder;
45
}
46
}
47
48
namespace geos {
49
namespace noding { // geos::noding
50
namespace snapround { // geos::noding::snapround
51
52
53
/** \brief
54
 * Uses Snap Rounding to compute a rounded,
55
 * fully noded arrangement from a set of SegmentString
56
 *
57
 * Implements the Snap Rounding technique described in Hobby, Guibas & Marimont,
58
 * and Goodrich et al.
59
 *
60
 * Snap Rounding assumes that all vertices lie on a uniform grid
61
 * (hence the precision model of the input must be fixed precision,
62
 * and all the input vertices must be rounded to that precision).
63
 *
64
 * This implementation uses a monotone chains and a spatial index to
65
 * speed up the intersection tests.
66
 *
67
 * This implementation appears to be fully robust using an integer
68
 * precision model.
69
 *
70
 * It will function with non-integer precision models, but the
71
 * results are not 100% guaranteed to be correctly noded.
72
 */
73
class GEOS_DLL MCIndexSnapRounder: public Noder { // implements Noder
74
75
public:
76
77
    MCIndexSnapRounder(const geom::PrecisionModel& nPm)
78
        :
79
        pm(nPm),
80
        scaleFactor(nPm.getScale()),
81
        pointSnapper(nullptr)
82
0
    {
83
0
        li.setPrecisionModel(&pm);
84
0
    }
85
86
    std::vector<std::unique_ptr<SegmentString>>
87
    getNodedSubstrings() override
88
0
    {
89
0
        return NodedSegmentString::getNodedSubstrings(nodedSegStrings);
90
0
    }
91
92
    void computeNodes(const std::vector<SegmentString*>& segStrings) override;
93
94
    /**
95
     * Computes nodes introduced as a result of
96
     * snapping segments to vertices of other segments
97
     *
98
     * @param edges the list of segment strings to snap together
99
     *        NOTE: they *must* be instances of NodedSegmentString, or
100
     *              an assertion will fail.
101
     */
102
    void computeVertexSnaps(const std::vector<SegmentString*>& edges);
103
104
private:
105
106
    /// externally owned
107
    const geom::PrecisionModel& pm;
108
109
    algorithm::LineIntersector li;
110
111
    double scaleFactor;
112
113
    std::vector<SegmentString*> nodedSegStrings;
114
115
    std::unique_ptr<MCIndexPointSnapper> pointSnapper;
116
117
    void snapRound(MCIndexNoder& noder, const std::vector<SegmentString*>& segStrings);
118
119
120
    /**
121
     * Computes all interior intersections in the collection of SegmentStrings,
122
     * and push their Coordinate to the provided vector.
123
     *
124
     * Does NOT node the segStrings.
125
     *
126
     */
127
    void findInteriorIntersections(MCIndexNoder& noder,
128
                                   const std::vector<SegmentString*>& segStrings,
129
                                   std::vector<geom::Coordinate>& intersections);
130
131
    /**
132
     * Computes nodes introduced as a result of snapping
133
     * segments to snap points (hot pixels)
134
     */
135
    void computeIntersectionSnaps(std::vector<geom::Coordinate>& snapPts);
136
137
    /**
138
     * Performs a brute-force comparison of every segment in each {@link SegmentString}.
139
     * This has n^2 performance.
140
     */
141
    void computeVertexSnaps(NodedSegmentString* e);
142
143
    void checkCorrectness(std::vector<SegmentString*>& inputSegmentStrings);
144
145
    // Declare type as noncopyable
146
    MCIndexSnapRounder(const MCIndexSnapRounder& other) = delete;
147
    MCIndexSnapRounder& operator=(const MCIndexSnapRounder& rhs) = delete;
148
};
149
150
} // namespace geos::noding::snapround
151
} // namespace geos::noding
152
} // namespace geos
153
154
#ifdef _MSC_VER
155
#pragma warning(pop)
156
#endif
157