35
35
namespace {
36
36
using namespace manifold ;
37
37
38
- constexpr uint64_t kRemove = std::numeric_limits<uint64_t >::max();
39
-
40
38
// Absolute error <= 6.7e-5
41
- float acos (float x) {
39
+ float fastacos (float x) {
42
40
float negate = float (x < 0 );
43
- x = abs (x);
41
+ x = std:: abs (x);
44
42
float ret = -0.0187293 ;
45
43
ret = ret * x;
46
44
ret = ret + 0.0742610 ;
@@ -240,7 +238,6 @@ void Manifold::Impl::DedupePropVerts() {
240
238
autoPolicy (halfedge_.size (), 1e4 ), countAt (0 ), halfedge_.size (),
241
239
[&vert2vert, numProp, this ](const int edgeIdx) {
242
240
const Halfedge edge = halfedge_[edgeIdx];
243
- const Halfedge pair = halfedge_[edge.pairedHalfedge ];
244
241
const int edgeFace = edgeIdx / 3 ;
245
242
const int pairFace = edge.pairedHalfedge / 3 ;
246
243
@@ -278,6 +275,8 @@ void Manifold::Impl::DedupePropVerts() {
278
275
for (int i : {0 , 1 , 2 }) prop[i] = label2vert[vertLabels[prop[i]]];
279
276
}
280
277
278
+ constexpr int removedHalfedge = -2 ;
279
+
281
280
/* *
282
281
* Create the halfedge_ data structure from an input triVerts array like Mesh.
283
282
*/
@@ -319,9 +318,7 @@ void Manifold::Impl::CreateHalfedges(const Vec<ivec3>& triVerts) {
319
318
// which are removed later by RemoveUnreferencedVerts() and Finish().
320
319
const int numEdge = numHalfedge / 2 ;
321
320
322
- constexpr int removedHalfedge = -2 ;
323
- const auto body = [&, removedHalfedge](int i, int consecutiveStart,
324
- int segmentEnd) {
321
+ const auto body = [&](int i, int consecutiveStart, int segmentEnd) {
325
322
const int pair0 = ids[i];
326
323
Halfedge& h0 = halfedge_[pair0];
327
324
int k = consecutiveStart + numEdge;
@@ -380,17 +377,16 @@ void Manifold::Impl::CreateHalfedges(const Vec<ivec3>& triVerts) {
380
377
// Once sorted, the first half of the range is the forward halfedges, which
381
378
// correspond to their backward pair at the same offset in the second half
382
379
// of the range.
383
- for_each_n (policy, countAt (0 ), numEdge,
384
- [this , &ids, numEdge, removedHalfedge](int i) {
385
- const int pair0 = ids[i];
386
- const int pair1 = ids[i + numEdge];
387
- if (halfedge_[pair0].pairedHalfedge != removedHalfedge) {
388
- halfedge_[pair0].pairedHalfedge = pair1;
389
- halfedge_[pair1].pairedHalfedge = pair0;
390
- } else {
391
- halfedge_[pair0] = halfedge_[pair1] = {-1 , -1 , -1 };
392
- }
393
- });
380
+ for_each_n (policy, countAt (0 ), numEdge, [this , &ids, numEdge](int i) {
381
+ const int pair0 = ids[i];
382
+ const int pair1 = ids[i + numEdge];
383
+ if (halfedge_[pair0].pairedHalfedge != removedHalfedge) {
384
+ halfedge_[pair0].pairedHalfedge = pair1;
385
+ halfedge_[pair1].pairedHalfedge = pair0;
386
+ } else {
387
+ halfedge_[pair0] = halfedge_[pair1] = {-1 , -1 , -1 };
388
+ }
389
+ });
394
390
}
395
391
396
392
/* *
@@ -529,7 +525,6 @@ void Manifold::Impl::CalculateNormals() {
529
525
ZoneScoped;
530
526
vertNormal_.resize (NumVert ());
531
527
auto policy = autoPolicy (NumTri ());
532
- bool calculateTriNormal = false ;
533
528
534
529
std::vector<std::atomic<int >> vertHalfedgeMap (NumVert ());
535
530
for_each_n (policy, countAt (0 ), NumVert (), [&](const size_t vert) {
@@ -544,7 +539,6 @@ void Manifold::Impl::CalculateNormals() {
544
539
};
545
540
if (faceNormal_.size () != NumTri ()) {
546
541
faceNormal_.resize (NumTri ());
547
- calculateTriNormal = true ;
548
542
for_each_n (policy, countAt (0 ), NumTri (), [&](const int face) {
549
543
vec3& triNormal = faceNormal_[face];
550
544
if (halfedge_[3 * face].startVert < 0 ) {
@@ -592,7 +586,7 @@ void Manifold::Impl::CalculateNormals() {
592
586
// should just exclude it from the normal calculation...
593
587
if (!la::isfinite (currEdge[0 ]) || !la::isfinite (prevEdge[0 ])) return ;
594
588
double dot = -la::dot (prevEdge, currEdge);
595
- double phi = dot >= 1 ? 0 : (dot <= -1 ? kPi : acos (dot));
589
+ double phi = dot >= 1 ? 0 : (dot <= -1 ? kPi : fastacos (dot));
596
590
normal += phi * faceNormal_[edge / 3 ];
597
591
});
598
592
vertNormal_[vert] = SafeNormalize (normal );
@@ -673,7 +667,7 @@ Manifold Manifold::ImportMeshGL64(std::istream& stream) {
673
667
stream.get (tmp.data (), SIZE, ' \n ' );
674
668
if (strncmp (tmp.data (), " tolerance" , SIZE) == 0 ) {
675
669
// skip 3 letters
676
- for (int i : {0 , 1 , 2 }) stream.get ();
670
+ for (int _ : {0 , 1 , 2 }) stream.get ();
677
671
stream >> mesh.tolerance ;
678
672
} else if (strncmp (tmp.data (), " epsilon =" , SIZE) == 0 ) {
679
673
double tmp;
@@ -694,14 +688,14 @@ Manifold Manifold::ImportMeshGL64(std::istream& stream) {
694
688
break ;
695
689
}
696
690
case ' v' :
697
- for (int i : {0 , 1 , 2 }) {
691
+ for (int _ : {0 , 1 , 2 }) {
698
692
double x;
699
693
stream >> x;
700
694
mesh.vertProperties .push_back (x);
701
695
}
702
696
break ;
703
697
case ' f' :
704
- for (int i : {0 , 1 , 2 }) {
698
+ for (int _ : {0 , 1 , 2 }) {
705
699
uint64_t x;
706
700
stream >> x;
707
701
mesh.triVerts .push_back (x - 1 );
0 commit comments