Coverage Report

Created: 2025-08-30 06:52

/src/geos/include/geos/simplify/ComponentJumpChecker.h
Line
Count
Source (jump to first uncovered line)
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://libgeos.org
5
 *
6
 * Copyright (C) 2006 Refractions Research Inc.
7
 * Copyright (C) 2023 Martin Davis <mtnclimb@gmail.com>
8
 * Copyright (C) 2023 Paul Ramsey <pramsey@cleverelephant.ca>
9
 *
10
 * This is free software; you can redistribute and/or modify it under
11
 * the terms of the GNU Lesser General Licence as published
12
 * by the Free Software Foundation.
13
 * See the COPYING file for more information.
14
 *
15
 **********************************************************************/
16
17
#pragma once
18
19
#include <geos/export.h>
20
#include <vector>
21
#include <memory>
22
23
24
// Forward declarations
25
namespace geos {
26
namespace geom {
27
class Coordinate;
28
class CoordinateSequence;
29
class Envelope;
30
class LineSegment;
31
}
32
namespace simplify {
33
class TaggedLineString;
34
}
35
}
36
37
namespace geos {
38
namespace simplify { // geos::simplify
39
40
41
class GEOS_DLL ComponentJumpChecker {
42
    using Coordinate = geos::geom::Coordinate;
43
    using Envelope = geos::geom::Envelope;
44
    using LineSegment = geos::geom::LineSegment;
45
46
private:
47
48
    const std::vector<TaggedLineString*>& components;
49
50
    static bool hasJumpAtComponent(
51
        const Coordinate& compPt,
52
        const TaggedLineString* line,
53
        std::size_t start, std::size_t end,
54
        const LineSegment& seg);
55
56
    static bool hasJumpAtComponent(
57
        const Coordinate& compPt,
58
        const LineSegment* seg1, const LineSegment* seg2,
59
        const LineSegment& seg);
60
61
    static std::size_t crossingCount(
62
        const Coordinate& compPt,
63
        const LineSegment& seg);
64
65
    static std::size_t crossingCount(
66
        const Coordinate& compPt,
67
        const LineSegment* seg1, const LineSegment* seg2);
68
69
    std::size_t static  crossingCount(
70
        const Coordinate& compPt,
71
        const TaggedLineString* line,
72
        std::size_t start, std::size_t end);
73
74
    static Envelope computeEnvelope(
75
        const LineSegment* seg1, const LineSegment* seg2);
76
77
    static Envelope computeEnvelope(
78
        const TaggedLineString* line,
79
        std::size_t start, std::size_t end);
80
81
82
public:
83
84
    ComponentJumpChecker(const std::vector<TaggedLineString*>& taggedLines)
85
0
        : components(taggedLines)
86
0
    {}
87
88
    bool hasJump(
89
        const TaggedLineString* line,
90
        std::size_t start, std::size_t end,
91
        const LineSegment& seg) const;
92
93
    /**
94
    * Checks if two consecutive segments jumps a component if flattened.
95
    * The segments are assumed to be consecutive.
96
    * (so the seg1.p1 = seg2.p0).
97
    * The flattening segment must be the segment between seg1.p0 and seg2.p1.
98
    *
99
    * @param line the line containing the section being flattened
100
    * @param seg1 the first replaced segment
101
    * @param seg2 the next replaced segment
102
    * @param seg the flattening segment
103
    * @return true if the flattened segment jumps a component
104
    */
105
    bool hasJump(
106
        const TaggedLineString* line,
107
        const LineSegment* seg1,
108
        const LineSegment* seg2,
109
        const LineSegment& seg) const;
110
111
};
112
113
} // namespace geos::simplify
114
} // namespace geos
115
116
117
118
119