35 template <
typename Real>
60 int operator()(std::vector<std::array<Real, 2>>
const& positions,
61 std::vector<std::array<int, 2>>
const& edges);
91 std::vector<std::array<int, 2>>
const& edges);
94 std::vector<std::array<int, 2>>
const& edges,
95 std::set<OrderedEdge>& overlappingRectangles)
const;
98 std::array<Real, 2>
const& p0, std::array<Real, 2>
const& p1,
99 std::array<Real, 2>
const& q0, std::array<Real, 2>
const& q1)
const;
110 template <
typename Real>
118 template <
typename Real>
120 std::vector<std::array<Real, 2>>
const& positions,
121 std::vector<std::array<int, 2>>
const& edges)
135 std::set<OrderedEdge> overlappingRectangles;
137 for (
auto key : overlappingRectangles)
142 std::array<int, 2> e0 = edges[key.V[0]];
143 std::array<int, 2> e1 = edges[key.V[1]];
144 std::array<Real, 2>
const& p0 = positions[e0[0]];
145 std::array<Real, 2>
const& p1 = positions[e0[1]];
146 std::array<Real, 2>
const& q0 = positions[e1[0]];
147 std::array<Real, 2>
const& q1 = positions[e1[1]];
162 template <
typename Real>
163 inline std::vector<std::vector<int>>
const&
169 template <
typename Real>
170 inline std::vector<std::vector<int>>
const&
176 template <
typename Real>
177 inline std::vector<int>
const&
183 template <
typename Real>
184 inline std::vector<int>
const&
190 template <
typename Real>
191 inline std::vector<typename IsPlanarGraph<Real>::OrderedEdge>
const&
197 template <
typename Real>
199 std::vector<std::array<int, 2>>
const& edges)
201 int const numPositions =
static_cast<int>(positions.size());
202 int const numEdges =
static_cast<int>(edges.size());
203 if (numPositions < 2 || numEdges == 0)
211 std::map<std::array<Real, 2>, std::vector<int>> uniquePositions;
212 for (
int i = 0; i < numPositions; ++i)
214 std::array<Real, 2>
p = positions[i];
215 auto iter = uniquePositions.find(p);
216 if (iter == uniquePositions.end())
219 indices.push_back(i);
220 uniquePositions.insert(std::make_pair(p, indices));
224 iter->second.push_back(i);
227 if (uniquePositions.size() < positions.size())
230 for (
auto const& element : uniquePositions)
232 if (element.second.size() > 1)
241 std::map<OrderedEdge, std::vector<int>> uniqueEdges;
242 for (
int i = 0; i < numEdges; ++i)
245 auto iter = uniqueEdges.find(key);
246 if (iter == uniqueEdges.end())
249 indices.push_back(i);
250 uniqueEdges.insert(std::make_pair(key, indices));
254 iter->second.push_back(i);
257 if (uniqueEdges.size() < edges.size())
262 for (
auto const& element : uniqueEdges)
264 if (element.second.size() > 1)
276 for (
int i = 0; i < numEdges; ++i)
278 std::array<int, 2> e = edges[i];
287 if (e[0] < 0 || e[0] >= numPositions || e[1] < 0 || e[1] >= numPositions)
298 template <
typename Real>
300 std::vector<std::array<int, 2>>
const& edges, std::set<OrderedEdge>& overlappingRectangles)
const 303 int const numEdges =
static_cast<int>(edges.size());
304 std::vector<std::array<Real, 2>> emin(numEdges);
305 std::vector<std::array<Real, 2>> emax(numEdges);
306 for (
int i = 0; i < numEdges; ++i)
308 std::array<int, 2> e = edges[i];
309 std::array<Real, 2>
const& p0 = positions[e[0]];
310 std::array<Real, 2>
const& p1 = positions[e[1]];
312 for (
int j = 0; j < 2; ++j)
328 int const numEndpoints = 2 * numEdges;
329 std::vector<Endpoint> xEndpoints(numEndpoints);
330 std::vector<Endpoint> yEndpoints(numEndpoints);
331 for (
int i = 0, j = 0; i < numEdges; ++i)
333 xEndpoints[j].type = 0;
334 xEndpoints[j].value = emin[i][0];
335 xEndpoints[j].index = i;
336 yEndpoints[j].type = 0;
337 yEndpoints[j].value = emin[i][1];
338 yEndpoints[j].index = i;
341 xEndpoints[j].type = 1;
342 xEndpoints[j].value = emax[i][0];
343 xEndpoints[j].index = i;
344 yEndpoints[j].type = 1;
345 yEndpoints[j].value = emax[i][1];
346 yEndpoints[j].index = i;
351 std::sort(xEndpoints.begin(), xEndpoints.end());
352 std::sort(yEndpoints.begin(), yEndpoints.end());
356 std::set<int> active;
357 for (
int i = 0; i < numEndpoints; ++i)
359 Endpoint const& endpoint = xEndpoints[i];
361 if (endpoint.
type == 0)
366 for (
auto activeIndex : active)
370 std::array<Real, 2>
const& r0min = emin[activeIndex];
371 std::array<Real, 2>
const& r0max = emax[activeIndex];
372 std::array<Real, 2>
const& r1min = emin[
index];
373 std::array<Real, 2>
const& r1max = emax[
index];
374 if (r0max[1] >= r1min[1] && r0min[1] <= r1max[1])
376 if (activeIndex < index)
378 overlappingRectangles.insert(
OrderedEdge(activeIndex, index));
382 overlappingRectangles.insert(
OrderedEdge(index, activeIndex));
386 active.insert(index);
395 template <
typename Real>
397 std::array<Real, 2>
const& p0, std::array<Real, 2>
const& p1,
398 std::array<Real, 2>
const& q0, std::array<Real, 2>
const& q1)
const 411 std::array<Real, 2> p1mp0, q1mq0, q0mp0;
412 for (
int j = 0; j < 2; ++j)
414 p1mp0[j] = p1[j] - p0[j];
415 q1mq0[j] = q1[j] - q0[j];
416 q0mp0[j] = q0[j] - p0[j];
419 Real denom = p1mp0[0] * q1mq0[1] - p1mp0[1] * q1mq0[0];
420 Real numer0 = q0mp0[0] * q1mq0[1] - q0mp0[1] * q1mq0[0];
421 Real numer1 = q0mp0[0] * p1mp0[1] - q0mp0[1] * p1mp0[0];
428 if (
mZero <= numer0 && numer0 <= denom &&
mZero <= numer1 && numer1 <= denom)
431 return (numer0 !=
mZero && numer0 != denom) || (numer1 !=
mZero && numer1 != denom);
440 if (
mZero >= numer0 && numer0 >= denom &&
mZero >= numer1 && numer1 >= denom)
443 return (numer0 !=
mZero && numer0 != denom) || (numer1 !=
mZero && numer1 != denom);
464 std::array<Real, 2> q1mp0;
465 for (
int j = 0; j < 2; ++j)
467 q1mp0[j] = q1[j] - p0[j];
469 Real sqrLenP1mP0 = p1mp0[0] * p1mp0[0] + p1mp0[1] * p1mp0[1];
470 Real value0 = q0mp0[0] * p1mp0[0] + q0mp0[1] * p1mp0[1];
471 Real value1 = q1mp0[0] * p1mp0[0] + q1mp0[1] * p1mp0[1];
472 if ((value0 >= sqrLenP1mP0 && value1 >= sqrLenP1mP0)
488 template <
typename Real>
502 template <
typename Real>
519 template <
typename Real>
std::vector< std::vector< int > > const & GetDuplicatedPositions() const
std::vector< int > const & GetEdgesWithInvalidVertices() const
OrderedEdge(int v0=-1, int v1=-1)
int IsValidTopology(std::vector< std::array< Real, 2 >> const &positions, std::vector< std::array< int, 2 >> const &edges)
bool InvalidSegmentIntersection(std::array< Real, 2 > const &p0, std::array< Real, 2 > const &p1, std::array< Real, 2 > const &q0, std::array< Real, 2 > const &q1) const
std::vector< OrderedEdge > const & GetInvalidIntersections() const
GLsizei const GLfloat * value
bool operator<(Endpoint const &endpoint) const
std::vector< std::vector< int > > mDuplicatedEdges
GLsizei GLenum const void * indices
std::vector< std::vector< int > > mDuplicatedPositions
bool operator<(OrderedEdge const &edge) const
std::vector< int > const & GetDegenerateEdges() const
std::vector< int > mEdgesWithInvalidVertices
std::vector< int > mDegenerateEdges
std::vector< OrderedEdge > mInvalidIntersections
std::vector< std::vector< int > > const & GetDuplicatedEdges() const
int operator()(std::vector< std::array< Real, 2 >> const &positions, std::vector< std::array< int, 2 >> const &edges)
void ComputeOverlappingRectangles(std::vector< std::array< Real, 2 >> const &positions, std::vector< std::array< int, 2 >> const &edges, std::set< OrderedEdge > &overlappingRectangles) const
GLint GLint GLsizei GLint GLenum GLenum type