GEOS 3.15.0dev
RingClipper.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
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#pragma once
16
17#include <geos/export.h>
18
19#include <geos/geom/Envelope.h>
20#include <geos/geom/CoordinateSequence.h>
21
22// Forward declarations
23namespace geos {
24namespace geom {
25class Coordinate;
26class CoordinateSequence;
27}
28}
29
30namespace geos { // geos.
31namespace operation { // geos.operation
32namespace overlayng { // geos.operation.overlayng
33
62class GEOS_DLL RingClipper {
64 using CoordinateXY = geos::geom::CoordinateXY;
67
68private:
69
70 // Constants
71 static constexpr int BOX_LEFT = 3;
72 static constexpr int BOX_TOP = 2;
73 static constexpr int BOX_RIGHT = 1;
74 static constexpr int BOX_BOTTOM = 0;
75
76 // Members
77 const Envelope clipEnv;
78
79 // Methods
80
84 std::unique_ptr<CoordinateSequence> clipToBoxEdge(const CoordinateSequence* pts, int edgeIndex, bool closeRing) const;
85
91 void intersection(const CoordinateXY& a, const CoordinateXY& b, int edgeIndex, CoordinateXY& rsltPt) const;
92 static double intersectionLineY(const CoordinateXY& a, const CoordinateXY& b, double y);
93 static double intersectionLineX(const CoordinateXY& a, const CoordinateXY& b, double x);
94 bool isInsideEdge(const CoordinateXY& p, int edgeIndex) const;
95
96
97public:
98
99 RingClipper(const Envelope* env)
100 : clipEnv(*env)
101 {};
102
106 std::unique_ptr<CoordinateSequence> clip(const CoordinateSequence* cs) const;
107
108};
109
110
111} // namespace geos.operation.overlayng
112} // namespace geos.operation
113} // namespace geos
114
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:220
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Definition RingClipper.h:62
std::unique_ptr< CoordinateSequence > clip(const CoordinateSequence *cs) const
Basic namespace for all GEOS functionalities.
Definition geos.h:38