GEOS 3.10.1
Tri.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/geom/Coordinate.h>
18
19#include <memory>
20
21// Forward declarations
22namespace geos {
23namespace geom {
24class Geometry;
25class GeometryFactory;
26class Polygon;
27}
28}
29
33
34typedef int TriIndex;
35
36namespace geos { // geos.
37namespace triangulate { // geos.triangulate
38namespace tri { // geos.triangulate.tri
39
40
50class GEOS_DLL Tri {
51
52private:
53
54 // Members
55 Coordinate p0;
56 Coordinate p1;
57 Coordinate p2;
58
63 Tri* tri0;
64 Tri* tri1;
65 Tri* tri2;
66
73 void replace(Tri* triOld, Tri* triNew);
74
85 std::vector<Tri*> getAdjacentTris(Tri* tri, TriIndex index0, TriIndex index1);
86
87 void setCoordinates(const Coordinate& p0, const Coordinate& p1, const Coordinate& p2);
88
89 void flip(Tri* tri, TriIndex index0, TriIndex index1,
90 const Coordinate& adj0, const Coordinate& adj1,
91 const Coordinate& opp0, const Coordinate& opp1);
92
93
94public:
95
96 Tri(const Coordinate& c0, const Coordinate& c1, const Coordinate& c2)
97 : p0(c0)
98 , p1(c1)
99 , p2(c2)
100 , tri0(nullptr)
101 , tri1(nullptr)
102 , tri2(nullptr)
103 {};
104
105 void setAdjacent(Tri* p_tri0, Tri* p_tri1, Tri* p_tri2);
106 void setTri(TriIndex edgeIndex, Tri* tri);
107 void setAdjacent(const Coordinate& pt, Tri* tri);
108
117 void flip(TriIndex index);
118
119 void validate();
120 void validateAdjacent(TriIndex index);
121
122 std::pair<const Coordinate&, const Coordinate&> getEdge(Tri* neighbor) const;
123
124 const Coordinate& getEdgeStart(TriIndex i) const;
125 const Coordinate& getEdgeEnd(TriIndex i) const;
126
127 bool hasCoordinate(const Coordinate& v) const;
128 const Coordinate& getCoordinate(TriIndex i) const;
129
130 TriIndex getIndex(const Coordinate& p) const;
131 TriIndex getIndex(Tri* tri) const;
132
133 Tri* getAdjacent(TriIndex i) const;
134 bool hasAdjacent(TriIndex i) const;
135 bool isAdjacent(Tri* tri) const;
136 int numAdjacent() const;
137
138 static TriIndex next(TriIndex i);
139 static TriIndex prev(TriIndex i);
140 static TriIndex oppVertex(TriIndex edgeIndex);
141 static TriIndex oppEdge(TriIndex vertexIndex);
142 Coordinate midpoint(TriIndex edgeIndex) const;
143
144 std::unique_ptr<Polygon> toPolygon(const GeometryFactory* gf) const;
145
146 friend std::ostream& operator << (std::ostream& os, const Tri&);
147
148};
149
150
151
152
153} // namespace geos.triangulate.tri
154} // namespace geos.triangulate
155} // namespace geos
156
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:68
Represents a linear polygon, which may include holes.
Definition: Polygon.h:64
Definition: Tri.h:50
void flip(TriIndex index)
Basic namespace for all GEOS functionalities.
Definition: geos.h:40