40 const int PLUS1MOD3[3] = {1, 2, 0};
41 const int MINUS1MOD3[3] = {2, 0, 1};
43 #define pointmark(pt, idx) ((int*)(pt))[idx] 44 #define setpointmark(pt, value, idx) ((int*)(pt))[idx] = value 48 #define decode(ptr, tedge) \ 49 (tedge).orient = (int)((unsigned long long)(ptr) & (unsigned long long)3l); \ 50 (tedge).tri = (Ttri*)((unsigned long long)(ptr) ^ (unsigned long long)(tedge).orient) 55 #define encode(tedge) (Ttri)((unsigned long long)(tedge).tri | (unsigned long long)(tedge).orient) 60 #define sym(tedge1, tedge2) \ 61 ptr = (tedge1).tri[(tedge1).orient]; \ 64 #define symself(tedge) \ 65 ptr = (tedge).tri[(tedge).orient]; \ 69 #define lnext(tedge1, tedge2) \ 70 (tedge2).tri = (tedge1).tri; \ 71 (tedge2).orient = PLUS1MOD3[(tedge1).orient] 73 #define lnextself(tedge) (tedge).orient = PLUS1MOD3[(tedge).orient] 76 #define lprev(tedge1, tedge2) \ 77 (tedge2).tri = (tedge1).tri; \ 78 (tedge2).orient = MINUS1MOD3[(tedge1).orient] 80 #define lprevself(tedge) (tedge).orient = MINUS1MOD3[(tedge).orient] 84 #define org(tedge, pointptr) pointptr = (Tpt)(tedge).tri[PLUS1MOD3[(tedge).orient] + 3] 86 #define dest(tedge, pointptr) pointptr = (Tpt)(tedge).tri[MINUS1MOD3[(tedge).orient] + 3] 88 #define apex(tedge, pointptr) pointptr = (Tpt)(tedge).tri[(tedge).orient + 3] 90 #define setorg(tedge, pointptr) (tedge).tri[PLUS1MOD3[(tedge).orient] + 3] = (Ttri)pointptr 92 #define setdest(tedge, pointptr) (tedge).tri[MINUS1MOD3[(tedge).orient] + 3] = (Ttri)pointptr 94 #define setapex(tedge, pointptr) (tedge).tri[(tedge).orient + 3] = (Ttri)pointptr 97 #define bond(tedge1, tedge2) \ 98 (tedge1).tri[(tedge1).orient] = encode(tedge2); \ 99 (tedge2).tri[(tedge2).orient] = encode(tedge1) 102 #define tedgecopy(tedge1, tedge2) \ 103 (tedge2).tri = (tedge1).tri; \ 104 (tedge2).orient = (tedge1).orient 107 #define tedgeequal(tedge1, tedge2) \ 108 (((tedge1).tri == (tedge2).tri) && ((tedge1).orient == (tedge2).orient)) 110 #define Fast_Two_Sum_Tail(a, b, x, y) \ 114 #define Fast_Two_Sum(a, b, x, y) \ 115 x = (double)(a + b); \ 116 Fast_Two_Sum_Tail(a, b, x, y) 118 #define Two_Sum_Tail(a, b, x, y) \ 119 bvirt = (double)(x - a); \ 121 bround = b - bvirt; \ 122 around = a - avirt; \ 125 #define Two_Sum(a, b, x, y) \ 126 x = (double)(a + b); \ 127 Two_Sum_Tail(a, b, x, y) 129 #define Two_Diff_Tail(a, b, x, y) \ 130 bvirt = (double)(a - x); \ 132 bround = bvirt - b; \ 133 around = a - avirt; \ 136 #define Two_Diff(a, b, x, y) \ 137 x = (double)(a - b); \ 138 Two_Diff_Tail(a, b, x, y) 140 #define Split(splitter, a, ahi, alo) \ 141 c = (double)(splitter * a); \ 142 abig = (double)(c - a); \ 146 #define Two_Product_Tail(splitter, a, b, x, y) \ 147 Split(splitter, a, ahi, alo); \ 148 Split(splitter, b, bhi, blo); \ 149 err1 = x - (ahi * bhi); \ 150 err2 = err1 - (alo * bhi); \ 151 err3 = err2 - (ahi * blo); \ 152 y = (alo * blo) - err3 154 #define Two_Product(splitter, a, b, x, y) \ 155 x = (double)(a * b); \ 156 Two_Product_Tail(splitter, a, b, x, y) 160 #define Two_Product_Presplit(splitter, a, b, bhi, blo, x, y) \ 161 x = (double)(a * b); \ 162 Split(splitter, a, ahi, alo); \ 163 err1 = x - (ahi * bhi); \ 164 err2 = err1 - (alo * bhi); \ 165 err3 = err2 - (ahi * blo); \ 166 y = (alo * blo) - err3 168 #define Square_Tail(splitter, a, x, y) \ 169 Split(splitter, a, ahi, alo); \ 170 err1 = x - (ahi * ahi); \ 171 err3 = err1 - ((ahi + ahi) * alo); \ 172 y = (alo * alo) - err3 175 #define Square(splitter, a, x, y) \ 176 x = (double)(a * a); \ 177 Square_Tail(splitter, a, x, y) 179 #define Two_One_Sum(a1, a0, b, x2, x1, x0) \ 180 Two_Sum(a0, b, _i, x0); \ 181 Two_Sum(a1, _i, x2, x1) 183 #define Two_One_Diff(a1, a0, b, x2, x1, x0) \ 184 Two_Diff(a0, b, _i, x0); \ 185 Two_Sum(a1, _i, x2, x1) 187 #define Two_Two_Sum(a1, a0, b1, b0, x3, x2, x1, x0) \ 188 Two_One_Sum(a1, a0, b0, _j, _0, x0); \ 189 Two_One_Sum(_j, _0, b1, x3, x2, x1) 191 #define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0) \ 192 Two_One_Diff(a1, a0, b0, _j, _0, x0); \ 193 Two_One_Diff(_j, _0, b1, x3, x2, x1) 198 typedef double** Ttri;
200 typedef struct Tpool* Tmemtype;
201 typedef struct Tedge* Tedgetype;
212 : firstblock(nullptr)
215 , deaditemstack(nullptr)
220 int **firstblock, **nowblock;
221 int *nextitem, *deaditemstack;
222 int **pathblock, *pathitem;
225 int itemsperblock = 0;
226 int itemsfirstblock = 0;
229 int unallocateditems = 0;
230 int pathitemsleft = 0;
235 enum Twordtype { TPOINTER, TFLOATINGPOINT };
244 Ttri* m_dummytribase;
247 int m_pointmarkindex;
250 double m_resulterrbound;
251 double m_ccwerrboundA, m_ccwerrboundB, m_ccwerrboundC;
252 double m_iccerrboundA, m_iccerrboundB, m_iccerrboundC;
261 static void triAlternateAxes(Tpt*,
int,
int);
262 static double triCounterClockwise(Tpt, Tpt, Tpt, TriVars&);
263 static double triCounterClockwiseAdapt(Tpt, Tpt, Tpt,
double, TriVars&);
264 static bool triDivConqDelaunay(TriVars&);
265 static bool triDivConqRecurse(Tpt*,
int,
int, Tedgetype, Tedgetype, TriVars&);
266 static void triDummyInit(
int, TriVars&);
267 static double triEstimate(
int,
double*);
268 static void triExactInit(TriVars&);
269 static int triFastExpansionSumZeroElim(
int,
double*,
int,
double*,
double*);
272 static double triInCircle(Tpt, Tpt, Tpt, Tpt, TriVars&);
273 static double triInCircleAdapt(Tpt, Tpt, Tpt, Tpt,
double, TriVars&);
274 static void triInitTrianglePool(TriVars&);
275 static bool triMakeTriangle(Tedgetype, TriVars&);
276 static bool triMergeHulls(Tedgetype, Tedgetype, Tedgetype, Tedgetype,
int, TriVars&);
277 static void triNumberNodes(TriVars&);
278 static void triPointMedian(Tpt*,
int,
int,
int);
279 static void triPointSort(Tpt*,
int);
280 static Tpt triPointTraverse(TriVars&);
281 static int* triPoolAlloc(Tmemtype);
282 static void triPoolDealloc(Tmemtype,
int*);
283 static void triPoolDeinit(Tmemtype);
284 static bool triPoolInit(Tmemtype,
int,
int,
int,
int);
285 static void triPoolRestart(Tmemtype);
286 static unsigned long triRandomnation(
unsigned int);
287 static void triRemoveGhosts(Tedgetype, TriVars&);
288 static int triScaleExpansionZeroElim(
int,
double*,
double,
double*, TriVars&);
289 static void triTraversalInit(Tmemtype);
290 static int* triTraverse(Tmemtype);
291 static void triTriangleDealloc(Ttri*, TriVars&);
292 static Ttri* triTriangleTraverse(TriVars&);
305 static void triAlternateAxes(Tpt* sortarray,
int arraysize,
int axis)
308 divider = arraysize >> 1;
316 triPointMedian(sortarray, arraysize, divider, axis);
318 if (arraysize - divider >= 2)
321 triAlternateAxes(sortarray, divider, 1 - axis);
322 triAlternateAxes(&sortarray[divider], arraysize - divider, 1 - axis);
330 static double triCounterClockwise(Tpt pa, Tpt pb, Tpt pc, TriVars& t)
332 double detleft, detright, det, detsum, errbound;
334 detleft = (pa[0] - pc[0]) * (pb[1] - pc[1]);
335 detright = (pa[1] - pc[1]) * (pb[0] - pc[0]);
336 det = detleft - detright;
343 detsum = detleft + detright;
345 else if (detleft < 0.0)
350 detsum = -detleft - detright;
355 errbound = t.m_ccwerrboundA * detsum;
356 if ((det >= errbound) || (-det >= errbound))
359 return triCounterClockwiseAdapt(pa, pb, pc, detsum, t);
376 static double triCounterClockwiseAdapt(Tpt pa, Tpt pb, Tpt pc,
double detsum, TriVars& t)
378 int C1length, C2length, Dlength;
379 double acx, acy, bcx, bcy;
380 double acxtail, acytail, bcxtail, bcytail;
381 double detleft, detright;
382 double detlefttail, detrighttail;
383 double det, errbound;
384 double B[4], C1[8], C2[12], D[16];
388 double s1, t1, s0, t0;
389 double bvirt, avirt, bround, around;
390 double c, abig, ahi, alo, bhi, blo;
391 double err1, err2, err3;
394 acx = (double)(pa[0] - pc[0]);
395 bcx = (double)(pb[0] - pc[0]);
396 acy = (double)(pa[1] - pc[1]);
397 bcy = (double)(pb[1] - pc[1]);
399 Two_Product(t.m_splitter, acx, bcy, detleft, detlefttail);
400 Two_Product(t.m_splitter, acy, bcx, detright, detrighttail);
402 Two_Two_Diff(detleft, detlefttail, detright, detrighttail, B3, B[2], B[1], B[0]);
405 det = triEstimate(4, B);
406 errbound = t.m_ccwerrboundB * detsum;
407 if ((det >= errbound) || (-det >= errbound))
410 Two_Diff_Tail(pa[0], pc[0], acx, acxtail);
411 Two_Diff_Tail(pb[0], pc[0], bcx, bcxtail);
412 Two_Diff_Tail(pa[1], pc[1], acy, acytail);
413 Two_Diff_Tail(pb[1], pc[1], bcy, bcytail);
415 if ((acxtail == 0.0) && (acytail == 0.0) && (bcxtail == 0.0) && (bcytail == 0.0))
420 errbound = t.m_ccwerrboundC * detsum + t.m_resulterrbound * fabs(det);
421 det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
422 if ((det >= errbound) || (-det >= errbound))
425 Two_Product(t.m_splitter, acxtail, bcy, s1, s0);
426 Two_Product(t.m_splitter, acytail, bcx, t1, t0);
427 Two_Two_Diff(s1, s0, t1, t0, u3, u[2], u[1], u[0]);
429 C1length = triFastExpansionSumZeroElim(4, B, 4, u, C1);
431 Two_Product(t.m_splitter, acx, bcytail, s1, s0);
432 Two_Product(t.m_splitter, acy, bcxtail, t1, t0);
433 Two_Two_Diff(s1, s0, t1, t0, u3, u[2], u[1], u[0]);
435 C2length = triFastExpansionSumZeroElim(C1length, C1, 4, u, C2);
437 Two_Product(t.m_splitter, acxtail, bcytail, s1, s0);
438 Two_Product(t.m_splitter, acytail, bcxtail, t1, t0);
439 Two_Two_Diff(s1, s0, t1, t0, u3, u[2], u[1], u[0]);
441 Dlength = triFastExpansionSumZeroElim(C2length, C2, 4, u, D);
443 return (D[Dlength - 1]);
452 static bool triDivConqDelaunay(TriVars& t)
456 Tedge hullleft = {0}, hullright = {0};
458 int size = t.m_numpoints * (int)
sizeof(Tpt);
460 sortarray = (Tpt*)malloc((
unsigned int)size);
462 if (sortarray ==
nullptr)
464 std::string s =
"malloc failed: ";
469 triTraversalInit(&t.m_points);
470 for (i = 0; i < t.m_numpoints; i++)
472 sortarray[i] = triPointTraverse(t);
475 triPointSort(sortarray, t.m_numpoints);
478 for (j = 1; j < t.m_numpoints; j++)
480 if ((sortarray[i][0] == sortarray[j][0] && sortarray[i][1] == sortarray[j][1]))
487 sortarray[i] = sortarray[j];
499 else if (i - divider >= 2)
503 triAlternateAxes(sortarray, divider, 1);
505 triAlternateAxes(&sortarray[divider], i - divider, 1);
508 bool canTriangulate = triDivConqRecurse(sortarray, i, 0, &hullleft, &hullright, t);
512 "Triangulation cannot be completed due to memory constraints. " 513 "A suggested work-around would be to divide the scattersets, " 514 "triangulate them seperately, then merge back into one scatterset. " 515 "It is suggested that the scatter set be broken into contiguous regions " 516 "of less than 5000000 points.";
518 triPoolDeinit(&t.m_triangles);
520 if (t.m_dummytribase)
522 free(t.m_dummytribase);
528 triRemoveGhosts(&hullleft, t);
546 static bool triDivConqRecurse(Tpt* sortarray,
555 Tedge midtri, tri1, tri2, tri3, innerleft, innerright;
556 bool canMakeTriangles =
true;
562 canMakeTriangles &= triMakeTriangle(farleft, t);
563 canMakeTriangles &= triMakeTriangle(farright, t);
564 if (!canMakeTriangles)
568 setorg(*farleft, sortarray[0]);
569 setdest(*farleft, sortarray[1]);
571 setorg(*farright, sortarray[1]);
572 setdest(*farright, sortarray[0]);
574 bond(*farleft, *farright);
576 lnextself(*farright);
577 bond(*farleft, *farright);
579 lnextself(*farright);
580 bond(*farleft, *farright);
582 lprev(*farright, *farleft);
586 else if (vertices == 3)
592 canMakeTriangles &= triMakeTriangle(&midtri, t);
593 canMakeTriangles &= triMakeTriangle(&tri1, t);
594 canMakeTriangles &= triMakeTriangle(&tri2, t);
595 canMakeTriangles &= triMakeTriangle(&tri3, t);
596 if (!canMakeTriangles)
600 area = triCounterClockwise(sortarray[0], sortarray[1], sortarray[2], t);
604 setorg(midtri, sortarray[0]);
605 setdest(midtri, sortarray[1]);
606 setorg(tri1, sortarray[1]);
607 setdest(tri1, sortarray[0]);
608 setorg(tri2, sortarray[2]);
609 setdest(tri2, sortarray[1]);
610 setorg(tri3, sortarray[1]);
611 setdest(tri3, sortarray[2]);
628 tedgecopy(tri1, *farleft);
630 tedgecopy(tri2, *farright);
635 setorg(midtri, sortarray[0]);
636 setdest(tri1, sortarray[0]);
637 setorg(tri3, sortarray[0]);
642 setdest(midtri, sortarray[1]);
643 setorg(tri1, sortarray[1]);
644 setdest(tri2, sortarray[1]);
645 setapex(midtri, sortarray[2]);
646 setorg(tri2, sortarray[2]);
647 setdest(tri3, sortarray[2]);
652 setdest(midtri, sortarray[2]);
653 setorg(tri1, sortarray[2]);
654 setdest(tri2, sortarray[2]);
655 setapex(midtri, sortarray[1]);
656 setorg(tri2, sortarray[1]);
657 setdest(tri3, sortarray[1]);
675 tedgecopy(tri1, *farleft);
679 tedgecopy(tri2, *farright);
683 lnext(*farleft, *farright);
691 divider = vertices >> 1;
693 canMakeTriangles = triDivConqRecurse(sortarray, divider, 1 - axis, farleft, &innerleft, t);
694 if (!canMakeTriangles)
698 canMakeTriangles = triDivConqRecurse(&sortarray[divider], vertices - divider, 1 - axis,
699 &innerright, farright, t);
700 if (!canMakeTriangles)
705 canMakeTriangles = triMergeHulls(farleft, &innerleft, &innerright, farright, axis, t);
706 if (canMakeTriangles)
729 static void triDummyInit(
int trianglewords, TriVars& t)
731 unsigned long long alignptr;
733 t.m_dummytribase = (Ttri*)malloc(trianglewords *
sizeof(Ttri) + t.m_triangles.alignbytes);
734 if (t.m_dummytribase ==
nullptr)
736 std::string s =
"malloc failed: ";
743 alignptr = (
unsigned long long)t.m_dummytribase;
744 t.m_dummytri = (Ttri*)(alignptr + (
unsigned long long)t.m_triangles.alignbytes -
745 (alignptr % (
unsigned long long)t.m_triangles.alignbytes));
750 t.m_dummytri[0] = (Ttri)t.m_dummytri;
751 t.m_dummytri[1] = (Ttri)t.m_dummytri;
752 t.m_dummytri[2] = (Ttri)t.m_dummytri;
754 t.m_dummytri[3] =
nullptr;
755 t.m_dummytri[4] =
nullptr;
756 t.m_dummytri[5] =
nullptr;
763 static double triEstimate(
int elen,
double* e)
769 for (eindex = 1; eindex < elen; eindex++)
791 static void triExactInit(TriVars& t)
793 double half, check, lastcheck, epsilon;
799 epsilon = check = 1.0;
810 every_other = !every_other;
811 check = 1.0 + epsilon;
812 }
while ((check != 1.0) && (check != lastcheck));
815 t.m_resulterrbound = (3.0 + 8.0 * epsilon) * epsilon;
816 t.m_ccwerrboundA = (3.0 + 16.0 * epsilon) * epsilon;
817 t.m_ccwerrboundB = (2.0 + 12.0 * epsilon) * epsilon;
818 t.m_ccwerrboundC = (9.0 + 64.0 * epsilon) * epsilon * epsilon;
819 t.m_iccerrboundA = (10.0 + 96.0 * epsilon) * epsilon;
820 t.m_iccerrboundB = (4.0 + 48.0 * epsilon) * epsilon;
821 t.m_iccerrboundC = (44.0 + 576.0 * epsilon) * epsilon * epsilon;
834 static int triFastExpansionSumZeroElim(
int elen,
double* e,
int flen,
double* f,
double* h)
836 int eindex, findex, hindex;
837 double Q, Qnew, hh, bvirt, avirt, bround, around, enow, fnow;
842 if ((fnow > enow) == (fnow > -enow))
853 if ((eindex < elen) && (findex < flen))
855 if ((fnow > enow) == (fnow > -enow))
857 Fast_Two_Sum(enow, Q, Qnew, hh);
862 Fast_Two_Sum(fnow, Q, Qnew, hh);
868 while ((eindex < elen) && (findex < flen))
870 if ((fnow > enow) == (fnow > -enow))
872 Two_Sum(Q, enow, Qnew, hh);
881 Two_Sum(Q, fnow, Qnew, hh);
893 while (eindex < elen)
895 Two_Sum(Q, enow, Qnew, hh);
901 while (findex < flen)
903 Two_Sum(Q, fnow, Qnew, hh);
909 if ((Q != 0.0) || (hindex == 0))
924 Progress prog(
"Triangulating Points");
926 a_Client.PrepareToReceiveTriangles();
927 double triCount(0.0);
928 double total =
static_cast<double>(a_Client.GetNPoints());
930 triTraversalInit(&t.m_triangles);
931 triangleloop.tri = triTriangleTraverse(t);
932 triangleloop.orient = 0;
933 while (triangleloop.tri !=
nullptr)
936 org(triangleloop, p1);
937 dest(triangleloop, p2);
938 apex(triangleloop, p3);
939 id1 = pointmark(p1, t.m_pointmarkindex);
940 id2 = pointmark(p2, t.m_pointmarkindex);
941 id3 = pointmark(p3, t.m_pointmarkindex);
944 a_Client.ReceiveTriangle(id1, id2, id3);
946 prog.ProgressStatus(std::min(1.0, triCount / total));
948 triangleloop.tri = triTriangleTraverse(t);
958 #define POINTPERBLOCK 4092 965 t.m_pointmarkindex = (3 *
sizeof(double) +
sizeof(
int) - 1) /
sizeof(
int);
966 pointsize = (t.m_pointmarkindex + 1) *
sizeof(
int);
970 t.m_numpoints = a_Client.GetNPoints();
972 if (!triPoolInit(&t.m_points, pointsize, POINTPERBLOCK,
973 t.m_numpoints > POINTPERBLOCK ? t.m_numpoints : POINTPERBLOCK, 0))
979 for (i = 0; i < t.m_numpoints; i++)
981 pointloop = (Tpt)triPoolAlloc(&t.m_points);
984 loc = a_Client.GetLocation();
985 pointloop[0] = loc.
x;
986 pointloop[1] = loc.
y;
989 pointloop[2] = a_Client.GetID();
991 setpointmark(pointloop, 0, t.m_pointmarkindex);
994 a_Client.IncrementPoint();
1003 static double triInCircle(Tpt pa, Tpt pb, Tpt pc, Tpt pd, TriVars& t)
1005 double adx, bdx, cdx, ady, bdy, cdy;
1006 double bdxcdy, cdxbdy, cdxady, adxcdy, adxbdy, bdxady;
1007 double alift, blift, clift;
1009 double permanent, errbound;
1011 adx = pa[0] - pd[0];
1012 bdx = pb[0] - pd[0];
1013 cdx = pc[0] - pd[0];
1014 ady = pa[1] - pd[1];
1015 bdy = pb[1] - pd[1];
1016 cdy = pc[1] - pd[1];
1020 alift = adx * adx + ady * ady;
1024 blift = bdx * bdx + bdy * bdy;
1028 clift = cdx * cdx + cdy * cdy;
1030 det = alift * (bdxcdy - cdxbdy) + blift * (cdxady - adxcdy) + clift * (adxbdy - bdxady);
1032 permanent = (fabs(bdxcdy) + fabs(cdxbdy)) * alift + (fabs(cdxady) + fabs(adxcdy)) * blift +
1033 (fabs(adxbdy) + fabs(bdxady)) * clift;
1034 errbound = t.m_iccerrboundA * permanent;
1035 if ((det > errbound) || (-det > errbound))
1038 return triInCircleAdapt(pa, pb, pc, pd, permanent, t);
1054 static double triInCircleAdapt(Tpt pa, Tpt pb, Tpt pc, Tpt pd,
double permanent, TriVars& t)
1056 int axbclen, axxbclen, aybclen, ayybclen, alen;
1057 int bxcalen, bxxcalen, bycalen, byycalen, blen;
1058 int cxablen, cxxablen, cyablen, cyyablen, clen;
1061 double adx, bdx, cdx, ady, bdy, cdy;
1062 double det, errbound;
1063 double bdxcdy1, cdxbdy1, cdxady1, adxcdy1, adxbdy1, bdxady1;
1064 double bdxcdy0, cdxbdy0, cdxady0, adxcdy0, adxbdy0, bdxady0;
1065 double bc[4], ca[4], ab[4];
1066 double bc3, ca3, ab3;
1067 double axbc[8], axxbc[16], aybc[8], ayybc[16], adet[32];
1068 double bxca[8], bxxca[16], byca[8], byyca[16], bdet[32];
1069 double cxab[8], cxxab[16], cyab[8], cyyab[16], cdet[32];
1071 double fin1[1152], fin2[1152];
1072 double *finnow, *finother, *finswap;
1074 int temp8len, temp16alen, temp16blen, temp16clen;
1075 int temp32alen, temp32blen, temp48len, temp64len;
1076 int axtbblen, axtcclen, aytbblen, aytcclen;
1077 int bxtaalen, bxtcclen, bytaalen, bytcclen;
1078 int cxtaalen, cxtbblen, cytaalen, cytbblen;
1079 int axtbclen = 0, aytbclen = 0, bxtcalen = 0;
1080 int bytcalen = 0, cxtablen = 0, cytablen = 0;
1081 int axtbctlen, bxtcatlen, cxtabtlen;
1082 int aytbctlen, bytcatlen, cytabtlen;
1083 int axtbcttlen, bxtcattlen, cxtabttlen;
1084 int aytbcttlen, bytcattlen, cytabttlen;
1085 int abtlen, bctlen, catlen;
1086 int abttlen, bcttlen, cattlen;
1087 double adxtail, bdxtail, cdxtail, adytail, bdytail, cdytail;
1088 double adxadx1, adyady1, bdxbdx1, bdybdy1, cdxcdx1, cdycdy1;
1089 double adxadx0, adyady0, bdxbdx0, bdybdy0, cdxcdx0, cdycdy0;
1090 double aa[4], bb[4], cc[4];
1091 double aa3, bb3, cc3;
1096 double temp8[8], temp16a[16], temp16b[16], temp16c[16];
1097 double temp32a[32], temp32b[32], temp48[48], temp64[64];
1098 double axtbb[8], axtcc[8], aytbb[8], aytcc[8];
1099 double bxtaa[8], bxtcc[8], bytaa[8], bytcc[8];
1100 double cxtaa[8], cxtbb[8], cytaa[8], cytbb[8];
1101 double axtbc[8], aytbc[8], bxtca[8], bytca[8], cxtab[8], cytab[8];
1102 double axtbct[16], bxtcat[16], cxtabt[16];
1103 double aytbct[16], bytcat[16], cytabt[16];
1104 double axtbctt[8], aytbctt[8], bxtcatt[8];
1105 double bytcatt[8], cxtabtt[8], cytabtt[8];
1106 double abt[8], bct[8], cat[8];
1107 double abtt[4], bctt[4], catt[4];
1108 double abtt3, bctt3, catt3;
1112 double avirt, bround, around;
1114 double abig, ahi, alo, bhi, blo;
1115 double err1, err2, err3;
1119 memset(bc, 0, 4 *
sizeof(
double));
1120 memset(ca, 0, 4 *
sizeof(
double));
1121 memset(ab, 0, 4 *
sizeof(
double));
1123 memset(axbc, 0, 8 *
sizeof(
double));
1124 memset(axxbc, 0, 16 *
sizeof(
double));
1125 memset(aybc, 0, 8 *
sizeof(
double));
1126 memset(ayybc, 0, 16 *
sizeof(
double));
1127 memset(adet, 0, 32 *
sizeof(
double));
1129 memset(bxca, 0, 8 *
sizeof(
double));
1130 memset(bxxca, 0, 16 *
sizeof(
double));
1131 memset(byca, 0, 8 *
sizeof(
double));
1132 memset(byyca, 0, 16 *
sizeof(
double));
1133 memset(bdet, 0, 32 *
sizeof(
double));
1135 memset(cxab, 0, 8 *
sizeof(
double));
1136 memset(cxxab, 0, 16 *
sizeof(
double));
1137 memset(cyab, 0, 8 *
sizeof(
double));
1138 memset(cyyab, 0, 16 *
sizeof(
double));
1139 memset(cdet, 0, 32 *
sizeof(
double));
1141 memset(abdet, 0, 64 *
sizeof(
double));
1142 memset(fin1, 0, 1152 *
sizeof(
double));
1143 memset(fin2, 0, 1152 *
sizeof(
double));
1145 memset(aa, 0, 4 *
sizeof(
double));
1146 memset(bb, 0, 4 *
sizeof(
double));
1147 memset(cc, 0, 4 *
sizeof(
double));
1149 memset(u, 0, 4 *
sizeof(
double));
1150 memset(v, 0, 4 *
sizeof(
double));
1152 memset(temp8, 0, 8 *
sizeof(
double));
1153 memset(temp16a, 0, 16 *
sizeof(
double));
1154 memset(temp16b, 0, 16 *
sizeof(
double));
1155 memset(temp16c, 0, 16 *
sizeof(
double));
1157 memset(temp32a, 0, 32 *
sizeof(
double));
1158 memset(temp32b, 0, 32 *
sizeof(
double));
1159 memset(temp48, 0, 48 *
sizeof(
double));
1160 memset(temp64, 0, 64 *
sizeof(
double));
1162 memset(axtbb, 0, 8 *
sizeof(
double));
1163 memset(axtcc, 0, 8 *
sizeof(
double));
1164 memset(aytbb, 0, 8 *
sizeof(
double));
1165 memset(aytcc, 0, 8 *
sizeof(
double));
1167 memset(bxtaa, 0, 8 *
sizeof(
double));
1168 memset(bxtcc, 0, 8 *
sizeof(
double));
1169 memset(bytaa, 0, 8 *
sizeof(
double));
1170 memset(bytcc, 0, 8 *
sizeof(
double));
1172 memset(cxtaa, 0, 8 *
sizeof(
double));
1173 memset(cxtbb, 0, 8 *
sizeof(
double));
1174 memset(cytaa, 0, 8 *
sizeof(
double));
1175 memset(cytbb, 0, 8 *
sizeof(
double));
1177 memset(axtbc, 0, 8 *
sizeof(
double));
1178 memset(aytbc, 0, 8 *
sizeof(
double));
1179 memset(bxtca, 0, 8 *
sizeof(
double));
1180 memset(bytca, 0, 8 *
sizeof(
double));
1181 memset(cxtab, 0, 8 *
sizeof(
double));
1182 memset(cytab, 0, 8 *
sizeof(
double));
1184 memset(axtbct, 0, 16 *
sizeof(
double));
1185 memset(bxtcat, 0, 16 *
sizeof(
double));
1186 memset(cxtabt, 0, 16 *
sizeof(
double));
1188 memset(aytbct, 0, 16 *
sizeof(
double));
1189 memset(bytcat, 0, 16 *
sizeof(
double));
1190 memset(cytabt, 0, 16 *
sizeof(
double));
1192 memset(axtbctt, 0, 8 *
sizeof(
double));
1193 memset(aytbctt, 0, 8 *
sizeof(
double));
1194 memset(bxtcatt, 0, 8 *
sizeof(
double));
1196 memset(bytcatt, 0, 8 *
sizeof(
double));
1197 memset(cxtabtt, 0, 8 *
sizeof(
double));
1198 memset(cytabtt, 0, 8 *
sizeof(
double));
1200 memset(abt, 0, 8 *
sizeof(
double));
1201 memset(bct, 0, 8 *
sizeof(
double));
1202 memset(cat, 0, 8 *
sizeof(
double));
1204 memset(abtt, 0, 4 *
sizeof(
double));
1205 memset(bctt, 0, 4 *
sizeof(
double));
1206 memset(catt, 0, 4 *
sizeof(
double));
1208 adx = (double)(pa[0] - pd[0]);
1209 bdx = (double)(pb[0] - pd[0]);
1210 cdx = (double)(pc[0] - pd[0]);
1211 ady = (double)(pa[1] - pd[1]);
1212 bdy = (double)(pb[1] - pd[1]);
1213 cdy = (double)(pc[1] - pd[1]);
1215 Two_Product(t.m_splitter, bdx, cdy, bdxcdy1, bdxcdy0);
1216 Two_Product(t.m_splitter, cdx, bdy, cdxbdy1, cdxbdy0);
1217 Two_Two_Diff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, bc3, bc[2], bc[1], bc[0]);
1219 axbclen = triScaleExpansionZeroElim(4, bc, adx, axbc, t);
1220 axxbclen = triScaleExpansionZeroElim(axbclen, axbc, adx, axxbc, t);
1221 aybclen = triScaleExpansionZeroElim(4, bc, ady, aybc, t);
1222 ayybclen = triScaleExpansionZeroElim(aybclen, aybc, ady, ayybc, t);
1223 alen = triFastExpansionSumZeroElim(axxbclen, axxbc, ayybclen, ayybc, adet);
1225 Two_Product(t.m_splitter, cdx, ady, cdxady1, cdxady0);
1226 Two_Product(t.m_splitter, adx, cdy, adxcdy1, adxcdy0);
1227 Two_Two_Diff(cdxady1, cdxady0, adxcdy1, adxcdy0, ca3, ca[2], ca[1], ca[0]);
1229 bxcalen = triScaleExpansionZeroElim(4, ca, bdx, bxca, t);
1230 bxxcalen = triScaleExpansionZeroElim(bxcalen, bxca, bdx, bxxca, t);
1231 bycalen = triScaleExpansionZeroElim(4, ca, bdy, byca, t);
1232 byycalen = triScaleExpansionZeroElim(bycalen, byca, bdy, byyca, t);
1233 blen = triFastExpansionSumZeroElim(bxxcalen, bxxca, byycalen, byyca, bdet);
1235 Two_Product(t.m_splitter, adx, bdy, adxbdy1, adxbdy0);
1236 Two_Product(t.m_splitter, bdx, ady, bdxady1, bdxady0);
1237 Two_Two_Diff(adxbdy1, adxbdy0, bdxady1, bdxady0, ab3, ab[2], ab[1], ab[0]);
1239 cxablen = triScaleExpansionZeroElim(4, ab, cdx, cxab, t);
1240 cxxablen = triScaleExpansionZeroElim(cxablen, cxab, cdx, cxxab, t);
1241 cyablen = triScaleExpansionZeroElim(4, ab, cdy, cyab, t);
1242 cyyablen = triScaleExpansionZeroElim(cyablen, cyab, cdy, cyyab, t);
1243 clen = triFastExpansionSumZeroElim(cxxablen, cxxab, cyyablen, cyyab, cdet);
1245 ablen = triFastExpansionSumZeroElim(alen, adet, blen, bdet, abdet);
1246 finlength = triFastExpansionSumZeroElim(ablen, abdet, clen, cdet, fin1);
1248 det = triEstimate(finlength, fin1);
1249 errbound = t.m_iccerrboundB * permanent;
1250 if ((det >= errbound) || (-det >= errbound))
1253 Two_Diff_Tail(pa[0], pd[0], adx, adxtail);
1254 Two_Diff_Tail(pa[1], pd[1], ady, adytail);
1255 Two_Diff_Tail(pb[0], pd[0], bdx, bdxtail);
1256 Two_Diff_Tail(pb[1], pd[1], bdy, bdytail);
1257 Two_Diff_Tail(pc[0], pd[0], cdx, cdxtail);
1258 Two_Diff_Tail(pc[1], pd[1], cdy, cdytail);
1259 if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) && (adytail == 0.0) &&
1260 (bdytail == 0.0) && (cdytail == 0.0))
1265 errbound = t.m_iccerrboundC * permanent + t.m_resulterrbound * fabs(det);
1267 ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) +
1268 2.0 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx)) +
1269 ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) +
1270 2.0 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx)) +
1271 ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) +
1272 2.0 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx));
1273 if ((det >= errbound) || (-det >= errbound))
1279 if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0))
1281 Square(t.m_splitter, adx, adxadx1, adxadx0);
1282 Square(t.m_splitter, ady, adyady1, adyady0);
1283 Two_Two_Sum(adxadx1, adxadx0, adyady1, adyady0, aa3, aa[2], aa[1], aa[0]);
1286 if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0))
1288 Square(t.m_splitter, bdx, bdxbdx1, bdxbdx0);
1289 Square(t.m_splitter, bdy, bdybdy1, bdybdy0);
1290 Two_Two_Sum(bdxbdx1, bdxbdx0, bdybdy1, bdybdy0, bb3, bb[2], bb[1], bb[0]);
1293 if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0))
1295 Square(t.m_splitter, cdx, cdxcdx1, cdxcdx0);
1296 Square(t.m_splitter, cdy, cdycdy1, cdycdy0);
1297 Two_Two_Sum(cdxcdx1, cdxcdx0, cdycdy1, cdycdy0, cc3, cc[2], cc[1], cc[0]);
1303 axtbclen = triScaleExpansionZeroElim(4, bc, adxtail, axtbc, t);
1304 temp16alen = triScaleExpansionZeroElim(axtbclen, axtbc, 2.0 * adx, temp16a, t);
1306 axtcclen = triScaleExpansionZeroElim(4, cc, adxtail, axtcc, t);
1307 temp16blen = triScaleExpansionZeroElim(axtcclen, axtcc, bdy, temp16b, t);
1309 axtbblen = triScaleExpansionZeroElim(4, bb, adxtail, axtbb, t);
1310 temp16clen = triScaleExpansionZeroElim(axtbblen, axtbb, -cdy, temp16c, t);
1312 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1313 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1314 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1321 aytbclen = triScaleExpansionZeroElim(4, bc, adytail, aytbc, t);
1322 temp16alen = triScaleExpansionZeroElim(aytbclen, aytbc, 2.0 * ady, temp16a, t);
1324 aytbblen = triScaleExpansionZeroElim(4, bb, adytail, aytbb, t);
1325 temp16blen = triScaleExpansionZeroElim(aytbblen, aytbb, cdx, temp16b, t);
1327 aytcclen = triScaleExpansionZeroElim(4, cc, adytail, aytcc, t);
1328 temp16clen = triScaleExpansionZeroElim(aytcclen, aytcc, -bdx, temp16c, t);
1330 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1331 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1332 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1339 bxtcalen = triScaleExpansionZeroElim(4, ca, bdxtail, bxtca, t);
1340 temp16alen = triScaleExpansionZeroElim(bxtcalen, bxtca, 2.0 * bdx, temp16a, t);
1342 bxtaalen = triScaleExpansionZeroElim(4, aa, bdxtail, bxtaa, t);
1343 temp16blen = triScaleExpansionZeroElim(bxtaalen, bxtaa, cdy, temp16b, t);
1345 bxtcclen = triScaleExpansionZeroElim(4, cc, bdxtail, bxtcc, t);
1346 temp16clen = triScaleExpansionZeroElim(bxtcclen, bxtcc, -ady, temp16c, t);
1348 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1349 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1350 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1357 bytcalen = triScaleExpansionZeroElim(4, ca, bdytail, bytca, t);
1358 temp16alen = triScaleExpansionZeroElim(bytcalen, bytca, 2.0 * bdy, temp16a, t);
1360 bytcclen = triScaleExpansionZeroElim(4, cc, bdytail, bytcc, t);
1361 temp16blen = triScaleExpansionZeroElim(bytcclen, bytcc, adx, temp16b, t);
1363 bytaalen = triScaleExpansionZeroElim(4, aa, bdytail, bytaa, t);
1364 temp16clen = triScaleExpansionZeroElim(bytaalen, bytaa, -cdx, temp16c, t);
1366 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1367 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1368 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1375 cxtablen = triScaleExpansionZeroElim(4, ab, cdxtail, cxtab, t);
1376 temp16alen = triScaleExpansionZeroElim(cxtablen, cxtab, 2.0 * cdx, temp16a, t);
1378 cxtbblen = triScaleExpansionZeroElim(4, bb, cdxtail, cxtbb, t);
1379 temp16blen = triScaleExpansionZeroElim(cxtbblen, cxtbb, ady, temp16b, t);
1381 cxtaalen = triScaleExpansionZeroElim(4, aa, cdxtail, cxtaa, t);
1382 temp16clen = triScaleExpansionZeroElim(cxtaalen, cxtaa, -bdy, temp16c, t);
1384 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1385 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1386 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1393 cytablen = triScaleExpansionZeroElim(4, ab, cdytail, cytab, t);
1394 temp16alen = triScaleExpansionZeroElim(cytablen, cytab, 2.0 * cdy, temp16a, t);
1396 cytaalen = triScaleExpansionZeroElim(4, aa, cdytail, cytaa, t);
1397 temp16blen = triScaleExpansionZeroElim(cytaalen, cytaa, bdx, temp16b, t);
1399 cytbblen = triScaleExpansionZeroElim(4, bb, cdytail, cytbb, t);
1400 temp16clen = triScaleExpansionZeroElim(cytbblen, cytbb, -adx, temp16c, t);
1402 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1403 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1404 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1410 if ((adxtail != 0.0) || (adytail != 0.0))
1412 if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0))
1414 Two_Product(t.m_splitter, bdxtail, cdy, ti1, ti0);
1415 Two_Product(t.m_splitter, bdx, cdytail, tj1, tj0);
1416 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
1419 Two_Product(t.m_splitter, cdxtail, negate, ti1, ti0);
1421 Two_Product(t.m_splitter, cdx, negate, tj1, tj0);
1422 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
1424 bctlen = triFastExpansionSumZeroElim(4, u, 4, v, bct);
1426 Two_Product(t.m_splitter, bdxtail, cdytail, ti1, ti0);
1427 Two_Product(t.m_splitter, cdxtail, bdytail, tj1, tj0);
1428 Two_Two_Diff(ti1, ti0, tj1, tj0, bctt3, bctt[2], bctt[1], bctt[0]);
1442 temp16alen = triScaleExpansionZeroElim(axtbclen, axtbc, adxtail, temp16a, t);
1443 axtbctlen = triScaleExpansionZeroElim(bctlen, bct, adxtail, axtbct, t);
1444 temp32alen = triScaleExpansionZeroElim(axtbctlen, axtbct, 2.0 * adx, temp32a, t);
1445 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1446 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1452 temp8len = triScaleExpansionZeroElim(4, cc, adxtail, temp8, t);
1453 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, bdytail, temp16a, t);
1454 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1461 temp8len = triScaleExpansionZeroElim(4, bb, -adxtail, temp8, t);
1462 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, cdytail, temp16a, t);
1463 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1469 temp32alen = triScaleExpansionZeroElim(axtbctlen, axtbct, adxtail, temp32a, t);
1470 axtbcttlen = triScaleExpansionZeroElim(bcttlen, bctt, adxtail, axtbctt, t);
1471 temp16alen = triScaleExpansionZeroElim(axtbcttlen, axtbctt, 2.0 * adx, temp16a, t);
1472 temp16blen = triScaleExpansionZeroElim(axtbcttlen, axtbctt, adxtail, temp16b, t);
1473 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1474 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1475 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1482 temp16alen = triScaleExpansionZeroElim(aytbclen, aytbc, adytail, temp16a, t);
1483 aytbctlen = triScaleExpansionZeroElim(bctlen, bct, adytail, aytbct, t);
1484 temp32alen = triScaleExpansionZeroElim(aytbctlen, aytbct, 2.0 * ady, temp32a, t);
1485 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1486 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1491 temp32alen = triScaleExpansionZeroElim(aytbctlen, aytbct, adytail, temp32a, t);
1492 aytbcttlen = triScaleExpansionZeroElim(bcttlen, bctt, adytail, aytbctt, t);
1493 temp16alen = triScaleExpansionZeroElim(aytbcttlen, aytbctt, 2.0 * ady, temp16a, t);
1494 temp16blen = triScaleExpansionZeroElim(aytbcttlen, aytbctt, adytail, temp16b, t);
1495 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1496 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1497 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1503 if ((bdxtail != 0.0) || (bdytail != 0.0))
1505 if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0))
1507 Two_Product(t.m_splitter, cdxtail, ady, ti1, ti0);
1508 Two_Product(t.m_splitter, cdx, adytail, tj1, tj0);
1509 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
1512 Two_Product(t.m_splitter, adxtail, negate, ti1, ti0);
1514 Two_Product(t.m_splitter, adx, negate, tj1, tj0);
1515 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
1517 catlen = triFastExpansionSumZeroElim(4, u, 4, v, cat);
1519 Two_Product(t.m_splitter, cdxtail, adytail, ti1, ti0);
1520 Two_Product(t.m_splitter, adxtail, cdytail, tj1, tj0);
1521 Two_Two_Diff(ti1, ti0, tj1, tj0, catt3, catt[2], catt[1], catt[0]);
1535 temp16alen = triScaleExpansionZeroElim(bxtcalen, bxtca, bdxtail, temp16a, t);
1536 bxtcatlen = triScaleExpansionZeroElim(catlen, cat, bdxtail, bxtcat, t);
1537 temp32alen = triScaleExpansionZeroElim(bxtcatlen, bxtcat, 2.0 * bdx, temp32a, t);
1538 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1539 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1545 temp8len = triScaleExpansionZeroElim(4, aa, bdxtail, temp8, t);
1546 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, cdytail, temp16a, t);
1547 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1554 temp8len = triScaleExpansionZeroElim(4, cc, -bdxtail, temp8, t);
1555 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, adytail, temp16a, t);
1556 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1562 temp32alen = triScaleExpansionZeroElim(bxtcatlen, bxtcat, bdxtail, temp32a, t);
1563 bxtcattlen = triScaleExpansionZeroElim(cattlen, catt, bdxtail, bxtcatt, t);
1564 temp16alen = triScaleExpansionZeroElim(bxtcattlen, bxtcatt, 2.0 * bdx, temp16a, t);
1565 temp16blen = triScaleExpansionZeroElim(bxtcattlen, bxtcatt, bdxtail, temp16b, t);
1566 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1567 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1568 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1575 temp16alen = triScaleExpansionZeroElim(bytcalen, bytca, bdytail, temp16a, t);
1576 bytcatlen = triScaleExpansionZeroElim(catlen, cat, bdytail, bytcat, t);
1577 temp32alen = triScaleExpansionZeroElim(bytcatlen, bytcat, 2.0 * bdy, temp32a, t);
1578 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1579 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1584 temp32alen = triScaleExpansionZeroElim(bytcatlen, bytcat, bdytail, temp32a, t);
1585 bytcattlen = triScaleExpansionZeroElim(cattlen, catt, bdytail, bytcatt, t);
1586 temp16alen = triScaleExpansionZeroElim(bytcattlen, bytcatt, 2.0 * bdy, temp16a, t);
1587 temp16blen = triScaleExpansionZeroElim(bytcattlen, bytcatt, bdytail, temp16b, t);
1588 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1589 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1590 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1596 if ((cdxtail != 0.0) || (cdytail != 0.0))
1598 if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0))
1600 Two_Product(t.m_splitter, adxtail, bdy, ti1, ti0);
1601 Two_Product(t.m_splitter, adx, bdytail, tj1, tj0);
1602 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
1605 Two_Product(t.m_splitter, bdxtail, negate, ti1, ti0);
1607 Two_Product(t.m_splitter, bdx, negate, tj1, tj0);
1608 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
1610 abtlen = triFastExpansionSumZeroElim(4, u, 4, v, abt);
1612 Two_Product(t.m_splitter, adxtail, bdytail, ti1, ti0);
1613 Two_Product(t.m_splitter, bdxtail, adytail, tj1, tj0);
1614 Two_Two_Diff(ti1, ti0, tj1, tj0, abtt3, abtt[2], abtt[1], abtt[0]);
1628 temp16alen = triScaleExpansionZeroElim(cxtablen, cxtab, cdxtail, temp16a, t);
1629 cxtabtlen = triScaleExpansionZeroElim(abtlen, abt, cdxtail, cxtabt, t);
1630 temp32alen = triScaleExpansionZeroElim(cxtabtlen, cxtabt, 2.0 * cdx, temp32a, t);
1631 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1632 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1638 temp8len = triScaleExpansionZeroElim(4, bb, cdxtail, temp8, t);
1639 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, adytail, temp16a, t);
1640 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1647 temp8len = triScaleExpansionZeroElim(4, aa, -cdxtail, temp8, t);
1648 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, bdytail, temp16a, t);
1649 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1655 temp32alen = triScaleExpansionZeroElim(cxtabtlen, cxtabt, cdxtail, temp32a, t);
1656 cxtabttlen = triScaleExpansionZeroElim(abttlen, abtt, cdxtail, cxtabtt, t);
1657 temp16alen = triScaleExpansionZeroElim(cxtabttlen, cxtabtt, 2.0 * cdx, temp16a, t);
1658 temp16blen = triScaleExpansionZeroElim(cxtabttlen, cxtabtt, cdxtail, temp16b, t);
1659 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1660 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1661 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1668 temp16alen = triScaleExpansionZeroElim(cytablen, cytab, cdytail, temp16a, t);
1669 cytabtlen = triScaleExpansionZeroElim(abtlen, abt, cdytail, cytabt, t);
1670 temp32alen = triScaleExpansionZeroElim(cytabtlen, cytabt, 2.0 * cdy, temp32a, t);
1671 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1672 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1677 temp32alen = triScaleExpansionZeroElim(cytabtlen, cytabt, cdytail, temp32a, t);
1678 cytabttlen = triScaleExpansionZeroElim(abttlen, abtt, cdytail, cytabtt, t);
1679 temp16alen = triScaleExpansionZeroElim(cytabttlen, cytabtt, 2.0 * cdy, temp16a, t);
1680 temp16blen = triScaleExpansionZeroElim(cytabttlen, cytabtt, cdytail, temp16b, t);
1681 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1682 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1683 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1690 return finnow[finlength - 1];
1705 static void triInitTrianglePool(TriVars& t)
1707 #define TRIPERBLOCK 4092 1708 int trisize, highorderid, elemattid;
1712 trisize = (3 + (highorderid - 3)) *
sizeof(Ttri);
1713 elemattid = (trisize +
sizeof(double) - 1) /
sizeof(double);
1715 triPoolInit(&t.m_triangles, trisize, TRIPERBLOCK, TRIPERBLOCK, 4);
1717 triDummyInit(t.m_triangles.itembytes, t);
1724 static bool triMakeTriangle(Tedgetype newtedge, TriVars& t)
1726 newtedge->tri = (Ttri*)triPoolAlloc(&t.m_triangles);
1729 newtedge->tri[0] = (Ttri)t.m_dummytri;
1730 newtedge->tri[1] = (Ttri)t.m_dummytri;
1731 newtedge->tri[2] = (Ttri)t.m_dummytri;
1733 newtedge->tri[3] =
nullptr;
1734 newtedge->tri[4] =
nullptr;
1735 newtedge->tri[5] =
nullptr;
1736 newtedge->orient = 0;
1772 static bool triMergeHulls(Tedgetype farleft,
1773 Tedgetype innerleft,
1774 Tedgetype innerright,
1779 int changemade, badedge, leftfinished, rightfinished;
1780 Tedge leftcand, rightcand, baseedge, nextedge;
1781 Tedge sidecasing, topcasing, outercasing, checkedge;
1782 Tpt innerleftdest, innerrightorg;
1783 Tpt innerleftapex, innerrightapex;
1784 Tpt farleftpt, farrightpt;
1785 Tpt farleftapex, farrightapex;
1786 Tpt lowerleft, lowerright;
1787 Tpt upperleft, upperright;
1788 Tpt nextapex, checkvertex;
1790 bool canMakeTriangles =
true;
1792 dest(*innerleft, innerleftdest);
1793 apex(*innerleft, innerleftapex);
1794 org(*innerright, innerrightorg);
1795 apex(*innerright, innerrightapex);
1799 org(*farleft, farleftpt);
1800 apex(*farleft, farleftapex);
1801 dest(*farright, farrightpt);
1802 apex(*farright, farrightapex);
1806 while (farleftapex[1] < farleftpt[1])
1808 lnextself(*farleft);
1810 farleftpt = farleftapex;
1811 apex(*farleft, farleftapex);
1813 sym(*innerleft, checkedge);
1814 apex(checkedge, checkvertex);
1815 while (checkvertex[1] > innerleftdest[1])
1817 lnext(checkedge, *innerleft);
1818 innerleftapex = innerleftdest;
1819 innerleftdest = checkvertex;
1820 sym(*innerleft, checkedge);
1821 apex(checkedge, checkvertex);
1823 while (innerrightapex[1] < innerrightorg[1])
1825 lnextself(*innerright);
1826 symself(*innerright);
1827 innerrightorg = innerrightapex;
1828 apex(*innerright, innerrightapex);
1830 sym(*farright, checkedge);
1831 apex(checkedge, checkvertex);
1832 while (checkvertex[1] > farrightpt[1])
1834 lnext(checkedge, *farright);
1835 farrightapex = farrightpt;
1836 farrightpt = checkvertex;
1837 sym(*farright, checkedge);
1838 apex(checkedge, checkvertex);
1847 if (triCounterClockwise(innerleftdest, innerleftapex, innerrightorg, t) > 0.0)
1849 lprevself(*innerleft);
1850 symself(*innerleft);
1851 innerleftdest = innerleftapex;
1852 apex(*innerleft, innerleftapex);
1857 if (triCounterClockwise(innerrightapex, innerrightorg, innerleftdest, t) > 0.0)
1859 lnextself(*innerright);
1860 symself(*innerright);
1861 innerrightorg = innerrightapex;
1862 apex(*innerright, innerrightapex);
1865 }
while (changemade);
1867 sym(*innerleft, leftcand);
1868 sym(*innerright, rightcand);
1870 canMakeTriangles = triMakeTriangle(&baseedge, t);
1871 if (!canMakeTriangles)
1877 bond(baseedge, *innerleft);
1878 lnextself(baseedge);
1879 bond(baseedge, *innerright);
1880 lnextself(baseedge);
1881 setorg(baseedge, innerrightorg);
1882 setdest(baseedge, innerleftdest);
1885 org(*farleft, farleftpt);
1886 if (innerleftdest == farleftpt)
1888 lnext(baseedge, *farleft);
1890 dest(*farright, farrightpt);
1891 if (innerrightorg == farrightpt)
1893 lprev(baseedge, *farright);
1896 lowerleft = innerleftdest;
1897 lowerright = innerrightorg;
1899 apex(leftcand, upperleft);
1900 apex(rightcand, upperright);
1909 leftfinished = triCounterClockwise(upperleft, lowerleft, lowerright, t) <= 0.0;
1910 rightfinished = triCounterClockwise(upperright, lowerleft, lowerright, t) <= 0.0;
1911 if (leftfinished && rightfinished)
1914 canMakeTriangles = triMakeTriangle(&nextedge, t);
1915 if (!canMakeTriangles)
1919 setorg(nextedge, lowerleft);
1920 setdest(nextedge, lowerright);
1924 bond(nextedge, baseedge);
1925 lnextself(nextedge);
1926 bond(nextedge, rightcand);
1927 lnextself(nextedge);
1928 bond(nextedge, leftcand);
1932 org(*farleft, farleftpt);
1933 apex(*farleft, farleftapex);
1934 dest(*farright, farrightpt);
1935 apex(*farright, farrightapex);
1936 sym(*farleft, checkedge);
1937 apex(checkedge, checkvertex);
1940 while (checkvertex[0] < farleftpt[0])
1942 lprev(checkedge, *farleft);
1943 farleftapex = farleftpt;
1944 farleftpt = checkvertex;
1945 sym(*farleft, checkedge);
1946 apex(checkedge, checkvertex);
1948 while (farrightapex[0] > farrightpt[0])
1950 lprevself(*farright);
1952 farrightpt = farrightapex;
1953 apex(*farright, farrightapex);
1964 lprev(leftcand, nextedge);
1966 apex(nextedge, nextapex);
1969 if (nextapex !=
nullptr)
1972 badedge = triInCircle(lowerleft, lowerright, upperleft, nextapex, t) > 0.0;
1977 lnextself(nextedge);
1978 sym(nextedge, topcasing);
1979 lnextself(nextedge);
1980 sym(nextedge, sidecasing);
1981 bond(nextedge, topcasing);
1982 bond(leftcand, sidecasing);
1983 lnextself(leftcand);
1984 sym(leftcand, outercasing);
1985 lprevself(nextedge);
1986 bond(nextedge, outercasing);
1988 setorg(leftcand, lowerleft);
1989 setdest(leftcand,
nullptr);
1990 setapex(leftcand, nextapex);
1991 setorg(nextedge,
nullptr);
1992 setdest(nextedge, upperleft);
1993 setapex(nextedge, nextapex);
1995 upperleft = nextapex;
1998 tedgecopy(sidecasing, nextedge);
1999 apex(nextedge, nextapex);
2000 if (nextapex !=
nullptr)
2003 badedge = triInCircle(lowerleft, lowerright, upperleft, nextapex, t) > 0.0;
2019 lnext(rightcand, nextedge);
2021 apex(nextedge, nextapex);
2025 if (nextapex !=
nullptr)
2028 badedge = triInCircle(lowerleft, lowerright, upperright, nextapex, t) > 0.0;
2034 lprevself(nextedge);
2035 sym(nextedge, topcasing);
2036 lprevself(nextedge);
2037 sym(nextedge, sidecasing);
2038 bond(nextedge, topcasing);
2039 bond(rightcand, sidecasing);
2040 lprevself(rightcand);
2041 sym(rightcand, outercasing);
2042 lnextself(nextedge);
2043 bond(nextedge, outercasing);
2045 setorg(rightcand,
nullptr);
2046 setdest(rightcand, lowerright);
2047 setapex(rightcand, nextapex);
2048 setorg(nextedge, upperright);
2049 setdest(nextedge,
nullptr);
2050 setapex(nextedge, nextapex);
2052 upperright = nextapex;
2055 tedgecopy(sidecasing, nextedge);
2056 apex(nextedge, nextapex);
2057 if (nextapex !=
nullptr)
2060 badedge = triInCircle(lowerleft, lowerright, upperright, nextapex, t) > 0.0;
2071 (!rightfinished && (triInCircle(upperleft, lowerleft, lowerright, upperright, t) > 0.0)))
2075 bond(baseedge, rightcand);
2076 lprev(rightcand, baseedge);
2077 setdest(baseedge, lowerleft);
2078 lowerright = upperright;
2079 sym(baseedge, rightcand);
2080 apex(rightcand, upperright);
2086 bond(baseedge, leftcand);
2087 lnext(leftcand, baseedge);
2088 setorg(baseedge, lowerright);
2089 lowerleft = upperleft;
2090 sym(baseedge, leftcand);
2091 apex(leftcand, upperleft);
2100 static void triNumberNodes(TriVars& t)
2105 triTraversalInit(&t.m_points);
2106 pointloop = triPointTraverse(t);
2108 while (pointloop !=
nullptr)
2110 setpointmark(pointloop, pointnumber, t.m_pointmarkindex);
2111 pointloop = triPointTraverse(t);
2125 static void triPointMedian(Tpt* sortarray,
int arraysize,
int median,
int axis)
2127 int left, right, pivot;
2128 double pivot1, pivot2;
2133 if ((sortarray[0][axis] > sortarray[1][axis]) ||
2134 ((sortarray[0][axis] == sortarray[1][axis]) &&
2135 (sortarray[0][1 - axis] > sortarray[1][1 - axis])))
2137 temp = sortarray[1];
2138 sortarray[1] = sortarray[0];
2139 sortarray[0] = temp;
2143 else if (arraysize == 0)
2146 pivot = (int)triRandomnation((
unsigned int)arraysize);
2147 pivot1 = sortarray[pivot][axis];
2148 pivot2 = sortarray[pivot][1 - axis];
2152 while (left < right)
2158 }
while ((left <= right) &&
2159 ((sortarray[left][axis] < pivot1) ||
2160 ((sortarray[left][axis] == pivot1) && (sortarray[left][1 - axis] < pivot2))));
2165 }
while ((left <= right) &&
2166 ((sortarray[right][axis] > pivot1) ||
2167 ((sortarray[right][axis] == pivot1) && (sortarray[right][1 - axis] > pivot2))));
2171 temp = sortarray[left];
2172 sortarray[left] = sortarray[right];
2173 sortarray[right] = temp;
2180 triPointMedian(sortarray, left, median, axis);
2182 if (right < median - 1)
2185 triPointMedian(&sortarray[right + 1], arraysize - right - 1, median - right - 1, axis);
2196 static void triPointSort(Tpt* sortarray,
int arraysize)
2198 int left, right, pivot;
2199 double pivotx, pivoty;
2204 if ((sortarray[0][0] > sortarray[1][0]) ||
2205 ((sortarray[0][0] == sortarray[1][0]) && (sortarray[0][1] > sortarray[1][1])))
2207 temp = sortarray[1];
2208 sortarray[1] = sortarray[0];
2209 sortarray[0] = temp;
2213 else if (arraysize == 0)
2216 pivot = (int)triRandomnation((
unsigned int)arraysize);
2217 pivotx = sortarray[pivot][0];
2218 pivoty = sortarray[pivot][1];
2222 while (left < right)
2228 }
while ((left <= right) && ((sortarray[left][0] < pivotx) || ((sortarray[left][0] == pivotx) &&
2229 (sortarray[left][1] < pivoty))));
2234 }
while ((left <= right) &&
2235 ((sortarray[right][0] > pivotx) ||
2236 ((sortarray[right][0] == pivotx) && (sortarray[right][1] > pivoty))));
2240 temp = sortarray[left];
2241 sortarray[left] = sortarray[right];
2242 sortarray[right] = temp;
2248 triPointSort(sortarray, left);
2250 if (right < arraysize - 2)
2253 triPointSort(&sortarray[right + 1], arraysize - right - 1);
2261 static Tpt triPointTraverse(TriVars& t)
2267 newpoint = (Tpt)triTraverse(&t.m_points);
2268 if (newpoint ==
nullptr)
2270 }
while (pointmark(newpoint, t.m_pointmarkindex) == -999);
2278 static int* triPoolAlloc(Tmemtype pool)
2280 int *newitem, **newblock;
2281 unsigned long long alignptr;
2283 if (pool->deaditemstack !=
nullptr)
2285 newitem = pool->deaditemstack;
2286 pool->deaditemstack = *(
int**)pool->deaditemstack;
2291 if (pool->unallocateditems == 0)
2293 if (*(pool->nowblock) ==
nullptr)
2297 (
int**)malloc(pool->itemsperblock * pool->itembytes +
sizeof(
int*) + pool->alignbytes);
2298 if (newblock ==
nullptr)
2300 std::string s =
"malloc failed: ";
2305 *(pool->nowblock) = (
int*)newblock;
2307 *newblock =
nullptr;
2310 pool->nowblock = (
int**)*(pool->nowblock);
2312 alignptr = (
unsigned long long)(pool->nowblock + 1);
2314 pool->nextitem = (
int*)(alignptr + (
unsigned long long)pool->alignbytes -
2315 (alignptr % (
unsigned long long)pool->alignbytes));
2317 pool->unallocateditems = pool->itemsperblock;
2320 newitem = pool->nextitem;
2322 pool->nextitem = (
int*)((
char*)pool->nextitem + pool->itembytes);
2324 pool->unallocateditems--;
2335 static void triPoolDealloc(Tmemtype pool,
int* dyingitem)
2338 *((
int**)dyingitem) = pool->deaditemstack;
2339 pool->deaditemstack = dyingitem;
2347 static void triPoolDeinit(Tmemtype pool)
2349 while (pool && pool->firstblock !=
nullptr)
2351 pool->nowblock = (
int**)*(pool->firstblock);
2352 free(pool->firstblock);
2353 pool->firstblock = pool->nowblock;
2373 static bool triPoolInit(Tmemtype pool,
2384 if (alignment >
sizeof(
int*))
2386 pool->alignbytes = alignment;
2390 pool->alignbytes =
sizeof(
int*);
2392 pool->itembytes = ((bytecount - 1) / pool->alignbytes + 1) * pool->alignbytes;
2393 pool->itemsperblock = itemcount;
2394 if (firstitemcount == 0)
2396 pool->itemsfirstblock = itemcount;
2400 pool->itemsfirstblock = firstitemcount;
2407 (
int**)malloc(pool->itemsfirstblock * pool->itembytes +
sizeof(
int*) + pool->alignbytes);
2408 if (pool->firstblock ==
nullptr)
2410 std::string s =
"malloc failed: ";
2416 *(pool->firstblock) =
nullptr;
2418 triPoolRestart(pool);
2429 static void triPoolRestart(Tmemtype pool)
2431 unsigned long long alignptr;
2437 pool->nowblock = pool->firstblock;
2439 alignptr = (
unsigned long long)(pool->nowblock + 1);
2441 pool->nextitem = (
int*)(alignptr + (
unsigned long long)pool->alignbytes -
2442 (alignptr % (
unsigned long long)pool->alignbytes));
2444 pool->unallocateditems = pool->itemsfirstblock;
2446 pool->deaditemstack =
nullptr;
2457 static unsigned long triRandomnation(
unsigned int choices)
2459 static unsigned long randomseed = 1;
2463 randomseed = (randomseed * 1366l + 150889l) % 714025l;
2464 return randomseed / (714025l / choices + 1);
2471 static void triRemoveGhosts(Tedgetype startghost, TriVars& t)
2473 Tedge searchedge, dissolveedge, deadtri;
2477 lprev(*startghost, searchedge);
2478 symself(searchedge);
2479 t.m_dummytri[0] = encode(searchedge);
2481 tedgecopy(*startghost, dissolveedge);
2484 lnext(dissolveedge, deadtri);
2485 lprevself(dissolveedge);
2486 symself(dissolveedge);
2490 if (dissolveedge.tri != t.m_dummytri)
2492 org(dissolveedge, markorg);
2493 if (pointmark(markorg, t.m_pointmarkindex) == 0)
2495 setpointmark(markorg, 1, t.m_pointmarkindex);
2499 dissolveedge.tri[dissolveedge.orient] = (Ttri)t.m_dummytri;
2501 sym(deadtri, dissolveedge);
2503 triTriangleDealloc(deadtri.tri, t);
2504 }
while (!tedgeequal(dissolveedge, *startghost));
2517 static int triScaleExpansionZeroElim(
int elen,
double* e,
double b,
double* h, TriVars& t)
2522 double product1, product0;
2524 double bvirt, avirt, bround, around;
2526 double abig, ahi, alo, bhi, blo;
2527 double err1, err2, err3;
2529 Split(t.m_splitter, b, bhi, blo);
2530 Two_Product_Presplit(t.m_splitter, e[0], b, bhi, blo, Q, hh);
2535 for (eindex = 1; eindex < elen; eindex++)
2538 Two_Product_Presplit(t.m_splitter, enow, b, bhi, blo, product1, product0);
2539 Two_Sum(Q, product0, sum, hh);
2542 Fast_Two_Sum(product1, sum, Q, hh);
2546 if ((Q != 0.0) || (hindex == 0))
2555 static void triTraversalInit(Tmemtype pool)
2557 unsigned long long alignptr;
2559 pool->pathblock = pool->firstblock;
2561 alignptr = (
unsigned long long)(pool->pathblock + 1);
2563 pool->pathitem = (
int*)(alignptr + (
unsigned long long)pool->alignbytes -
2564 (alignptr % (
unsigned long long)pool->alignbytes));
2566 pool->pathitemsleft = pool->itemsfirstblock;
2579 static int* triTraverse(Tmemtype pool)
2582 unsigned long long alignptr;
2584 if (pool->pathitem == pool->nextitem)
2587 if (pool->pathitemsleft == 0)
2590 pool->pathblock = (
int**)*(pool->pathblock);
2592 alignptr = (
unsigned long long)(pool->pathblock + 1);
2594 pool->pathitem = (
int*)(alignptr + (
unsigned long long)pool->alignbytes -
2595 (alignptr % (
unsigned long long)pool->alignbytes));
2597 pool->pathitemsleft = pool->itemsperblock;
2599 newitem = pool->pathitem;
2602 pool->pathitem = (
int*)((
char*)pool->pathitem + pool->itembytes);
2603 pool->pathitemsleft--;
2611 static void triTriangleDealloc(Ttri* dyingtriangle, TriVars& t)
2614 dyingtriangle[3] =
nullptr;
2615 dyingtriangle[4] =
nullptr;
2616 dyingtriangle[5] =
nullptr;
2617 triPoolDealloc(&t.m_triangles, (
int*)dyingtriangle);
2624 static Ttri* triTriangleTraverse(TriVars& t)
2629 newtriangle = (Ttri*)triTraverse(&t.m_triangles);
2630 if (newtriangle ==
nullptr)
2632 }
while (newtriangle[3] ==
nullptr);
2662 t.m_points.maxitems = t.m_triangles.maxitems = 0l;
2663 t.m_points.itembytes = t.m_triangles.itembytes = 0;
2669 if (!triGetPoints(a_Client, t))
2674 if (t.m_numpoints > 2)
2677 triInitTrianglePool(t);
2680 bool ok = triDivConqDelaunay(t);
2684 triFillTriList(a_Client, t);
2687 triPoolDeinit(&t.m_triangles);
2688 if (t.m_dummytribase)
2690 free(t.m_dummytribase);
2696 triPoolDeinit(&t.m_points);
2698 a_Client.FinalizeTriangulation();
2703 triPoolDeinit(&t.m_triangles);
2704 triPoolDeinit(&t.m_points);
Code that creates a Delauney triangulation from points.
bool trTriangulateIt(TrTriangulator &a_Client)
Do delaunay divide-and-conquer triangulation.
Base class used to derive a class to triangulate points.