Coverage Report

Created: 2022-08-24 06:40

/src/geos/include/geos/noding/OrientedCoordinateArray.h
Line
Count
Source (jump to first uncovered line)
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2009    Sandro Santilli <strk@kbt.io>
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/OrientedCoordinateArray.java rev. 1.1 (JTS-1.9)
16
 *
17
 **********************************************************************/
18
19
#pragma once
20
21
#include <geos/export.h>
22
23
#include <cstddef>
24
25
// Forward declarations
26
namespace geos {
27
namespace geom {
28
class CoordinateSequence;
29
}
30
namespace noding {
31
//class SegmentString;
32
}
33
}
34
35
namespace geos {
36
namespace noding { // geos.noding
37
38
/** \brief
39
 * Allows comparing {@link geom::CoordinateSequence}s
40
 * in an orientation-independent way.
41
 */
42
class GEOS_DLL OrientedCoordinateArray {
43
public:
44
45
    /**
46
     * Creates a new {@link OrientedCoordinateArray}
47
     * for the given {@link geom::CoordinateSequence}.
48
     *
49
     * @param p_pts the coordinates to orient
50
     */
51
    OrientedCoordinateArray(const geom::CoordinateSequence& p_pts)
52
        :
53
        pts(&p_pts),
54
        orientationVar(orientation(p_pts))
55
13.8M
    {
56
13.8M
    }
57
58
    /** \brief
59
     * Compares two {@link OrientedCoordinateArray}s for their
60
     * relative order
61
     *
62
     * @return -1 this one is smaller
63
     * @return 0 the two objects are equal
64
     * @return 1 this one is greater
65
     *
66
     * In JTS, this is used automatically by ordered lists.
67
     * In C++, operator< would be used instead....
68
     */
69
    int compareTo(const OrientedCoordinateArray& o1) const;
70
71
    bool operator==(const OrientedCoordinateArray& other) const;
72
73
    struct GEOS_DLL HashCode {
74
        std::size_t operator()(const OrientedCoordinateArray & oca) const;
75
    };
76
77
private:
78
79
    static int compareOriented(const geom::CoordinateSequence& pts1,
80
                               bool orientation1,
81
                               const geom::CoordinateSequence& pts2,
82
                               bool orientation2);
83
84
85
    /**
86
     * Computes the canonical orientation for a coordinate array.
87
     *
88
     * @param pts the array to test
89
     * @return <code>true</code> if the points are oriented forwards
90
     * @return <code>false</code> if the points are oriented in reverse
91
     */
92
    static bool orientation(const geom::CoordinateSequence& pts);
93
94
    /// Externally owned
95
    const geom::CoordinateSequence* pts;
96
97
    bool orientationVar;
98
99
};
100
101
/// Strict weak ordering operator for OrientedCoordinateArray
102
///
103
/// This is the C++ equivalent of JTS's compareTo
104
inline bool
105
operator< (const OrientedCoordinateArray& oca1,
106
           const OrientedCoordinateArray& oca2)
107
0
{
108
0
    return oca1.compareTo(oca2) < 0;
109
0
}
110
111
} // namespace geos.noding
112
} // namespace geos
113