GEOS 3.14.0dev
RayCrossingCounter.h
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 *
16 * Last port: algorithm/RayCrossingCounter.java rev. 1.2 (JTS-1.9)
17 *
18 **********************************************************************/
19
20#pragma once
21
22#include <geos/export.h>
23#include <geos/geom/Location.h>
24
25#include <array>
26#include <vector>
27
28// forward declarations
29namespace geos {
30namespace geom {
31class Coordinate;
32class CoordinateXY;
33class CoordinateSequence;
34class CircularArc;
35class Curve;
36}
37}
38
39
40namespace geos {
41namespace algorithm {
42
68class GEOS_DLL RayCrossingCounter {
69private:
70 const geom::CoordinateXY& point;
71
72 std::size_t crossingCount;
73
74 // true if the test point lies on an input segment
75 bool isPointOnSegment;
76
77 // Declare type as noncopyable
78 RayCrossingCounter(const RayCrossingCounter& other) = delete;
79 RayCrossingCounter& operator=(const RayCrossingCounter& rhs) = delete;
80
81public:
91 static geom::Location locatePointInRing(const geom::CoordinateXY& p,
92 const geom::CoordinateSequence& ring);
93
95 static geom::Location locatePointInRing(const geom::CoordinateXY& p,
96 const std::vector<const geom::Coordinate*>& ring);
97
98 static geom::Location locatePointInRing(const geom::CoordinateXY& p,
99 const geom::Curve& ring);
100
101 RayCrossingCounter(const geom::CoordinateXY& p_point)
102 : point(p_point),
103 crossingCount(0),
104 isPointOnSegment(false)
105 { }
106
113 void countSegment(const geom::CoordinateXY& p1,
114 const geom::CoordinateXY& p2);
115
116 void countArc(const geom::CoordinateXY& p1,
117 const geom::CoordinateXY& p2,
118 const geom::CoordinateXY& p3);
119
123 void processSequence(const geom::CoordinateSequence& seq, bool isLinear);
124
134 bool
136 {
137 return isPointOnSegment;
138 }
139
151
161 bool isPointInPolygon() const;
162
163 std::size_t getCount() const { return crossingCount; };
164
165 static bool shouldCountCrossing(const geom::CircularArc& arc, const geom::CoordinateXY& q);
166
167 static std::array<geom::CoordinateXY, 2>
168 pointsIntersectingHorizontalRay(const geom::CircularArc& arc, const geom::CoordinateXY& origin);
169
170};
171
172} // geos::algorithm
173} // geos
Counts the number of segments crossed by a horizontal ray extending to the right from a given point,...
Definition RayCrossingCounter.h:68
void countSegment(const geom::CoordinateXY &p1, const geom::CoordinateXY &p2)
Counts a segment.
static geom::Location locatePointInRing(const geom::CoordinateXY &p, const geom::CoordinateSequence &ring)
Determines the Location of a point in a ring.
geom::Location getLocation() const
Gets the Location of the point relative to the ring, polygon or multipolygon from which the processed...
static geom::Location locatePointInRing(const geom::CoordinateXY &p, const std::vector< const geom::Coordinate * > &ring)
Semantically equal to the above, just different args encoding.
bool isPointInPolygon() const
Tests whether the point lies in or on the ring, polygon or multipolygon from which the processed segm...
bool isOnSegment() const
Reports whether the point lies exactly on one of the supplied segments.
Definition RayCrossingCounter.h:135
void processSequence(const geom::CoordinateSequence &seq, bool isLinear)
Counts all segments or arcs in the sequence.
Definition CircularArc.h:29
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Location
Constants representing the location of a point relative to a geometry.
Definition Location.h:32
Basic namespace for all GEOS functionalities.
Definition geos.h:39