Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pca006132 committed Oct 6, 2024
1 parent 5229d3b commit eca5bbc
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions src/polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class EarClip {
struct IdxCollider {
Collider collider;
std::vector<VertItr> itr;
SparseIndices ind;
};

// A circularly-linked list representing the polygon(s) that still need to be
Expand Down Expand Up @@ -489,8 +490,7 @@ class EarClip {
// values < -precision so they will never affect validity. The first
// totalCost is designed to give priority to sharper angles. Any cost < (-1
// - precision) has satisfied the Delaunay condition.
double EarCost(double precision, const IdxCollider &collider,
SparseIndices &toTest) const {
double EarCost(double precision, IdxCollider &collider) const {
vec2 openSide = left->pos - right->pos;
const vec2 center = 0.5 * (left->pos + right->pos);
const double scale = 4 / glm::dot(openSide, openSide);
Expand All @@ -507,12 +507,12 @@ class EarClip {
earBox.push_back({vec3(center.x - radius, center.y - radius, 0),
vec3(center.x + radius, center.y + radius, 0)});
earBox.back().Union(vec3(pos, 0));
collider.collider.Collisions(earBox.cview(), toTest);
collider.collider.Collisions(earBox.cview(), collider.ind);

const int lid = left->mesh_idx;
const int rid = right->mesh_idx;
for (size_t i = 0; i < toTest.size(); ++i) {
const VertItr test = collider.itr[toTest.Get(i, true)];
for (size_t i = 0; i < collider.ind.size(); ++i) {
const VertItr test = collider.itr[collider.ind.Get(i, true)];
if (!Clipped(test) && test->mesh_idx != mesh_idx &&
test->mesh_idx != lid &&
test->mesh_idx != rid) { // Skip duplicated verts
Expand All @@ -523,7 +523,7 @@ class EarClip {
totalCost = std::max(totalCost, cost);
}
}
toTest.Clear();
collider.ind.Clear();
return totalCost;
}

Expand Down Expand Up @@ -800,8 +800,7 @@ class EarClip {

// Recalculate the cost of the Vert v ear, updating it in the queue by
// removing and reinserting it.
void ProcessEar(VertItr v, const IdxCollider &collider,
SparseIndices &buffer) {
void ProcessEar(VertItr v, IdxCollider &collider) {
if (v->ear != earsQueue_.end()) {
earsQueue_.erase(v->ear);
v->ear = earsQueue_.end();
Expand All @@ -810,7 +809,7 @@ class EarClip {
v->cost = kBest;
v->ear = earsQueue_.insert(v);
} else if (v->IsConvex(2 * precision_)) {
v->cost = v->EarCost(precision_, collider, buffer);
v->cost = v->EarCost(precision_, collider);
v->ear = earsQueue_.insert(v);
} else {
v->cost = 1; // not used, but marks reflex verts for debug
Expand Down Expand Up @@ -857,7 +856,7 @@ class EarClip {
void TriangulatePoly(VertItr start) {
ZoneScoped;

const IdxCollider vertCollider = VertCollider(start);
IdxCollider vertCollider = VertCollider(start);

if (vertCollider.itr.empty()) {
PRINT("Empty poly");
Expand All @@ -868,9 +867,8 @@ class EarClip {
int numTri = -2;
earsQueue_.clear();

SparseIndices buffer;
auto QueueVert = [&](VertItr v) {
ProcessEar(v, vertCollider, buffer);
ProcessEar(v, vertCollider);
++numTri;
v->PrintVert();
};
Expand All @@ -893,8 +891,8 @@ class EarClip {
ClipEar(v);
--numTri;

ProcessEar(v->left, vertCollider, buffer);
ProcessEar(v->right, vertCollider, buffer);
ProcessEar(v->left, vertCollider);
ProcessEar(v->right, vertCollider);
// This is a backup vert that is used if the queue is empty (geometrically
// invalid polygon), to ensure manifoldness.
v = v->right;
Expand Down

0 comments on commit eca5bbc

Please sign in to comment.