GEOS 3.11.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#include <geos/triangulate/tri/TriList.h>
19
20#include <memory>
21
22// Forward declarations
23namespace geos {
24namespace geom {
25class Geometry;
26class GeometryFactory;
27class Polygon;
28}
29}
30
34
35namespace geos { // geos.
36namespace triangulate { // geos.triangulate
37namespace tri { // geos.triangulate.tri
38
39
49class GEOS_DLL Tri {
50
51protected:
52
53 // Members
54 Coordinate p0;
55 Coordinate p1;
56 Coordinate p2;
57
63 Tri* tri1;
64 Tri* tri2;
65
66private:
67
74 void replace(Tri* triOld, Tri* triNew);
75 void remove(TriIndex index);
76
87 std::vector<Tri*> getAdjacentTris(Tri* tri, TriIndex index0, TriIndex index1);
88
89 void setCoordinates(const Coordinate& p0, const Coordinate& p1, const Coordinate& p2);
90
91 void flip(Tri* tri, TriIndex index0, TriIndex index1,
92 const Coordinate& adj0, const Coordinate& adj1,
93 const Coordinate& opp0, const Coordinate& opp1);
94
95
96public:
97
98 Tri(const Coordinate& c0, const Coordinate& c1, const Coordinate& c2)
99 : p0(c0)
100 , p1(c1)
101 , p2(c2)
102 , tri0(nullptr)
103 , tri1(nullptr)
104 , tri2(nullptr)
105 {};
106
107 void setAdjacent(Tri* p_tri0, Tri* p_tri1, Tri* p_tri2);
108 void setAdjacent(const Coordinate& pt, Tri* tri);
109 void setTri(TriIndex edgeIndex, Tri* tri);
110
119 void flip(TriIndex index);
120
126 void remove();
127 void remove(TriList<Tri>& triList);
128
129 void validate();
130 void validateAdjacent(TriIndex index);
131
132 std::pair<const Coordinate&, const Coordinate&> getEdge(Tri* neighbor) const;
133
134 const Coordinate& getEdgeStart(TriIndex i) const;
135 const Coordinate& getEdgeEnd(TriIndex i) const;
136
137 bool hasCoordinate(const Coordinate& v) const;
138 const Coordinate& getCoordinate(TriIndex i) const;
139
140 TriIndex getIndex(const Coordinate& p) const;
141 TriIndex getIndex(const Tri* tri) const;
142
143 Tri* getAdjacent(TriIndex i) const;
144 bool hasAdjacent(TriIndex i) const;
145 bool hasAdjacent() const;
146 bool isAdjacent(Tri* tri) const;
147
148 int numAdjacent() const;
149
150 static TriIndex next(TriIndex i);
151 static TriIndex prev(TriIndex i);
152 static TriIndex oppVertex(TriIndex edgeIndex);
153 static TriIndex oppEdge(TriIndex vertexIndex);
154
163 bool isInteriorVertex(TriIndex index) const;
164
165 bool isBorder() const;
166 bool isBoundary(TriIndex index) const;
167 Coordinate midpoint(TriIndex edgeIndex) const;
168
169 double getArea() const;
170 double getLength() const;
171 double getLength(TriIndex i) const;
172
173 std::unique_ptr<Polygon> toPolygon(const GeometryFactory* gf) const;
174 static std::unique_ptr<Geometry> toGeometry(std::set<Tri*>& tris, const GeometryFactory* gf);
175
176 friend std::ostream& operator << (std::ostream& os, const Tri&);
177
178};
179
180
181
182
183} // namespace geos.triangulate.tri
184} // namespace geos.triangulate
185} // namespace geos
186
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:66
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition: Geometry.h:186
Represents a linear polygon, which may include holes.
Definition: Polygon.h:61
Definition: Tri.h:49
bool isInteriorVertex(TriIndex index) const
void flip(TriIndex index)
Tri * tri0
Definition: Tri.h:62
Basic namespace for all GEOS functionalities.
Definition: geos.h:39