GEOS  3.13.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 <vector>
26 
27 // forward declarations
28 namespace geos {
29 namespace geom {
30 class Coordinate;
31 class CoordinateXY;
32 class CoordinateSequence;
33 }
34 }
35 
36 
37 namespace geos {
38 namespace algorithm {
39 
65 class GEOS_DLL RayCrossingCounter {
66 private:
67  const geom::CoordinateXY& point;
68 
69  std::size_t crossingCount;
70 
71  // true if the test point lies on an input segment
72  bool isPointOnSegment;
73 
74  // Declare type as noncopyable
75  RayCrossingCounter(const RayCrossingCounter& other) = delete;
76  RayCrossingCounter& operator=(const RayCrossingCounter& rhs) = delete;
77 
78 public:
88  static geom::Location locatePointInRing(const geom::CoordinateXY& p,
89  const geom::CoordinateSequence& ring);
90 
92  static geom::Location locatePointInRing(const geom::CoordinateXY& p,
93  const std::vector<const geom::Coordinate*>& ring);
94 
95  RayCrossingCounter(const geom::CoordinateXY& p_point)
96  : point(p_point),
97  crossingCount(0),
98  isPointOnSegment(false)
99  { }
100 
107  void countSegment(const geom::CoordinateXY& p1,
108  const geom::CoordinateXY& p2);
109 
119  bool
120  isOnSegment() const
121  {
122  return isPointOnSegment;
123  }
124 
136 
146  bool isPointInPolygon() const;
147 
148  std::size_t getCount() const { return crossingCount; };
149 
150 };
151 
152 } // geos::algorithm
153 } // geos
Counts the number of segments crossed by a horizontal ray extending to the right from a given point,...
Definition: RayCrossingCounter.h:65
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:120
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: Angle.h:25