Coverage Report

Created: 2026-03-20 06:27

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/src/geom/prep/PreparedPolygonPredicate.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 Public Licence as published
10
 * by the Free Software Foundation.
11
 * See the COPYING file for more information.
12
 *
13
 **********************************************************************
14
 *
15
 * Last port: geom/prep/PreparedPolygonPredicate.java rev. 1.4 (JTS-1.10)
16
 * (2007-12-12)
17
 *
18
 **********************************************************************/
19
20
#include <geos/geom/prep/PreparedPolygonPredicate.h>
21
#include <geos/geom/prep/PreparedPolygon.h>
22
#include <geos/geom/Coordinate.h>
23
#include <geos/geom/CoordinateFilter.h>
24
#include <geos/geom/util/ComponentCoordinateExtracter.h>
25
#include <geos/geom/Location.h>
26
#include <geos/algorithm/locate/PointOnGeometryLocator.h>
27
#include <geos/algorithm/locate/SimplePointInAreaLocator.h>
28
// std
29
#include <cstddef>
30
31
namespace geos {
32
namespace geom { // geos.geom
33
namespace prep { // geos.geom.prep
34
//
35
// private:
36
//
37
38
//
39
// protected:
40
//
41
struct LocationMatchingFilter : public GeometryComponentFilter {
42
    explicit LocationMatchingFilter(algorithm::locate::PointOnGeometryLocator* locator, Location loc) :
43
0
        pt_locator(locator), test_loc(loc), found(false) {}
44
45
    algorithm::locate::PointOnGeometryLocator* pt_locator;
46
    const Location test_loc;
47
    bool found;
48
49
0
    void filter_ro(const Geometry* g) override {
50
0
        if (g->isEmpty())
51
0
            return;
52
0
        const CoordinateXY* pt = g->getCoordinate();
53
0
        const auto loc = pt_locator->locate(pt);
54
55
0
        if (loc == test_loc) {
56
0
            found = true;
57
0
        }
58
0
    }
59
60
0
    bool isDone() override {
61
0
        return found;
62
0
    }
63
};
64
65
struct LocationNotMatchingFilter : public GeometryComponentFilter {
66
    explicit LocationNotMatchingFilter(algorithm::locate::PointOnGeometryLocator* locator, Location loc) :
67
0
            pt_locator(locator), test_loc(loc), found(false) {}
68
69
    algorithm::locate::PointOnGeometryLocator* pt_locator;
70
    const Location test_loc;
71
    bool found;
72
73
0
    void filter_ro(const Geometry* g) override {
74
0
        if (g->isEmpty())
75
0
            return;
76
0
        const CoordinateXY* pt = g->getCoordinate();
77
0
        const auto loc = pt_locator->locate(pt);
78
79
0
        if (loc != test_loc) {
80
0
            found = true;
81
0
        }
82
0
    }
83
84
0
    bool isDone() override {
85
0
        return found;
86
0
    }
87
};
88
89
struct OutermostLocationFilter : public GeometryComponentFilter {
90
    explicit OutermostLocationFilter(algorithm::locate::PointOnGeometryLocator* locator) :
91
0
    pt_locator(locator),
92
0
    outermost_loc(geom::Location::NONE),
93
0
    done(false) {}
94
95
    algorithm::locate::PointOnGeometryLocator* pt_locator;
96
    Location outermost_loc;
97
    bool done;
98
99
0
    void filter_ro(const Geometry* g) override {
100
0
        if (g->isEmpty())
101
0
            return;
102
0
        const CoordinateXY* pt = g->getCoordinate();
103
0
        auto loc = pt_locator->locate(pt);
104
105
0
        if (outermost_loc == Location::NONE || outermost_loc == Location::INTERIOR) {
106
0
            outermost_loc = loc;
107
0
        } else if (loc == Location::EXTERIOR) {
108
0
            outermost_loc = loc;
109
0
            done = true;
110
0
        }
111
0
    }
112
113
0
    bool isDone() override {
114
0
        return done;
115
0
    }
116
117
0
    Location getOutermostLocation() {
118
0
        return outermost_loc;
119
0
    }
120
};
121
122
Location
123
PreparedPolygonPredicate::getOutermostTestComponentLocation(const geom::Geometry* testGeom) const
124
0
{
125
0
    OutermostLocationFilter filter(prepPoly->getPointLocator());
126
0
    testGeom->apply_ro(&filter);
127
128
0
    return filter.getOutermostLocation();
129
0
}
130
131
bool
132
PreparedPolygonPredicate::isAllTestComponentsInTargetInterior(
133
    const geom::Geometry* testGeom) const
134
0
{
135
0
    LocationNotMatchingFilter filter(prepPoly->getPointLocator(), geom::Location::INTERIOR);
136
0
    testGeom->apply_ro(&filter);
137
138
0
    return !filter.found;
139
0
}
140
141
bool
142
PreparedPolygonPredicate::isAnyTestComponentInTarget(
143
    const geom::Geometry* testGeom) const
144
0
{
145
0
    LocationNotMatchingFilter filter(prepPoly->getPointLocator(), geom::Location::EXTERIOR);
146
0
    testGeom->apply_ro(&filter);
147
148
0
    return filter.found;
149
0
}
150
151
bool
152
PreparedPolygonPredicate::isAnyTestComponentInTargetInterior(
153
    const geom::Geometry* testGeom) const
154
0
{
155
0
    LocationMatchingFilter filter(prepPoly->getPointLocator(), geom::Location::INTERIOR);
156
0
    testGeom->apply_ro(&filter);
157
158
0
    return filter.found;
159
0
}
160
161
bool
162
PreparedPolygonPredicate::isAnyTargetComponentInAreaTest(
163
    const geom::Geometry* testGeom,
164
    const std::vector<const CoordinateXY*>* targetRepPts) const
165
0
{
166
0
    algorithm::locate::SimplePointInAreaLocator piaLoc(testGeom);
167
168
0
    for(const auto& pt : *targetRepPts) {
169
0
        const Location loc = piaLoc.locate(pt);
170
0
        if(geom::Location::EXTERIOR != loc) {
171
0
            return true;
172
0
        }
173
0
    }
174
175
0
    return false;
176
0
}
177
178
//
179
// public:
180
//
181
182
} // namespace geos.geom.prep
183
} // namespace geos.geom
184
} // namespace geos