@@ -71,9 +71,9 @@ struct CopyFaceEdges {
71
71
SparseIndices &pXq1;
72
72
VecView<const Halfedge> halfedgesQ;
73
73
74
- void operator ()(thrust::tuple<int , int > in) {
74
+ void operator ()(thrust::tuple<size_t , size_t > in) {
75
75
int idx = 3 * thrust::get<0 >(in);
76
- int i = thrust::get<1 >(in);
76
+ size_t i = thrust::get<1 >(in);
77
77
int pX = p1q1.Get (i, inverted);
78
78
int q2 = p1q1.Get (i, !inverted);
79
79
@@ -83,7 +83,7 @@ struct CopyFaceEdges {
83
83
int a = pX;
84
84
int b = edge.IsForward () ? q1 : edge.pairedHalfedge ;
85
85
if (inverted) std::swap (a, b);
86
- pXq1.Set (idx + j , a, b);
86
+ pXq1.Set (idx + static_cast < size_t >(j) , a, b);
87
87
}
88
88
}
89
89
};
@@ -92,9 +92,9 @@ SparseIndices Filter11(const Manifold::Impl &inP, const Manifold::Impl &inQ,
92
92
const SparseIndices &p1q2, const SparseIndices &p2q1) {
93
93
ZoneScoped;
94
94
SparseIndices p1q1 (3 * p1q2.size () + 3 * p2q1.size ());
95
- for_each_n (autoPolicy (p1q2.size ()), zip (countAt (0 ), countAt (0 )), p1q2. size ( ),
96
- CopyFaceEdges<false >({p1q2, p1q1, inQ.halfedge_ }));
97
- for_each_n (autoPolicy (p2q1.size ()), zip (countAt (p1q2.size ()), countAt (0 )),
95
+ for_each_n (autoPolicy (p1q2.size ()), zip (countAt (0_z ), countAt (0_z) ),
96
+ p1q2. size (), CopyFaceEdges<false >({p1q2, p1q1, inQ.halfedge_ }));
97
+ for_each_n (autoPolicy (p2q1.size ()), zip (countAt (p1q2.size ()), countAt (0_z )),
98
98
p2q1.size (), CopyFaceEdges<true >({p2q1, p1q1, inP.halfedge_ }));
99
99
p1q1.Unique ();
100
100
return p1q1;
@@ -137,14 +137,14 @@ inline thrust::pair<int, glm::vec2> Shadow01(
137
137
138
138
// https://github.com/scandum/binary_search/blob/master/README.md
139
139
// much faster than standard binary search on large arrays
140
- int monobound_quaternary_search (VecView<const int64_t > array, int64_t key) {
140
+ size_t monobound_quaternary_search (VecView<const int64_t > array, int64_t key) {
141
141
if (array.size () == 0 ) {
142
142
return -1 ;
143
143
}
144
- unsigned int bot = 0 ;
145
- unsigned int top = array.size ();
144
+ size_t bot = 0 ;
145
+ size_t top = array.size ();
146
146
while (top >= 65536 ) {
147
- unsigned int mid = top / 4 ;
147
+ size_t mid = top / 4 ;
148
148
top -= mid * 3 ;
149
149
if (key < array[bot + mid * 2 ]) {
150
150
if (key >= array[bot + mid]) {
@@ -159,7 +159,7 @@ int monobound_quaternary_search(VecView<const int64_t> array, int64_t key) {
159
159
}
160
160
161
161
while (top > 3 ) {
162
- unsigned int mid = top / 2 ;
162
+ size_t mid = top / 2 ;
163
163
if (key >= array[bot + mid]) {
164
164
bot += mid;
165
165
}
@@ -183,7 +183,7 @@ struct Kernel11 {
183
183
VecView<const glm::vec3> normalP;
184
184
const SparseIndices &p1q1;
185
185
186
- void operator ()(thrust::tuple<int , glm::vec4 &, int &> inout) {
186
+ void operator ()(thrust::tuple<size_t , glm::vec4 &, int &> inout) {
187
187
const int p1 = p1q1.Get (thrust::get<0 >(inout), false );
188
188
const int q1 = p1q1.Get (thrust::get<0 >(inout), true );
189
189
glm::vec4 &xyzz11 = thrust::get<1 >(inout);
@@ -261,7 +261,7 @@ std::tuple<Vec<int>, Vec<glm::vec4>> Shadow11(SparseIndices &p1q1,
261
261
Vec<glm::vec4> xyzz11 (p1q1.size ());
262
262
263
263
for_each_n (autoPolicy (p1q1.size ()),
264
- zip (countAt (0 ), xyzz11.begin (), s11.begin ()), p1q1.size (),
264
+ zip (countAt (0_z ), xyzz11.begin (), s11.begin ()), p1q1.size (),
265
265
Kernel11 ({inP.vertPos_ , inQ.vertPos_ , inP.halfedge_ , inQ.halfedge_ ,
266
266
expandP, inP.vertNormal_ , p1q1}));
267
267
@@ -279,7 +279,7 @@ struct Kernel02 {
279
279
const SparseIndices &p0q2;
280
280
const bool forward;
281
281
282
- void operator ()(thrust::tuple<int , int &, float &> inout) {
282
+ void operator ()(thrust::tuple<size_t , int &, float &> inout) {
283
283
const int p0 = p0q2.Get (thrust::get<0 >(inout), !forward);
284
284
const int q2 = p0q2.Get (thrust::get<0 >(inout), forward);
285
285
int &s02 = thrust::get<1 >(inout);
@@ -351,8 +351,8 @@ std::tuple<Vec<int>, Vec<float>> Shadow02(const Manifold::Impl &inP,
351
351
Vec<float > z02 (p0q2.size ());
352
352
353
353
auto vertNormalP = forward ? inP.vertNormal_ : inQ.vertNormal_ ;
354
- for_each_n (autoPolicy (p0q2.size ()), zip ( countAt ( 0 ), s02. begin (), z02. begin ()),
355
- p0q2.size (),
354
+ for_each_n (autoPolicy (p0q2.size ()),
355
+ zip ( countAt (0_z), s02. begin (), z02. begin ()), p0q2.size (),
356
356
Kernel02 ({inP.vertPos_ , inQ.halfedge_ , inQ.vertPos_ , expandP,
357
357
vertNormalP, p0q2, forward}));
358
358
@@ -374,7 +374,7 @@ struct Kernel12 {
374
374
const bool forward;
375
375
const SparseIndices &p1q2;
376
376
377
- void operator ()(thrust::tuple<int , int &, glm::vec3 &> inout) {
377
+ void operator ()(thrust::tuple<size_t , int &, glm::vec3 &> inout) {
378
378
int p1 = p1q2.Get (thrust::get<0 >(inout), !forward);
379
379
int q2 = p1q2.Get (thrust::get<0 >(inout), forward);
380
380
int &x12 = thrust::get<1 >(inout);
@@ -394,7 +394,7 @@ struct Kernel12 {
394
394
for (int vert : {edge.startVert , edge.endVert }) {
395
395
const int64_t key = forward ? SparseIndices::EncodePQ (vert, q2)
396
396
: SparseIndices::EncodePQ (q2, vert);
397
- const int idx = monobound_quaternary_search (p0q2, key);
397
+ const size_t idx = monobound_quaternary_search (p0q2, key);
398
398
if (idx != -1 ) {
399
399
const int s = s02[idx];
400
400
x12 += s * ((vert == edge.startVert ) == forward ? 1 : -1 );
@@ -415,7 +415,7 @@ struct Kernel12 {
415
415
const int q1F = edge.IsForward () ? q1 : edge.pairedHalfedge ;
416
416
const int64_t key = forward ? SparseIndices::EncodePQ (p1, q1F)
417
417
: SparseIndices::EncodePQ (q1F, p1);
418
- const int idx = monobound_quaternary_search (p1q1, key);
418
+ const size_t idx = monobound_quaternary_search (p1q1, key);
419
419
if (idx != -1 ) { // s is implicitly zero for anything not found
420
420
const int s = s11[idx];
421
421
x12 -= s * (edge.IsForward () ? 1 : -1 );
@@ -456,7 +456,7 @@ std::tuple<Vec<int>, Vec<glm::vec3>> Intersect12(
456
456
Vec<glm::vec3> v12 (p1q2.size ());
457
457
458
458
for_each_n (
459
- autoPolicy (p1q2.size ()), zip (countAt (0 ), x12.begin (), v12.begin ()),
459
+ autoPolicy (p1q2.size ()), zip (countAt (0_z ), x12.begin (), v12.begin ()),
460
460
p1q2.size (),
461
461
Kernel12 ({p0q2.AsVec64 (), s02, z02, p1q1.AsVec64 (), s11, xyzz11,
462
462
inP.halfedge_ , inQ.halfedge_ , inP.vertPos_ , forward, p1q2}));
@@ -578,6 +578,9 @@ Boolean3::Boolean3(const Manifold::Impl &inP, const Manifold::Impl &inQ,
578
578
Intersect12 (inQ, inP, s20, p2q0, s11, p1q1, z20, xyzz11, p2q1_, false );
579
579
PRINT (" x21 size = " << x21_.size ());
580
580
581
+ if (x12_.size () + x21_.size () >= std::numeric_limits<int >::max ())
582
+ throw std::out_of_range (" mesh too large" );
583
+
581
584
Vec<int > p0 = p0q2.Copy (false );
582
585
p0q2.Resize (0 );
583
586
Vec<int > q0 = p2q0.Copy (true );
0 commit comments