110 #include "../vmisc/diagnostic.h"
113 QT_WARNING_DISABLE_MSVC(4701)
114 QT_WARNING_DISABLE_GCC("-Wold-style-cast")
115 QT_WARNING_DISABLE_GCC("-Wfloat-equal")
116 #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 408
117 QT_WARNING_DISABLE_GCC(
"-Wmaybe-uninitialized")
119 QT_WARNING_DISABLE_GCC(
"-Wuninitialized")
121 QT_WARNING_DISABLE_CLANG(
"-Wold-style-cast")
122 QT_WARNING_DISABLE_CLANG("-Wmissing-variable-declarations")
123 QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
124 QT_WARNING_DISABLE_CLANG("-Wmissing-prototypes")
125 QT_WARNING_DISABLE_CLANG("-Wconditional-uninitialized")
139 #define REALPRINT doubleprint
140 #define REALRAND doublerand
141 #define NARROWRAND narrowdoublerand
142 #define UNIFORMRAND uniformdoublerand
150 #define Absolute(a) ((a) >= 0.0 ? (a) : -(a))
167 #define Fast_Two_Sum_Tail(a, b, x, y) \
171 #define Fast_Two_Sum(a, b, x, y) \
172 x = (qreal) (a + b); \
173 Fast_Two_Sum_Tail(a, b, x, y)
175 #define Two_Sum_Tail(a, b, x, y) \
176 bvirt = (qreal) (x - a); \
178 bround = b - bvirt; \
179 around = a - avirt; \
182 #define Two_Sum(a, b, x, y) \
183 x = (qreal) (a + b); \
184 Two_Sum_Tail(a, b, x, y)
186 #define Two_Diff_Tail(a, b, x, y) \
187 bvirt = (qreal) (a - x); \
189 bround = bvirt - b; \
190 around = a - avirt; \
193 #define Two_Diff(a, b, x, y) \
194 x = (qreal) (a - b); \
195 Two_Diff_Tail(a, b, x, y)
197 #define Split(a, ahi, alo) \
198 c = (qreal) (splitter * a); \
199 abig = (qreal) (c - a); \
203 #define Two_Product_Tail(a, b, x, y) \
204 Split(a, ahi, alo); \
205 Split(b, bhi, blo); \
206 err1 = x - (ahi * bhi); \
207 err2 = err1 - (alo * bhi); \
208 err3 = err2 - (ahi * blo); \
209 y = (alo * blo) - err3
211 #define Two_Product(a, b, x, y) \
212 x = (qreal) (a * b); \
213 Two_Product_Tail(a, b, x, y)
218 #define Two_Product_Presplit(a, b, bhi, blo, x, y) \
219 x = (qreal) (a * b); \
220 Split(a, ahi, alo); \
221 err1 = x - (ahi * bhi); \
222 err2 = err1 - (alo * bhi); \
223 err3 = err2 - (ahi * blo); \
224 y = (alo * blo) - err3
228 #define Square_Tail(a, x, y) \
229 Split(a, ahi, alo); \
230 err1 = x - (ahi * ahi); \
231 err3 = err1 - ((ahi + ahi) * alo); \
232 y = (alo * alo) - err3
234 #define Square(a, x, y) \
235 x = (qreal) (a * a); \
241 #define Two_One_Sum(a1, a0, b, x2, x1, x0) \
242 Two_Sum(a0, b , _i, x0); \
243 Two_Sum(a1, _i, x2, x1)
245 #define Two_One_Diff(a1, a0, b, x2, x1, x0) \
246 Two_Diff(a0, b , _i, x0); \
247 Two_Sum( a1, _i, x2, x1)
249 #define Two_Two_Sum(a1, a0, b1, b0, x3, x2, x1, x0) \
250 Two_One_Sum(a1, a0, b0, _j, _0, x0); \
251 Two_One_Sum(_j, _0, b1, x3, x2, x1)
253 #define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0) \
254 Two_One_Diff(a1, a0, b0, _j, _0, x0); \
255 Two_One_Diff(_j, _0, b1, x3, x2, x1)
288 qreal check, lastcheck;
308 every_other = !every_other;
310 }
while ((check != 1.0) && (check != lastcheck));
349 qreal avirt, bround, around;
350 int eindex, findex, hindex;
356 if ((fnow > enow) == (fnow > -enow))
367 if ((eindex < elen) && (findex < flen))
369 if ((fnow > enow) == (fnow > -enow))
384 while ((eindex < elen) && (findex < flen))
386 if ((fnow > enow) == (fnow > -enow))
403 while (eindex < elen)
413 while (findex < flen)
423 if ((Q != 0.0) || (hindex == 0))
454 qreal avirt, bround, around;
457 qreal ahi, alo, bhi, blo;
458 qreal err1, err2, err3;
466 for (eindex = 1; eindex < elen; eindex++)
481 if ((Q != 0.0) || (hindex == 0))
502 for (eindex = 1; eindex < elen; eindex++)
509 qreal
incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent)
511 INEXACT qreal adx, bdx, cdx, ady, bdy, cdy;
514 INEXACT qreal bdxcdy1, cdxbdy1, cdxady1, adxcdy1, adxbdy1, bdxady1;
515 qreal bdxcdy0, cdxbdy0, cdxady0, adxcdy0, adxbdy0, bdxady0;
516 qreal bc[4], ca[4], ab[4];
518 qreal axbc[8], axxbc[16], aybc[8], ayybc[16], adet[32];
519 int axbclen, axxbclen, aybclen, ayybclen, alen;
520 qreal bxca[8], bxxca[16], byca[8], byyca[16], bdet[32];
521 int bxcalen, bxxcalen, bycalen, byycalen, blen;
522 qreal cxab[8], cxxab[16], cyab[8], cyyab[16], cdet[32];
523 int cxablen, cxxablen, cyablen, cyyablen, clen;
526 qreal fin1[1152], fin2[1152];
527 qreal *finnow, *finother, *finswap;
530 qreal adxtail, bdxtail, cdxtail, adytail, bdytail, cdytail;
531 INEXACT qreal adxadx1, adyady1, bdxbdx1, bdybdy1, cdxcdx1, cdycdy1;
532 qreal adxadx0, adyady0, bdxbdx0, bdybdy0, cdxcdx0, cdycdy0;
533 qreal aa[4], bb[4], cc[4];
539 qreal temp8[8], temp16a[16], temp16b[16], temp16c[16];
540 qreal temp32a[32], temp32b[32], temp48[48], temp64[64];
541 int temp8len, temp16alen, temp16blen, temp16clen;
542 int temp32alen, temp32blen, temp48len, temp64len;
543 qreal axtbb[8], axtcc[8], aytbb[8], aytcc[8];
545 int axtbblen, axtcclen, aytbblen, aytcclen;
546 qreal bxtaa[8], bxtcc[8], bytaa[8], bytcc[8];
548 int bxtaalen, bxtcclen, bytaalen, bytcclen;
549 qreal cxtaa[8], cxtbb[8], cytaa[8], cytbb[8];
551 int cxtaalen, cxtbblen, cytaalen, cytbblen;
552 qreal axtbc[8], aytbc[8], bxtca[8], bytca[8], cxtab[8], cytab[8];
553 int axtbclen, aytbclen, bxtcalen, bytcalen, cxtablen, cytablen;
554 qreal axtbct[16], aytbct[16], bxtcat[16], bytcat[16], cxtabt[16], cytabt[16];
556 int axtbctlen, aytbctlen, bxtcatlen, bytcatlen, cxtabtlen, cytabtlen;
557 qreal axtbctt[8], aytbctt[8], bxtcatt[8];
558 qreal bytcatt[8], cxtabtt[8], cytabtt[8];
560 int axtbcttlen, aytbcttlen, bxtcattlen, bytcattlen, cxtabttlen, cytabttlen;
561 qreal abt[8], bct[8], cat[8];
563 int abtlen, bctlen, catlen;
564 qreal abtt[4], bctt[4], catt[4];
566 int abttlen, bcttlen, cattlen;
567 INEXACT qreal abtt3, bctt3, catt3;
571 qreal avirt, bround, around;
574 qreal ahi, alo, bhi, blo;
575 qreal err1, err2, err3;
579 adx = (qreal) (pa[0] - pd[0]);
580 bdx = (qreal) (pb[0] - pd[0]);
581 cdx = (qreal) (pc[0] - pd[0]);
582 ady = (qreal) (pa[1] - pd[1]);
583 bdy = (qreal) (pb[1] - pd[1]);
584 cdy = (qreal) (pc[1] - pd[1]);
588 Two_Two_Diff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, bc3, bc[2], bc[1], bc[0]);
598 Two_Two_Diff(cdxady1, cdxady0, adxcdy1, adxcdy0, ca3, ca[2], ca[1], ca[0]);
608 Two_Two_Diff(adxbdy1, adxbdy0, bdxady1, bdxady0, ab3, ab[2], ab[1], ab[0]);
621 if ((det >= errbound) || (-det >= errbound))
632 if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0)
633 && (adytail == 0.0) && (bdytail == 0.0) && (cdytail == 0.0))
639 det += ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail))
640 + 2.0 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx))
641 + ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail))
642 + 2.0 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx))
643 + ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail))
644 + 2.0 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx));
645 if ((det >= errbound) || (-det >= errbound))
653 if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0))
655 Square(adx, adxadx1, adxadx0);
656 Square(ady, adyady1, adyady0);
657 Two_Two_Sum(adxadx1, adxadx0, adyady1, adyady0, aa3, aa[2], aa[1], aa[0]);
660 if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0))
662 Square(bdx, bdxbdx1, bdxbdx0);
663 Square(bdy, bdybdy1, bdybdy0);
664 Two_Two_Sum(bdxbdx1, bdxbdx0, bdybdy1, bdybdy0, bb3, bb[2], bb[1], bb[0]);
667 if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0))
669 Square(cdx, cdxcdx1, cdxcdx0);
670 Square(cdy, cdycdy1, cdycdy0);
671 Two_Two_Sum(cdxcdx1, cdxcdx0, cdycdy1, cdycdy0, cc3, cc[2], cc[1], cc[0]);
689 finswap = finnow; finnow = finother; finother = finswap;
705 finswap = finnow; finnow = finother; finother = finswap;
721 finswap = finnow; finnow = finother; finother = finswap;
737 finswap = finnow; finnow = finother; finother = finswap;
751 temp16blen, temp16b, temp32a);
753 temp32alen, temp32a, temp48);
756 finswap = finnow; finnow = finother; finother = finswap;
772 finswap = finnow; finnow = finother; finother = finswap;
775 if ((adxtail != 0.0) || (adytail != 0.0))
777 if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0))
781 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
787 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
793 Two_Two_Diff(ti1, ti0, tj1, tj0, bctt3, bctt[2], bctt[1], bctt[0]);
812 finswap = finnow; finnow = finother; finother = finswap;
818 finswap = finnow; finnow = finother; finother = finswap;
825 finswap = finnow; finnow = finother; finother = finswap;
835 finswap = finnow; finnow = finother; finother = finswap;
844 finswap = finnow; finnow = finother; finother = finswap;
854 finswap = finnow; finnow = finother; finother = finswap;
857 if ((bdxtail != 0.0) || (bdytail != 0.0))
859 if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0))
863 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
869 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
875 Two_Two_Diff(ti1, ti0, tj1, tj0, catt3, catt[2], catt[1], catt[0]);
923 finswap = finnow; finnow = finother; finother = finswap;
949 if ((cdxtail != 0.0) || (cdytail != 0.0))
951 if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0))
955 Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
961 Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
967 Two_Two_Diff(ti1, ti0, tj1, tj0, abtt3, abtt[2], abtt[1], abtt[0]);
1003 finswap = finnow; finnow = finother; finother = finswap;
1036 finswap = finnow; finnow = finother; finother = finswap;
1040 return finnow[finlength - 1];
1044 qreal
incircle(qreal *pa, qreal *pb, qreal *pc, qreal *pd)
1046 qreal adx, bdx, cdx, ady, bdy, cdy;
1047 qreal bdxcdy, cdxbdy, cdxady, adxcdy, adxbdy, bdxady;
1048 qreal alift, blift, clift;
1050 qreal permanent, errbound;
1052 adx = pa[0] - pd[0];
1053 bdx = pb[0] - pd[0];
1054 cdx = pc[0] - pd[0];
1055 ady = pa[1] - pd[1];
1056 bdy = pb[1] - pd[1];
1057 cdy = pc[1] - pd[1];
1061 alift = adx * adx + ady * ady;
1065 blift = bdx * bdx + bdy * bdy;
1069 clift = cdx * cdx + cdy * cdy;
1071 det = alift * (bdxcdy - cdxbdy)
1072 + blift * (cdxady - adxcdy)
1073 + clift * (adxbdy - bdxady);
1079 if ((det > errbound) || (-det > errbound))
#define Two_Product(a, b, x, y)
qreal estimate(int elen, qreal *e)
qreal incircle(qreal *pa, qreal *pb, qreal *pc, qreal *pd)
#define Two_Product_Presplit(a, b, bhi, blo, x, y)
int fast_expansion_sum_zeroelim(int elen, qreal *e, int flen, qreal *f, qreal *h)
#define Two_Diff_Tail(a, b, x, y)
int scale_expansion_zeroelim(int elen, qreal *e, qreal b, qreal *h)
qreal incircleadapt(qreal *pa, qreal *pb, qreal *pc, qreal *pd, qreal permanent)
#define Two_Sum(a, b, x, y)
#define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0)
#define Two_Two_Sum(a1, a0, b1, b0, x3, x2, x1, x0)
#define Fast_Two_Sum(a, b, x, y)
#define Split(a, ahi, alo)