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))
925 a_Client.PrepareToReceiveTriangles();
927 triTraversalInit(&t.m_triangles);
928 triangleloop.tri = triTriangleTraverse(t);
929 triangleloop.orient = 0;
930 while (triangleloop.tri !=
nullptr)
933 org(triangleloop, p1);
934 dest(triangleloop, p2);
935 apex(triangleloop, p3);
936 id1 = pointmark(p1, t.m_pointmarkindex);
937 id2 = pointmark(p2, t.m_pointmarkindex);
938 id3 = pointmark(p3, t.m_pointmarkindex);
941 a_Client.ReceiveTriangle(id1, id2, id3);
943 triangleloop.tri = triTriangleTraverse(t);
953 #define POINTPERBLOCK 4092
960 t.m_pointmarkindex = (3 *
sizeof(double) +
sizeof(
int) - 1) /
sizeof(
int);
961 pointsize = (t.m_pointmarkindex + 1) *
sizeof(
int);
965 t.m_numpoints = a_Client.GetNPoints();
967 if (!triPoolInit(&t.m_points, pointsize, POINTPERBLOCK,
968 t.m_numpoints > POINTPERBLOCK ? t.m_numpoints : POINTPERBLOCK, 0))
974 for (i = 0; i < t.m_numpoints; i++)
976 pointloop = (Tpt)triPoolAlloc(&t.m_points);
979 loc = a_Client.GetLocation();
980 pointloop[0] = loc.
x;
981 pointloop[1] = loc.
y;
984 pointloop[2] = a_Client.GetID();
986 setpointmark(pointloop, 0, t.m_pointmarkindex);
989 a_Client.IncrementPoint();
998 static double triInCircle(Tpt pa, Tpt pb, Tpt pc, Tpt pd, TriVars& t)
1000 double adx, bdx, cdx, ady, bdy, cdy;
1001 double bdxcdy, cdxbdy, cdxady, adxcdy, adxbdy, bdxady;
1002 double alift, blift, clift;
1004 double permanent, errbound;
1006 adx = pa[0] - pd[0];
1007 bdx = pb[0] - pd[0];
1008 cdx = pc[0] - pd[0];
1009 ady = pa[1] - pd[1];
1010 bdy = pb[1] - pd[1];
1011 cdy = pc[1] - pd[1];
1015 alift = adx * adx + ady * ady;
1019 blift = bdx * bdx + bdy * bdy;
1023 clift = cdx * cdx + cdy * cdy;
1025 det = alift * (bdxcdy - cdxbdy) + blift * (cdxady - adxcdy) + clift * (adxbdy - bdxady);
1027 permanent = (fabs(bdxcdy) + fabs(cdxbdy)) * alift + (fabs(cdxady) + fabs(adxcdy)) * blift +
1028 (fabs(adxbdy) + fabs(bdxady)) * clift;
1029 errbound = t.m_iccerrboundA * permanent;
1030 if ((det > errbound) || (-det > errbound))
1033 return triInCircleAdapt(pa, pb, pc, pd, permanent, t);
1049 static double triInCircleAdapt(Tpt pa, Tpt pb, Tpt pc, Tpt pd,
double permanent, TriVars& t)
1051 int axbclen, axxbclen, aybclen, ayybclen, alen;
1052 int bxcalen, bxxcalen, bycalen, byycalen, blen;
1053 int cxablen, cxxablen, cyablen, cyyablen, clen;
1056 double adx, bdx, cdx, ady, bdy, cdy;
1057 double det, errbound;
1058 double bdxcdy1, cdxbdy1, cdxady1, adxcdy1, adxbdy1, bdxady1;
1059 double bdxcdy0, cdxbdy0, cdxady0, adxcdy0, adxbdy0, bdxady0;
1060 double bc[4], ca[4], ab[4];
1061 double bc3, ca3, ab3;
1062 double axbc[8], axxbc[16], aybc[8], ayybc[16], adet[32];
1063 double bxca[8], bxxca[16], byca[8], byyca[16], bdet[32];
1064 double cxab[8], cxxab[16], cyab[8], cyyab[16], cdet[32];
1066 double fin1[1152], fin2[1152];
1067 double *finnow, *finother, *finswap;
1069 int temp8len, temp16alen, temp16blen, temp16clen;
1070 int temp32alen, temp32blen, temp48len, temp64len;
1071 int axtbblen, axtcclen, aytbblen, aytcclen;
1072 int bxtaalen, bxtcclen, bytaalen, bytcclen;
1073 int cxtaalen, cxtbblen, cytaalen, cytbblen;
1074 int axtbclen = 0, aytbclen = 0, bxtcalen = 0;
1075 int bytcalen = 0, cxtablen = 0, cytablen = 0;
1076 int axtbctlen, bxtcatlen, cxtabtlen;
1077 int aytbctlen, bytcatlen, cytabtlen;
1078 int axtbcttlen, bxtcattlen, cxtabttlen;
1079 int aytbcttlen, bytcattlen, cytabttlen;
1080 int abtlen, bctlen, catlen;
1081 int abttlen, bcttlen, cattlen;
1082 double adxtail, bdxtail, cdxtail, adytail, bdytail, cdytail;
1083 double adxadx1, adyady1, bdxbdx1, bdybdy1, cdxcdx1, cdycdy1;
1084 double adxadx0, adyady0, bdxbdx0, bdybdy0, cdxcdx0, cdycdy0;
1085 double aa[4], bb[4], cc[4];
1086 double aa3, bb3, cc3;
1091 double temp8[8], temp16a[16], temp16b[16], temp16c[16];
1092 double temp32a[32], temp32b[32], temp48[48], temp64[64];
1093 double axtbb[8], axtcc[8], aytbb[8], aytcc[8];
1094 double bxtaa[8], bxtcc[8], bytaa[8], bytcc[8];
1095 double cxtaa[8], cxtbb[8], cytaa[8], cytbb[8];
1096 double axtbc[8], aytbc[8], bxtca[8], bytca[8], cxtab[8], cytab[8];
1097 double axtbct[16], bxtcat[16], cxtabt[16];
1098 double aytbct[16], bytcat[16], cytabt[16];
1099 double axtbctt[8], aytbctt[8], bxtcatt[8];
1100 double bytcatt[8], cxtabtt[8], cytabtt[8];
1101 double abt[8], bct[8], cat[8];
1102 double abtt[4], bctt[4], catt[4];
1103 double abtt3, bctt3, catt3;
1107 double avirt, bround, around;
1109 double abig, ahi, alo, bhi, blo;
1110 double err1, err2, err3;
1114 memset(bc, 0, 4 *
sizeof(
double));
1115 memset(ca, 0, 4 *
sizeof(
double));
1116 memset(ab, 0, 4 *
sizeof(
double));
1118 memset(axbc, 0, 8 *
sizeof(
double));
1119 memset(axxbc, 0, 16 *
sizeof(
double));
1120 memset(aybc, 0, 8 *
sizeof(
double));
1121 memset(ayybc, 0, 16 *
sizeof(
double));
1122 memset(adet, 0, 32 *
sizeof(
double));
1124 memset(bxca, 0, 8 *
sizeof(
double));
1125 memset(bxxca, 0, 16 *
sizeof(
double));
1126 memset(byca, 0, 8 *
sizeof(
double));
1127 memset(byyca, 0, 16 *
sizeof(
double));
1128 memset(bdet, 0, 32 *
sizeof(
double));
1130 memset(cxab, 0, 8 *
sizeof(
double));
1131 memset(cxxab, 0, 16 *
sizeof(
double));
1132 memset(cyab, 0, 8 *
sizeof(
double));
1133 memset(cyyab, 0, 16 *
sizeof(
double));
1134 memset(cdet, 0, 32 *
sizeof(
double));
1136 memset(abdet, 0, 64 *
sizeof(
double));
1137 memset(fin1, 0, 1152 *
sizeof(
double));
1138 memset(fin2, 0, 1152 *
sizeof(
double));
1140 memset(aa, 0, 4 *
sizeof(
double));
1141 memset(bb, 0, 4 *
sizeof(
double));
1142 memset(cc, 0, 4 *
sizeof(
double));
1144 memset(u, 0, 4 *
sizeof(
double));
1145 memset(v, 0, 4 *
sizeof(
double));
1147 memset(temp8, 0, 8 *
sizeof(
double));
1148 memset(temp16a, 0, 16 *
sizeof(
double));
1149 memset(temp16b, 0, 16 *
sizeof(
double));
1150 memset(temp16c, 0, 16 *
sizeof(
double));
1152 memset(temp32a, 0, 32 *
sizeof(
double));
1153 memset(temp32b, 0, 32 *
sizeof(
double));
1154 memset(temp48, 0, 48 *
sizeof(
double));
1155 memset(temp64, 0, 64 *
sizeof(
double));
1157 memset(axtbb, 0, 8 *
sizeof(
double));
1158 memset(axtcc, 0, 8 *
sizeof(
double));
1159 memset(aytbb, 0, 8 *
sizeof(
double));
1160 memset(aytcc, 0, 8 *
sizeof(
double));
1162 memset(bxtaa, 0, 8 *
sizeof(
double));
1163 memset(bxtcc, 0, 8 *
sizeof(
double));
1164 memset(bytaa, 0, 8 *
sizeof(
double));
1165 memset(bytcc, 0, 8 *
sizeof(
double));
1167 memset(cxtaa, 0, 8 *
sizeof(
double));
1168 memset(cxtbb, 0, 8 *
sizeof(
double));
1169 memset(cytaa, 0, 8 *
sizeof(
double));
1170 memset(cytbb, 0, 8 *
sizeof(
double));
1172 memset(axtbc, 0, 8 *
sizeof(
double));
1173 memset(aytbc, 0, 8 *
sizeof(
double));
1174 memset(bxtca, 0, 8 *
sizeof(
double));
1175 memset(bytca, 0, 8 *
sizeof(
double));
1176 memset(cxtab, 0, 8 *
sizeof(
double));
1177 memset(cytab, 0, 8 *
sizeof(
double));
1179 memset(axtbct, 0, 16 *
sizeof(
double));
1180 memset(bxtcat, 0, 16 *
sizeof(
double));
1181 memset(cxtabt, 0, 16 *
sizeof(
double));
1183 memset(aytbct, 0, 16 *
sizeof(
double));
1184 memset(bytcat, 0, 16 *
sizeof(
double));
1185 memset(cytabt, 0, 16 *
sizeof(
double));
1187 memset(axtbctt, 0, 8 *
sizeof(
double));
1188 memset(aytbctt, 0, 8 *
sizeof(
double));
1189 memset(bxtcatt, 0, 8 *
sizeof(
double));
1191 memset(bytcatt, 0, 8 *
sizeof(
double));
1192 memset(cxtabtt, 0, 8 *
sizeof(
double));
1193 memset(cytabtt, 0, 8 *
sizeof(
double));
1195 memset(abt, 0, 8 *
sizeof(
double));
1196 memset(bct, 0, 8 *
sizeof(
double));
1197 memset(cat, 0, 8 *
sizeof(
double));
1199 memset(abtt, 0, 4 *
sizeof(
double));
1200 memset(bctt, 0, 4 *
sizeof(
double));
1201 memset(catt, 0, 4 *
sizeof(
double));
1203 adx = (double)(pa[0] - pd[0]);
1204 bdx = (double)(pb[0] - pd[0]);
1205 cdx = (double)(pc[0] - pd[0]);
1206 ady = (double)(pa[1] - pd[1]);
1207 bdy = (double)(pb[1] - pd[1]);
1208 cdy = (double)(pc[1] - pd[1]);
1210 Two_Product(t.m_splitter, bdx, cdy, bdxcdy1, bdxcdy0);
1211 Two_Product(t.m_splitter, cdx, bdy, cdxbdy1, cdxbdy0);
1212 Two_Two_Diff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, bc3, bc[2], bc[1], bc[0]);
1214 axbclen = triScaleExpansionZeroElim(4, bc, adx, axbc, t);
1215 axxbclen = triScaleExpansionZeroElim(axbclen, axbc, adx, axxbc, t);
1216 aybclen = triScaleExpansionZeroElim(4, bc, ady, aybc, t);
1217 ayybclen = triScaleExpansionZeroElim(aybclen, aybc, ady, ayybc, t);
1218 alen = triFastExpansionSumZeroElim(axxbclen, axxbc, ayybclen, ayybc, adet);
1220 Two_Product(t.m_splitter, cdx, ady, cdxady1, cdxady0);
1221 Two_Product(t.m_splitter, adx, cdy, adxcdy1, adxcdy0);
1222 Two_Two_Diff(cdxady1, cdxady0, adxcdy1, adxcdy0, ca3, ca[2], ca[1], ca[0]);
1224 bxcalen = triScaleExpansionZeroElim(4, ca, bdx, bxca, t);
1225 bxxcalen = triScaleExpansionZeroElim(bxcalen, bxca, bdx, bxxca, t);
1226 bycalen = triScaleExpansionZeroElim(4, ca, bdy, byca, t);
1227 byycalen = triScaleExpansionZeroElim(bycalen, byca, bdy, byyca, t);
1228 blen = triFastExpansionSumZeroElim(bxxcalen, bxxca, byycalen, byyca, bdet);
1230 Two_Product(t.m_splitter, adx, bdy, adxbdy1, adxbdy0);
1231 Two_Product(t.m_splitter, bdx, ady, bdxady1, bdxady0);
1232 Two_Two_Diff(adxbdy1, adxbdy0, bdxady1, bdxady0, ab3, ab[2], ab[1], ab[0]);
1234 cxablen = triScaleExpansionZeroElim(4, ab, cdx, cxab, t);
1235 cxxablen = triScaleExpansionZeroElim(cxablen, cxab, cdx, cxxab, t);
1236 cyablen = triScaleExpansionZeroElim(4, ab, cdy, cyab, t);
1237 cyyablen = triScaleExpansionZeroElim(cyablen, cyab, cdy, cyyab, t);
1238 clen = triFastExpansionSumZeroElim(cxxablen, cxxab, cyyablen, cyyab, cdet);
1240 ablen = triFastExpansionSumZeroElim(alen, adet, blen, bdet, abdet);
1241 finlength = triFastExpansionSumZeroElim(ablen, abdet, clen, cdet, fin1);
1243 det = triEstimate(finlength, fin1);
1244 errbound = t.m_iccerrboundB * permanent;
1245 if ((det >= errbound) || (-det >= errbound))
1248 Two_Diff_Tail(pa[0], pd[0], adx, adxtail);
1249 Two_Diff_Tail(pa[1], pd[1], ady, adytail);
1250 Two_Diff_Tail(pb[0], pd[0], bdx, bdxtail);
1251 Two_Diff_Tail(pb[1], pd[1], bdy, bdytail);
1252 Two_Diff_Tail(pc[0], pd[0], cdx, cdxtail);
1253 Two_Diff_Tail(pc[1], pd[1], cdy, cdytail);
1254 if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) && (adytail == 0.0) &&
1255 (bdytail == 0.0) && (cdytail == 0.0))
1260 errbound = t.m_iccerrboundC * permanent + t.m_resulterrbound * fabs(det);
1262 ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) +
1263 2.0 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx)) +
1264 ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) +
1265 2.0 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx)) +
1266 ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) +
1267 2.0 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx));
1268 if ((det >= errbound) || (-det >= errbound))
1274 if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0))
1276 Square(t.m_splitter, adx, adxadx1, adxadx0);
1277 Square(t.m_splitter, ady, adyady1, adyady0);
1278 Two_Two_Sum(adxadx1, adxadx0, adyady1, adyady0, aa3, aa[2], aa[1], aa[0]);
1281 if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0))
1283 Square(t.m_splitter, bdx, bdxbdx1, bdxbdx0);
1284 Square(t.m_splitter, bdy, bdybdy1, bdybdy0);
1285 Two_Two_Sum(bdxbdx1, bdxbdx0, bdybdy1, bdybdy0, bb3, bb[2], bb[1], bb[0]);
1288 if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0))
1290 Square(t.m_splitter, cdx, cdxcdx1, cdxcdx0);
1291 Square(t.m_splitter, cdy, cdycdy1, cdycdy0);
1292 Two_Two_Sum(cdxcdx1, cdxcdx0, cdycdy1, cdycdy0, cc3, cc[2], cc[1], cc[0]);
1298 axtbclen = triScaleExpansionZeroElim(4, bc, adxtail, axtbc, t);
1299 temp16alen = triScaleExpansionZeroElim(axtbclen, axtbc, 2.0 * adx, temp16a, t);
1301 axtcclen = triScaleExpansionZeroElim(4, cc, adxtail, axtcc, t);
1302 temp16blen = triScaleExpansionZeroElim(axtcclen, axtcc, bdy, temp16b, t);
1304 axtbblen = triScaleExpansionZeroElim(4, bb, adxtail, axtbb, t);
1305 temp16clen = triScaleExpansionZeroElim(axtbblen, axtbb, -cdy, temp16c, t);
1307 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1308 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1309 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1316 aytbclen = triScaleExpansionZeroElim(4, bc, adytail, aytbc, t);
1317 temp16alen = triScaleExpansionZeroElim(aytbclen, aytbc, 2.0 * ady, temp16a, t);
1319 aytbblen = triScaleExpansionZeroElim(4, bb, adytail, aytbb, t);
1320 temp16blen = triScaleExpansionZeroElim(aytbblen, aytbb, cdx, temp16b, t);
1322 aytcclen = triScaleExpansionZeroElim(4, cc, adytail, aytcc, t);
1323 temp16clen = triScaleExpansionZeroElim(aytcclen, aytcc, -bdx, temp16c, t);
1325 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1326 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1327 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1334 bxtcalen = triScaleExpansionZeroElim(4, ca, bdxtail, bxtca, t);
1335 temp16alen = triScaleExpansionZeroElim(bxtcalen, bxtca, 2.0 * bdx, temp16a, t);
1337 bxtaalen = triScaleExpansionZeroElim(4, aa, bdxtail, bxtaa, t);
1338 temp16blen = triScaleExpansionZeroElim(bxtaalen, bxtaa, cdy, temp16b, t);
1340 bxtcclen = triScaleExpansionZeroElim(4, cc, bdxtail, bxtcc, t);
1341 temp16clen = triScaleExpansionZeroElim(bxtcclen, bxtcc, -ady, temp16c, t);
1343 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1344 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1345 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1352 bytcalen = triScaleExpansionZeroElim(4, ca, bdytail, bytca, t);
1353 temp16alen = triScaleExpansionZeroElim(bytcalen, bytca, 2.0 * bdy, temp16a, t);
1355 bytcclen = triScaleExpansionZeroElim(4, cc, bdytail, bytcc, t);
1356 temp16blen = triScaleExpansionZeroElim(bytcclen, bytcc, adx, temp16b, t);
1358 bytaalen = triScaleExpansionZeroElim(4, aa, bdytail, bytaa, t);
1359 temp16clen = triScaleExpansionZeroElim(bytaalen, bytaa, -cdx, temp16c, t);
1361 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1362 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1363 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1370 cxtablen = triScaleExpansionZeroElim(4, ab, cdxtail, cxtab, t);
1371 temp16alen = triScaleExpansionZeroElim(cxtablen, cxtab, 2.0 * cdx, temp16a, t);
1373 cxtbblen = triScaleExpansionZeroElim(4, bb, cdxtail, cxtbb, t);
1374 temp16blen = triScaleExpansionZeroElim(cxtbblen, cxtbb, ady, temp16b, t);
1376 cxtaalen = triScaleExpansionZeroElim(4, aa, cdxtail, cxtaa, t);
1377 temp16clen = triScaleExpansionZeroElim(cxtaalen, cxtaa, -bdy, temp16c, t);
1379 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1380 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1381 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1388 cytablen = triScaleExpansionZeroElim(4, ab, cdytail, cytab, t);
1389 temp16alen = triScaleExpansionZeroElim(cytablen, cytab, 2.0 * cdy, temp16a, t);
1391 cytaalen = triScaleExpansionZeroElim(4, aa, cdytail, cytaa, t);
1392 temp16blen = triScaleExpansionZeroElim(cytaalen, cytaa, bdx, temp16b, t);
1394 cytbblen = triScaleExpansionZeroElim(4, bb, cdytail, cytbb, t);
1395 temp16clen = triScaleExpansionZeroElim(cytbblen, cytbb, -adx, temp16c, t);
1397 temp32alen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1398 temp48len = triFastExpansionSumZeroElim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1399 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1405 if ((adxtail != 0.0) || (adytail != 0.0))
1407 if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0))
1409 Two_Product(t.m_splitter, bdxtail, cdy, ti1, ti0);
1410 Two_Product(t.m_splitter, bdx, cdytail, tj1, tj0);
1411 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
1414 Two_Product(t.m_splitter, cdxtail, negate, ti1, ti0);
1416 Two_Product(t.m_splitter, cdx, negate, tj1, tj0);
1417 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
1419 bctlen = triFastExpansionSumZeroElim(4, u, 4, v, bct);
1421 Two_Product(t.m_splitter, bdxtail, cdytail, ti1, ti0);
1422 Two_Product(t.m_splitter, cdxtail, bdytail, tj1, tj0);
1423 Two_Two_Diff(ti1, ti0, tj1, tj0, bctt3, bctt[2], bctt[1], bctt[0]);
1437 temp16alen = triScaleExpansionZeroElim(axtbclen, axtbc, adxtail, temp16a, t);
1438 axtbctlen = triScaleExpansionZeroElim(bctlen, bct, adxtail, axtbct, t);
1439 temp32alen = triScaleExpansionZeroElim(axtbctlen, axtbct, 2.0 * adx, temp32a, t);
1440 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1441 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1447 temp8len = triScaleExpansionZeroElim(4, cc, adxtail, temp8, t);
1448 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, bdytail, temp16a, t);
1449 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1456 temp8len = triScaleExpansionZeroElim(4, bb, -adxtail, temp8, t);
1457 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, cdytail, temp16a, t);
1458 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1464 temp32alen = triScaleExpansionZeroElim(axtbctlen, axtbct, adxtail, temp32a, t);
1465 axtbcttlen = triScaleExpansionZeroElim(bcttlen, bctt, adxtail, axtbctt, t);
1466 temp16alen = triScaleExpansionZeroElim(axtbcttlen, axtbctt, 2.0 * adx, temp16a, t);
1467 temp16blen = triScaleExpansionZeroElim(axtbcttlen, axtbctt, adxtail, temp16b, t);
1468 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1469 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1470 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1477 temp16alen = triScaleExpansionZeroElim(aytbclen, aytbc, adytail, temp16a, t);
1478 aytbctlen = triScaleExpansionZeroElim(bctlen, bct, adytail, aytbct, t);
1479 temp32alen = triScaleExpansionZeroElim(aytbctlen, aytbct, 2.0 * ady, temp32a, t);
1480 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1481 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1486 temp32alen = triScaleExpansionZeroElim(aytbctlen, aytbct, adytail, temp32a, t);
1487 aytbcttlen = triScaleExpansionZeroElim(bcttlen, bctt, adytail, aytbctt, t);
1488 temp16alen = triScaleExpansionZeroElim(aytbcttlen, aytbctt, 2.0 * ady, temp16a, t);
1489 temp16blen = triScaleExpansionZeroElim(aytbcttlen, aytbctt, adytail, temp16b, t);
1490 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1491 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1492 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1498 if ((bdxtail != 0.0) || (bdytail != 0.0))
1500 if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0))
1502 Two_Product(t.m_splitter, cdxtail, ady, ti1, ti0);
1503 Two_Product(t.m_splitter, cdx, adytail, tj1, tj0);
1504 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
1507 Two_Product(t.m_splitter, adxtail, negate, ti1, ti0);
1509 Two_Product(t.m_splitter, adx, negate, tj1, tj0);
1510 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
1512 catlen = triFastExpansionSumZeroElim(4, u, 4, v, cat);
1514 Two_Product(t.m_splitter, cdxtail, adytail, ti1, ti0);
1515 Two_Product(t.m_splitter, adxtail, cdytail, tj1, tj0);
1516 Two_Two_Diff(ti1, ti0, tj1, tj0, catt3, catt[2], catt[1], catt[0]);
1530 temp16alen = triScaleExpansionZeroElim(bxtcalen, bxtca, bdxtail, temp16a, t);
1531 bxtcatlen = triScaleExpansionZeroElim(catlen, cat, bdxtail, bxtcat, t);
1532 temp32alen = triScaleExpansionZeroElim(bxtcatlen, bxtcat, 2.0 * bdx, temp32a, t);
1533 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1534 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1540 temp8len = triScaleExpansionZeroElim(4, aa, bdxtail, temp8, t);
1541 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, cdytail, temp16a, t);
1542 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1549 temp8len = triScaleExpansionZeroElim(4, cc, -bdxtail, temp8, t);
1550 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, adytail, temp16a, t);
1551 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1557 temp32alen = triScaleExpansionZeroElim(bxtcatlen, bxtcat, bdxtail, temp32a, t);
1558 bxtcattlen = triScaleExpansionZeroElim(cattlen, catt, bdxtail, bxtcatt, t);
1559 temp16alen = triScaleExpansionZeroElim(bxtcattlen, bxtcatt, 2.0 * bdx, temp16a, t);
1560 temp16blen = triScaleExpansionZeroElim(bxtcattlen, bxtcatt, bdxtail, temp16b, t);
1561 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1562 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1563 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1570 temp16alen = triScaleExpansionZeroElim(bytcalen, bytca, bdytail, temp16a, t);
1571 bytcatlen = triScaleExpansionZeroElim(catlen, cat, bdytail, bytcat, t);
1572 temp32alen = triScaleExpansionZeroElim(bytcatlen, bytcat, 2.0 * bdy, temp32a, t);
1573 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1574 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1579 temp32alen = triScaleExpansionZeroElim(bytcatlen, bytcat, bdytail, temp32a, t);
1580 bytcattlen = triScaleExpansionZeroElim(cattlen, catt, bdytail, bytcatt, t);
1581 temp16alen = triScaleExpansionZeroElim(bytcattlen, bytcatt, 2.0 * bdy, temp16a, t);
1582 temp16blen = triScaleExpansionZeroElim(bytcattlen, bytcatt, bdytail, temp16b, t);
1583 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1584 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1585 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1591 if ((cdxtail != 0.0) || (cdytail != 0.0))
1593 if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0))
1595 Two_Product(t.m_splitter, adxtail, bdy, ti1, ti0);
1596 Two_Product(t.m_splitter, adx, bdytail, tj1, tj0);
1597 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
1600 Two_Product(t.m_splitter, bdxtail, negate, ti1, ti0);
1602 Two_Product(t.m_splitter, bdx, negate, tj1, tj0);
1603 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
1605 abtlen = triFastExpansionSumZeroElim(4, u, 4, v, abt);
1607 Two_Product(t.m_splitter, adxtail, bdytail, ti1, ti0);
1608 Two_Product(t.m_splitter, bdxtail, adytail, tj1, tj0);
1609 Two_Two_Diff(ti1, ti0, tj1, tj0, abtt3, abtt[2], abtt[1], abtt[0]);
1623 temp16alen = triScaleExpansionZeroElim(cxtablen, cxtab, cdxtail, temp16a, t);
1624 cxtabtlen = triScaleExpansionZeroElim(abtlen, abt, cdxtail, cxtabt, t);
1625 temp32alen = triScaleExpansionZeroElim(cxtabtlen, cxtabt, 2.0 * cdx, temp32a, t);
1626 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1627 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1633 temp8len = triScaleExpansionZeroElim(4, bb, cdxtail, temp8, t);
1634 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, adytail, temp16a, t);
1635 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1642 temp8len = triScaleExpansionZeroElim(4, aa, -cdxtail, temp8, t);
1643 temp16alen = triScaleExpansionZeroElim(temp8len, temp8, bdytail, temp16a, t);
1644 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp16alen, temp16a, finother);
1650 temp32alen = triScaleExpansionZeroElim(cxtabtlen, cxtabt, cdxtail, temp32a, t);
1651 cxtabttlen = triScaleExpansionZeroElim(abttlen, abtt, cdxtail, cxtabtt, t);
1652 temp16alen = triScaleExpansionZeroElim(cxtabttlen, cxtabtt, 2.0 * cdx, temp16a, t);
1653 temp16blen = triScaleExpansionZeroElim(cxtabttlen, cxtabtt, cdxtail, temp16b, t);
1654 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1655 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1656 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1663 temp16alen = triScaleExpansionZeroElim(cytablen, cytab, cdytail, temp16a, t);
1664 cytabtlen = triScaleExpansionZeroElim(abtlen, abt, cdytail, cytabt, t);
1665 temp32alen = triScaleExpansionZeroElim(cytabtlen, cytabt, 2.0 * cdy, temp32a, t);
1666 temp48len = triFastExpansionSumZeroElim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1667 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp48len, temp48, finother);
1672 temp32alen = triScaleExpansionZeroElim(cytabtlen, cytabt, cdytail, temp32a, t);
1673 cytabttlen = triScaleExpansionZeroElim(abttlen, abtt, cdytail, cytabtt, t);
1674 temp16alen = triScaleExpansionZeroElim(cytabttlen, cytabtt, 2.0 * cdy, temp16a, t);
1675 temp16blen = triScaleExpansionZeroElim(cytabttlen, cytabtt, cdytail, temp16b, t);
1676 temp32blen = triFastExpansionSumZeroElim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1677 temp64len = triFastExpansionSumZeroElim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1678 finlength = triFastExpansionSumZeroElim(finlength, finnow, temp64len, temp64, finother);
1685 return finnow[finlength - 1];
1700 static void triInitTrianglePool(TriVars& t)
1702 #define TRIPERBLOCK 4092
1703 int trisize, highorderid, elemattid;
1707 trisize = (3 + (highorderid - 3)) *
sizeof(Ttri);
1708 elemattid = (trisize +
sizeof(double) - 1) /
sizeof(double);
1710 triPoolInit(&t.m_triangles, trisize, TRIPERBLOCK, TRIPERBLOCK, 4);
1712 triDummyInit(t.m_triangles.itembytes, t);
1719 static bool triMakeTriangle(Tedgetype newtedge, TriVars& t)
1721 newtedge->tri = (Ttri*)triPoolAlloc(&t.m_triangles);
1724 newtedge->tri[0] = (Ttri)t.m_dummytri;
1725 newtedge->tri[1] = (Ttri)t.m_dummytri;
1726 newtedge->tri[2] = (Ttri)t.m_dummytri;
1728 newtedge->tri[3] =
nullptr;
1729 newtedge->tri[4] =
nullptr;
1730 newtedge->tri[5] =
nullptr;
1731 newtedge->orient = 0;
1767 static bool triMergeHulls(Tedgetype farleft,
1768 Tedgetype innerleft,
1769 Tedgetype innerright,
1774 int changemade, badedge, leftfinished, rightfinished;
1775 Tedge leftcand, rightcand, baseedge, nextedge;
1776 Tedge sidecasing, topcasing, outercasing, checkedge;
1777 Tpt innerleftdest, innerrightorg;
1778 Tpt innerleftapex, innerrightapex;
1779 Tpt farleftpt, farrightpt;
1780 Tpt farleftapex, farrightapex;
1781 Tpt lowerleft, lowerright;
1782 Tpt upperleft, upperright;
1783 Tpt nextapex, checkvertex;
1785 bool canMakeTriangles =
true;
1787 dest(*innerleft, innerleftdest);
1788 apex(*innerleft, innerleftapex);
1789 org(*innerright, innerrightorg);
1790 apex(*innerright, innerrightapex);
1794 org(*farleft, farleftpt);
1795 apex(*farleft, farleftapex);
1796 dest(*farright, farrightpt);
1797 apex(*farright, farrightapex);
1801 while (farleftapex[1] < farleftpt[1])
1803 lnextself(*farleft);
1805 farleftpt = farleftapex;
1806 apex(*farleft, farleftapex);
1808 sym(*innerleft, checkedge);
1809 apex(checkedge, checkvertex);
1810 while (checkvertex[1] > innerleftdest[1])
1812 lnext(checkedge, *innerleft);
1813 innerleftapex = innerleftdest;
1814 innerleftdest = checkvertex;
1815 sym(*innerleft, checkedge);
1816 apex(checkedge, checkvertex);
1818 while (innerrightapex[1] < innerrightorg[1])
1820 lnextself(*innerright);
1821 symself(*innerright);
1822 innerrightorg = innerrightapex;
1823 apex(*innerright, innerrightapex);
1825 sym(*farright, checkedge);
1826 apex(checkedge, checkvertex);
1827 while (checkvertex[1] > farrightpt[1])
1829 lnext(checkedge, *farright);
1830 farrightapex = farrightpt;
1831 farrightpt = checkvertex;
1832 sym(*farright, checkedge);
1833 apex(checkedge, checkvertex);
1842 if (triCounterClockwise(innerleftdest, innerleftapex, innerrightorg, t) > 0.0)
1844 lprevself(*innerleft);
1845 symself(*innerleft);
1846 innerleftdest = innerleftapex;
1847 apex(*innerleft, innerleftapex);
1852 if (triCounterClockwise(innerrightapex, innerrightorg, innerleftdest, t) > 0.0)
1854 lnextself(*innerright);
1855 symself(*innerright);
1856 innerrightorg = innerrightapex;
1857 apex(*innerright, innerrightapex);
1860 }
while (changemade);
1862 sym(*innerleft, leftcand);
1863 sym(*innerright, rightcand);
1865 canMakeTriangles = triMakeTriangle(&baseedge, t);
1866 if (!canMakeTriangles)
1872 bond(baseedge, *innerleft);
1873 lnextself(baseedge);
1874 bond(baseedge, *innerright);
1875 lnextself(baseedge);
1876 setorg(baseedge, innerrightorg);
1877 setdest(baseedge, innerleftdest);
1880 org(*farleft, farleftpt);
1881 if (innerleftdest == farleftpt)
1883 lnext(baseedge, *farleft);
1885 dest(*farright, farrightpt);
1886 if (innerrightorg == farrightpt)
1888 lprev(baseedge, *farright);
1891 lowerleft = innerleftdest;
1892 lowerright = innerrightorg;
1894 apex(leftcand, upperleft);
1895 apex(rightcand, upperright);
1904 leftfinished = triCounterClockwise(upperleft, lowerleft, lowerright, t) <= 0.0;
1905 rightfinished = triCounterClockwise(upperright, lowerleft, lowerright, t) <= 0.0;
1906 if (leftfinished && rightfinished)
1909 canMakeTriangles = triMakeTriangle(&nextedge, t);
1910 if (!canMakeTriangles)
1914 setorg(nextedge, lowerleft);
1915 setdest(nextedge, lowerright);
1919 bond(nextedge, baseedge);
1920 lnextself(nextedge);
1921 bond(nextedge, rightcand);
1922 lnextself(nextedge);
1923 bond(nextedge, leftcand);
1927 org(*farleft, farleftpt);
1928 apex(*farleft, farleftapex);
1929 dest(*farright, farrightpt);
1930 apex(*farright, farrightapex);
1931 sym(*farleft, checkedge);
1932 apex(checkedge, checkvertex);
1935 while (checkvertex[0] < farleftpt[0])
1937 lprev(checkedge, *farleft);
1938 farleftapex = farleftpt;
1939 farleftpt = checkvertex;
1940 sym(*farleft, checkedge);
1941 apex(checkedge, checkvertex);
1943 while (farrightapex[0] > farrightpt[0])
1945 lprevself(*farright);
1947 farrightpt = farrightapex;
1948 apex(*farright, farrightapex);
1959 lprev(leftcand, nextedge);
1961 apex(nextedge, nextapex);
1964 if (nextapex !=
nullptr)
1967 badedge = triInCircle(lowerleft, lowerright, upperleft, nextapex, t) > 0.0;
1972 lnextself(nextedge);
1973 sym(nextedge, topcasing);
1974 lnextself(nextedge);
1975 sym(nextedge, sidecasing);
1976 bond(nextedge, topcasing);
1977 bond(leftcand, sidecasing);
1978 lnextself(leftcand);
1979 sym(leftcand, outercasing);
1980 lprevself(nextedge);
1981 bond(nextedge, outercasing);
1983 setorg(leftcand, lowerleft);
1984 setdest(leftcand,
nullptr);
1985 setapex(leftcand, nextapex);
1986 setorg(nextedge,
nullptr);
1987 setdest(nextedge, upperleft);
1988 setapex(nextedge, nextapex);
1990 upperleft = nextapex;
1993 tedgecopy(sidecasing, nextedge);
1994 apex(nextedge, nextapex);
1995 if (nextapex !=
nullptr)
1998 badedge = triInCircle(lowerleft, lowerright, upperleft, nextapex, t) > 0.0;
2014 lnext(rightcand, nextedge);
2016 apex(nextedge, nextapex);
2020 if (nextapex !=
nullptr)
2023 badedge = triInCircle(lowerleft, lowerright, upperright, nextapex, t) > 0.0;
2029 lprevself(nextedge);
2030 sym(nextedge, topcasing);
2031 lprevself(nextedge);
2032 sym(nextedge, sidecasing);
2033 bond(nextedge, topcasing);
2034 bond(rightcand, sidecasing);
2035 lprevself(rightcand);
2036 sym(rightcand, outercasing);
2037 lnextself(nextedge);
2038 bond(nextedge, outercasing);
2040 setorg(rightcand,
nullptr);
2041 setdest(rightcand, lowerright);
2042 setapex(rightcand, nextapex);
2043 setorg(nextedge, upperright);
2044 setdest(nextedge,
nullptr);
2045 setapex(nextedge, nextapex);
2047 upperright = nextapex;
2050 tedgecopy(sidecasing, nextedge);
2051 apex(nextedge, nextapex);
2052 if (nextapex !=
nullptr)
2055 badedge = triInCircle(lowerleft, lowerright, upperright, nextapex, t) > 0.0;
2066 (!rightfinished && (triInCircle(upperleft, lowerleft, lowerright, upperright, t) > 0.0)))
2070 bond(baseedge, rightcand);
2071 lprev(rightcand, baseedge);
2072 setdest(baseedge, lowerleft);
2073 lowerright = upperright;
2074 sym(baseedge, rightcand);
2075 apex(rightcand, upperright);
2081 bond(baseedge, leftcand);
2082 lnext(leftcand, baseedge);
2083 setorg(baseedge, lowerright);
2084 lowerleft = upperleft;
2085 sym(baseedge, leftcand);
2086 apex(leftcand, upperleft);
2095 static void triNumberNodes(TriVars& t)
2100 triTraversalInit(&t.m_points);
2101 pointloop = triPointTraverse(t);
2103 while (pointloop !=
nullptr)
2105 setpointmark(pointloop, pointnumber, t.m_pointmarkindex);
2106 pointloop = triPointTraverse(t);
2120 static void triPointMedian(Tpt* sortarray,
int arraysize,
int median,
int axis)
2122 int left, right, pivot;
2123 double pivot1, pivot2;
2128 if ((sortarray[0][axis] > sortarray[1][axis]) ||
2129 ((sortarray[0][axis] == sortarray[1][axis]) &&
2130 (sortarray[0][1 - axis] > sortarray[1][1 - axis])))
2132 temp = sortarray[1];
2133 sortarray[1] = sortarray[0];
2134 sortarray[0] = temp;
2138 else if (arraysize == 0)
2141 pivot = (int)triRandomnation((
unsigned int)arraysize);
2142 pivot1 = sortarray[pivot][axis];
2143 pivot2 = sortarray[pivot][1 - axis];
2147 while (left < right)
2153 }
while ((left <= right) &&
2154 ((sortarray[left][axis] < pivot1) ||
2155 ((sortarray[left][axis] == pivot1) && (sortarray[left][1 - axis] < pivot2))));
2160 }
while ((left <= right) &&
2161 ((sortarray[right][axis] > pivot1) ||
2162 ((sortarray[right][axis] == pivot1) && (sortarray[right][1 - axis] > pivot2))));
2166 temp = sortarray[left];
2167 sortarray[left] = sortarray[right];
2168 sortarray[right] = temp;
2175 triPointMedian(sortarray, left, median, axis);
2177 if (right < median - 1)
2180 triPointMedian(&sortarray[right + 1], arraysize - right - 1, median - right - 1, axis);
2191 static void triPointSort(Tpt* sortarray,
int arraysize)
2193 int left, right, pivot;
2194 double pivotx, pivoty;
2199 if ((sortarray[0][0] > sortarray[1][0]) ||
2200 ((sortarray[0][0] == sortarray[1][0]) && (sortarray[0][1] > sortarray[1][1])))
2202 temp = sortarray[1];
2203 sortarray[1] = sortarray[0];
2204 sortarray[0] = temp;
2208 else if (arraysize == 0)
2211 pivot = (int)triRandomnation((
unsigned int)arraysize);
2212 pivotx = sortarray[pivot][0];
2213 pivoty = sortarray[pivot][1];
2217 while (left < right)
2223 }
while ((left <= right) && ((sortarray[left][0] < pivotx) || ((sortarray[left][0] == pivotx) &&
2224 (sortarray[left][1] < pivoty))));
2229 }
while ((left <= right) &&
2230 ((sortarray[right][0] > pivotx) ||
2231 ((sortarray[right][0] == pivotx) && (sortarray[right][1] > pivoty))));
2235 temp = sortarray[left];
2236 sortarray[left] = sortarray[right];
2237 sortarray[right] = temp;
2243 triPointSort(sortarray, left);
2245 if (right < arraysize - 2)
2248 triPointSort(&sortarray[right + 1], arraysize - right - 1);
2256 static Tpt triPointTraverse(TriVars& t)
2262 newpoint = (Tpt)triTraverse(&t.m_points);
2263 if (newpoint ==
nullptr)
2265 }
while (pointmark(newpoint, t.m_pointmarkindex) == -999);
2273 static int* triPoolAlloc(Tmemtype pool)
2275 int *newitem, **newblock;
2276 unsigned long long alignptr;
2278 if (pool->deaditemstack !=
nullptr)
2280 newitem = pool->deaditemstack;
2281 pool->deaditemstack = *(
int**)pool->deaditemstack;
2286 if (pool->unallocateditems == 0)
2288 if (*(pool->nowblock) ==
nullptr)
2292 (
int**)malloc(pool->itemsperblock * pool->itembytes +
sizeof(
int*) + pool->alignbytes);
2293 if (newblock ==
nullptr)
2295 std::string s =
"malloc failed: ";
2300 *(pool->nowblock) = (
int*)newblock;
2302 *newblock =
nullptr;
2305 pool->nowblock = (
int**)*(pool->nowblock);
2307 alignptr = (
unsigned long long)(pool->nowblock + 1);
2309 pool->nextitem = (
int*)(alignptr + (
unsigned long long)pool->alignbytes -
2310 (alignptr % (
unsigned long long)pool->alignbytes));
2312 pool->unallocateditems = pool->itemsperblock;
2315 newitem = pool->nextitem;
2317 pool->nextitem = (
int*)((
char*)pool->nextitem + pool->itembytes);
2319 pool->unallocateditems--;
2330 static void triPoolDealloc(Tmemtype pool,
int* dyingitem)
2333 *((
int**)dyingitem) = pool->deaditemstack;
2334 pool->deaditemstack = dyingitem;
2342 static void triPoolDeinit(Tmemtype pool)
2344 while (pool && pool->firstblock !=
nullptr)
2346 pool->nowblock = (
int**)*(pool->firstblock);
2347 free(pool->firstblock);
2348 pool->firstblock = pool->nowblock;
2368 static bool triPoolInit(Tmemtype pool,
2379 if (alignment >
sizeof(
int*))
2381 pool->alignbytes = alignment;
2385 pool->alignbytes =
sizeof(
int*);
2387 pool->itembytes = ((bytecount - 1) / pool->alignbytes + 1) * pool->alignbytes;
2388 pool->itemsperblock = itemcount;
2389 if (firstitemcount == 0)
2391 pool->itemsfirstblock = itemcount;
2395 pool->itemsfirstblock = firstitemcount;
2402 (
int**)malloc(pool->itemsfirstblock * pool->itembytes +
sizeof(
int*) + pool->alignbytes);
2403 if (pool->firstblock ==
nullptr)
2405 std::string s =
"malloc failed: ";
2411 *(pool->firstblock) =
nullptr;
2413 triPoolRestart(pool);
2424 static void triPoolRestart(Tmemtype pool)
2426 unsigned long long alignptr;
2432 pool->nowblock = pool->firstblock;
2434 alignptr = (
unsigned long long)(pool->nowblock + 1);
2436 pool->nextitem = (
int*)(alignptr + (
unsigned long long)pool->alignbytes -
2437 (alignptr % (
unsigned long long)pool->alignbytes));
2439 pool->unallocateditems = pool->itemsfirstblock;
2441 pool->deaditemstack =
nullptr;
2452 static unsigned long triRandomnation(
unsigned int choices)
2454 static unsigned long randomseed = 1;
2458 randomseed = (randomseed * 1366l + 150889l) % 714025l;
2459 return randomseed / (714025l / choices + 1);
2466 static void triRemoveGhosts(Tedgetype startghost, TriVars& t)
2468 Tedge searchedge, dissolveedge, deadtri;
2472 lprev(*startghost, searchedge);
2473 symself(searchedge);
2474 t.m_dummytri[0] = encode(searchedge);
2476 tedgecopy(*startghost, dissolveedge);
2479 lnext(dissolveedge, deadtri);
2480 lprevself(dissolveedge);
2481 symself(dissolveedge);
2485 if (dissolveedge.tri != t.m_dummytri)
2487 org(dissolveedge, markorg);
2488 if (pointmark(markorg, t.m_pointmarkindex) == 0)
2490 setpointmark(markorg, 1, t.m_pointmarkindex);
2494 dissolveedge.tri[dissolveedge.orient] = (Ttri)t.m_dummytri;
2496 sym(deadtri, dissolveedge);
2498 triTriangleDealloc(deadtri.tri, t);
2499 }
while (!tedgeequal(dissolveedge, *startghost));
2512 static int triScaleExpansionZeroElim(
int elen,
double* e,
double b,
double* h, TriVars& t)
2517 double product1, product0;
2519 double bvirt, avirt, bround, around;
2521 double abig, ahi, alo, bhi, blo;
2522 double err1, err2, err3;
2524 Split(t.m_splitter, b, bhi, blo);
2525 Two_Product_Presplit(t.m_splitter, e[0], b, bhi, blo, Q, hh);
2530 for (eindex = 1; eindex < elen; eindex++)
2533 Two_Product_Presplit(t.m_splitter, enow, b, bhi, blo, product1, product0);
2534 Two_Sum(Q, product0, sum, hh);
2537 Fast_Two_Sum(product1, sum, Q, hh);
2541 if ((Q != 0.0) || (hindex == 0))
2550 static void triTraversalInit(Tmemtype pool)
2552 unsigned long long alignptr;
2554 pool->pathblock = pool->firstblock;
2556 alignptr = (
unsigned long long)(pool->pathblock + 1);
2558 pool->pathitem = (
int*)(alignptr + (
unsigned long long)pool->alignbytes -
2559 (alignptr % (
unsigned long long)pool->alignbytes));
2561 pool->pathitemsleft = pool->itemsfirstblock;
2574 static int* triTraverse(Tmemtype pool)
2577 unsigned long long alignptr;
2579 if (pool->pathitem == pool->nextitem)
2582 if (pool->pathitemsleft == 0)
2585 pool->pathblock = (
int**)*(pool->pathblock);
2587 alignptr = (
unsigned long long)(pool->pathblock + 1);
2589 pool->pathitem = (
int*)(alignptr + (
unsigned long long)pool->alignbytes -
2590 (alignptr % (
unsigned long long)pool->alignbytes));
2592 pool->pathitemsleft = pool->itemsperblock;
2594 newitem = pool->pathitem;
2597 pool->pathitem = (
int*)((
char*)pool->pathitem + pool->itembytes);
2598 pool->pathitemsleft--;
2606 static void triTriangleDealloc(Ttri* dyingtriangle, TriVars& t)
2609 dyingtriangle[3] =
nullptr;
2610 dyingtriangle[4] =
nullptr;
2611 dyingtriangle[5] =
nullptr;
2612 triPoolDealloc(&t.m_triangles, (
int*)dyingtriangle);
2619 static Ttri* triTriangleTraverse(TriVars& t)
2624 newtriangle = (Ttri*)triTraverse(&t.m_triangles);
2625 if (newtriangle ==
nullptr)
2627 }
while (newtriangle[3] ==
nullptr);
2657 t.m_points.maxitems = t.m_triangles.maxitems = 0l;
2658 t.m_points.itembytes = t.m_triangles.itembytes = 0;
2664 if (!triGetPoints(a_Client, t))
2669 if (t.m_numpoints > 2)
2672 triInitTrianglePool(t);
2675 bool ok = triDivConqDelaunay(t);
2679 triFillTriList(a_Client, t);
2682 triPoolDeinit(&t.m_triangles);
2683 if (t.m_dummytribase)
2685 free(t.m_dummytribase);
2691 triPoolDeinit(&t.m_points);
2693 a_Client.FinalizeTriangulation();
2698 triPoolDeinit(&t.m_triangles);
2699 triPoolDeinit(&t.m_points);
Code that creates a Delauney triangulation from points.
Base class used to derive a class to triangulate points.