Skip to content

Commit

Permalink
remove triangulation intersection check
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed Aug 3, 2023
1 parent ab11469 commit 6a8591f
Showing 1 changed file with 0 additions and 67 deletions.
67 changes: 0 additions & 67 deletions src/polygon/src/polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,6 @@ void CheckTopology(const std::vector<glm::ivec3> &triangles,
CheckTopology(halfedges);
}

struct Edge {
glm::vec2 west; // -x side vertex
glm::vec2 east; // +x side vertex
size_t i; // index of origin vertex
inline bool operator<(const Edge &other) const {
return west.x < other.west.x ||
(west.x == other.west.x && east.x < other.east.x);
}
Edge() : west{0}, east{0}, i(0) {}
inline Edge(glm::vec2 p, glm::vec2 q, size_t i) : west(p), east(q), i(i) {
if (west.x > east.x) std::swap(east, west);
}
};

void CheckGeometry(const std::vector<glm::ivec3> &triangles,
const PolygonsIdx &polys, float precision) {
std::unordered_map<int, glm::vec2> vertPos;
Expand All @@ -172,59 +158,6 @@ void CheckGeometry(const std::vector<glm::ivec3> &triangles,
vertPos[tri[2]], precision) >= 0;
}),
geometryErr, "triangulation is not entirely CCW!");

std::vector<Edge> edges(3 * triangles.size());
auto f = [&](size_t i) {
edges[3 * i] = Edge(vertPos[triangles[i].x], vertPos[triangles[i].y], i);
edges[3 * i + 1] =
Edge(vertPos[triangles[i].y], vertPos[triangles[i].z], i);
edges[3 * i + 2] =
Edge(vertPos[triangles[i].z], vertPos[triangles[i].x], i);
};
std::for_each(
#if MANIFOLD_PAR == 'T' && __has_include(<pstl/glue_execution_defs.h>)
std::execution::par,
#endif
countAt((size_t)0), countAt(triangles.size()), f);
std::sort(
#if MANIFOLD_PAR == 'T' && __has_include(<pstl/glue_execution_defs.h>)
std::execution::par,
#endif
edges.begin(), edges.end());
std::mutex mutex;
std::vector<std::pair<Edge, Edge>> overlappingPairs;
auto p = [&](size_t i) {
// check all subsequent edges e' until e'.west.x > e.east.x
// this ensures we checked all edges e' where
// e.west.x < e'.west.x < e.east.x
Edge e = edges[i];
// note: 4*precision < 4*precision^2 because precision < 1
if (glm::length2(e.west - e.east) < 4 * precision) return false;
for (size_t j = i + 1; j < edges.size() && edges[j].west.x < e.east.x;
j++) {
Edge e1 = edges[j];
if (intersect(e.west, e.east, e1.west, e1.east, precision)) {
mutex.lock();
overlappingPairs.push_back(std::make_pair(e, e1));
mutex.unlock();
return true;
}
}
return false;
};
std::any_of(
#if MANIFOLD_PAR == 'T' && __has_include(<pstl/glue_execution_defs.h>)
std::execution::par,
#endif
countAt((size_t)0), countAt(edges.size() - 1), p);
if (!params.suppressErrors) {
for (auto &pairs : overlappingPairs) {
printf("triangle %d and %d are overlapping\n", (int)pairs.first.i,
(int)pairs.second.i);
}
}
ASSERT(overlappingPairs.empty(), geometryErr,
"triangulation is overlapping!");
}

void Dump(const PolygonsIdx &polys) {
Expand Down

0 comments on commit 6a8591f

Please sign in to comment.