Coverage Report

Created: 2026-09-14 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/include/geos/operation/predicate/RectangleContains.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: operation/predicate/RectangleContains.java rev 1.5 (JTS-1.10)
16
 *
17
 **********************************************************************/
18
19
#pragma once
20
21
#include <geos/export.h>
22
23
#include <geos/geom/Polygon.h> // for inlines
24
25
// Forward declarations
26
namespace geos {
27
namespace geom {
28
class Envelope;
29
class Geometry;
30
class Point;
31
class Coordinate;
32
class LineString;
33
//class Polygon;
34
}
35
}
36
37
namespace geos {
38
namespace operation { // geos::operation
39
namespace predicate { // geos::operation::predicate
40
41
/** \brief
42
 * Optimized implementation of spatial predicate "contains"
43
 * for cases where the first Geometry is a rectangle.
44
 *
45
 * As a further optimization,
46
 * this class can be used directly to test many geometries against a single
47
 * rectangle.
48
 *
49
 */
50
class GEOS_DLL RectangleContains {
51
52
private:
53
54
    const geom::Envelope& rectEnv;
55
56
    bool isContainedInBoundary(const geom::Geometry& geom);
57
58
    bool isPointContainedInBoundary(const geom::Point& geom);
59
60
    /** \brief
61
     * Tests if a point is contained in the boundary of the target
62
     * rectangle.
63
     *
64
     * @param pt the point to test
65
     * @return true if the point is contained in the boundary
66
     */
67
    bool isPointContainedInBoundary(const geom::CoordinateXY& pt);
68
69
    /** \brief
70
     * Tests if a linestring is completely contained in the boundary
71
     * of the target rectangle.
72
     *
73
     * @param line the linestring to test
74
     * @return true if the linestring is contained in the boundary
75
     */
76
    bool isLineStringContainedInBoundary(const geom::LineString& line);
77
78
    /** \brief
79
     * Tests if a line segment is contained in the boundary of the
80
     * target rectangle.
81
     *
82
     * @param p0 an endpoint of the segment
83
     * @param p1 an endpoint of the segment
84
     * @return true if the line segment is contained in the boundary
85
     */
86
    bool isLineSegmentContainedInBoundary(const geom::Coordinate& p0,
87
                                          const geom::Coordinate& p1);
88
89
public:
90
91
    static bool
92
    contains(const geom::Polygon& rect, const geom::Geometry& b)
93
0
    {
94
0
        RectangleContains rc(rect);
95
0
        return rc.contains(b);
96
0
    }
97
98
    /**
99
     * Create a new contains computer for two geometries.
100
     *
101
     * @param rect a rectangular geometry
102
     */
103
    RectangleContains(const geom::Polygon& rect)
104
        :
105
0
        rectEnv(*(rect.getEnvelopeInternal()))
106
0
    {}
107
108
    bool contains(const geom::Geometry& geom);
109
110
    // Declare type as noncopyable
111
    RectangleContains(const RectangleContains& other) = delete;
112
    RectangleContains& operator=(const RectangleContains& rhs) = delete;
113
};
114
115
116
117
} // namespace geos::operation::predicate
118
} // namespace geos::operation
119
} // namespace geos