Coverage Report

Created: 2026-04-01 06:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/include/geos/geomgraph/EdgeIntersection.h
Line
Count
Source
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2009-2011 Sandro Santilli <strk@kbt.io>
7
 * Copyright (C) 2005-2006 Refractions Research Inc.
8
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9
 *
10
 * This is free software; you can redistribute and/or modify it under
11
 * the terms of the GNU Lesser General Public Licence as published
12
 * by the Free Software Foundation.
13
 * See the COPYING file for more information.
14
 *
15
 **********************************************************************
16
 *
17
 * Last port: geomgraph/EdgeIntersection.java rev. 1.5 (JTS-1.10)
18
 *
19
 **********************************************************************/
20
21
22
#pragma once
23
24
#include <geos/export.h>
25
26
#include <geos/geom/Coordinate.h> // for composition and inlines
27
28
#include <ostream>
29
30
31
namespace geos {
32
namespace geomgraph { // geos.geomgraph
33
34
/** \brief
35
 * Represents a point on an edge which intersects with another edge.
36
 *
37
 * The intersection may either be a single point, or a line segment
38
 * (in which case this point is the start of the line segment)
39
 * The intersection point must be precise.
40
 *
41
 */
42
class GEOS_DLL EdgeIntersection final {
43
public:
44
45
    // the point of intersection
46
    geom::Coordinate coord;
47
48
    // the edge distance of this point along the containing line segment
49
    double dist;
50
51
    // the index of the containing line segment in the parent edge
52
    std::size_t segmentIndex;
53
54
    EdgeIntersection(const geom::Coordinate& newCoord,
55
                     std::size_t newSegmentIndex, double newDist)
56
        :
57
0
        coord(newCoord),
58
0
        dist(newDist),
59
0
        segmentIndex(newSegmentIndex)
60
0
    {}
61
62
    bool
63
    isEndPoint(std::size_t maxSegmentIndex) const
64
0
    {
65
0
        if(segmentIndex == 0 && dist == 0.0) {
66
0
            return true;
67
0
        }
68
0
        if(segmentIndex == maxSegmentIndex) {
69
0
            return true;
70
0
        }
71
0
        return false;
72
0
    }
73
74
    const geom::Coordinate&
75
    getCoordinate() const
76
0
    {
77
0
        return coord;
78
0
    }
79
80
    size_t
81
    getSegmentIndex() const
82
0
    {
83
0
        return segmentIndex;
84
0
    }
85
86
    double
87
    getDistance() const
88
0
    {
89
0
        return dist;
90
0
    }
91
92
0
    bool operator==(const EdgeIntersection& other) const {
93
0
        return segmentIndex == other.segmentIndex &&
94
0
            dist == other.dist;
95
96
        // We don't check the coordinate, consistent with operator<
97
0
    }
98
99
};
100
101
/// Strict weak ordering operator for EdgeIntersection
102
///
103
/// This is the C++ equivalent of JTS's compareTo
104
inline bool
105
operator< (const EdgeIntersection& ei1, const EdgeIntersection& ei2)
106
0
{
107
0
    if(ei1.segmentIndex < ei2.segmentIndex) {
108
0
        return true;
109
0
    }
110
0
    if(ei1.segmentIndex == ei2.segmentIndex) {
111
0
        if(ei1.dist < ei2.dist) {
112
0
            return true;
113
0
        }
114
115
        // TODO: check if the Coordinate matches, or this will
116
        //       be a robustness issue in computing distance
117
        //       See http://trac.osgeo.org/geos/ticket/350
118
0
    }
119
0
    return false;
120
0
}
121
122
// @deprecated, use strict weak ordering operator
123
struct GEOS_DLL  EdgeIntersectionLessThen {
124
    bool
125
    operator()(const EdgeIntersection* ei1,
126
               const EdgeIntersection* ei2) const
127
0
    {
128
0
        return *ei1 < *ei2;
129
0
    }
130
131
    bool
132
    operator()(const EdgeIntersection& ei1,
133
               const EdgeIntersection& ei2) const
134
0
    {
135
0
        return ei1 < ei2;
136
0
    }
137
};
138
139
/// Output operator
140
inline std::ostream&
141
operator<< (std::ostream& os, const EdgeIntersection& e)
142
0
{
143
0
    os << e.coord << " seg # = " << e.segmentIndex << " dist = " << e.dist;
144
0
    return os;
145
0
}
146
147
} // namespace geos.geomgraph
148
} // namespace geos
149