Blender  V2.93
math_boolean.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "BLI_double2.hh"
22 #include "BLI_double3.hh"
23 #include "BLI_float2.hh"
24 #include "BLI_float3.hh"
25 #include "BLI_hash.hh"
26 #include "BLI_math_boolean.hh"
27 #include "BLI_math_mpq.hh"
28 #include "BLI_mpq2.hh"
29 #include "BLI_mpq3.hh"
30 #include "BLI_span.hh"
31 #include "BLI_utildefines.h"
32 
33 namespace blender {
34 
35 #ifdef WITH_GMP
40 int orient2d(const mpq2 &a, const mpq2 &b, const mpq2 &c)
41 {
42  mpq_class detleft = (a[0] - c[0]) * (b[1] - c[1]);
43  mpq_class detright = (a[1] - c[1]) * (b[0] - c[0]);
44  mpq_class det = detleft - detright;
45  return sgn(det);
46 }
47 
53 int incircle(const mpq2 &a, const mpq2 &b, const mpq2 &c, const mpq2 &d)
54 {
55  mpq_class adx = a[0] - d[0];
56  mpq_class bdx = b[0] - d[0];
57  mpq_class cdx = c[0] - d[0];
58  mpq_class ady = a[1] - d[1];
59  mpq_class bdy = b[1] - d[1];
60  mpq_class cdy = c[1] - d[1];
61 
62  mpq_class bdxcdy = bdx * cdy;
63  mpq_class cdxbdy = cdx * bdy;
64  mpq_class alift = adx * adx + ady * ady;
65 
66  mpq_class cdxady = cdx * ady;
67  mpq_class adxcdy = adx * cdy;
68  mpq_class blift = bdx * bdx + bdy * bdy;
69 
70  mpq_class adxbdy = adx * bdy;
71  mpq_class bdxady = bdx * ady;
72  mpq_class clift = cdx * cdx + cdy * cdy;
73 
74  mpq_class det = alift * (bdxcdy - cdxbdy) + blift * (cdxady - adxcdy) +
75  clift * (adxbdy - bdxady);
76  return sgn(det);
77 }
78 
85 int orient3d(const mpq3 &a, const mpq3 &b, const mpq3 &c, const mpq3 &d)
86 {
87  mpq_class adx = a[0] - d[0];
88  mpq_class bdx = b[0] - d[0];
89  mpq_class cdx = c[0] - d[0];
90  mpq_class ady = a[1] - d[1];
91  mpq_class bdy = b[1] - d[1];
92  mpq_class cdy = c[1] - d[1];
93  mpq_class adz = a[2] - d[2];
94  mpq_class bdz = b[2] - d[2];
95  mpq_class cdz = c[2] - d[2];
96 
97  mpq_class bdxcdy = bdx * cdy;
98  mpq_class cdxbdy = cdx * bdy;
99 
100  mpq_class cdxady = cdx * ady;
101  mpq_class adxcdy = adx * cdy;
102 
103  mpq_class adxbdy = adx * bdy;
104  mpq_class bdxady = bdx * ady;
105 
106  mpq_class det = adz * (bdxcdy - cdxbdy) + bdz * (cdxady - adxcdy) + cdz * (adxbdy - bdxady);
107  return sgn(det);
108 }
109 #endif /* WITH_GMP */
110 
117 namespace robust_pred {
118 
119 /* Using Shewchuk's file here, edited to removed unneeded functions,
120  * change REAL to double everywhere, added const to some arguments,
121  * and to export only the following declared non-static functions.
122  *
123  * Since this is C++, an instantiated singleton class is used to make
124  * sure that #exactinit() is called once.
125  * (Because it's undefined when this is called in initialization of all modules,
126  * other modules shouldn't use these functions in initialization.)
127  */
128 
129 void exactinit();
130 double orient2dfast(const double *pa, const double *pb, const double *pc);
131 double orient2d(const double *pa, const double *pb, const double *pc);
132 double orient3dfast(const double *pa, const double *pb, const double *pc, const double *pd);
133 double orient3d(const double *pa, const double *pb, const double *pc, const double *pd);
134 double incirclefast(const double *pa, const double *pb, const double *pc, const double *pd);
135 double incircle(const double *pa, const double *pb, const double *pc, const double *pd);
136 double inspherefast(
137  const double *pa, const double *pb, const double *pc, const double *pd, const double *pe);
138 double insphere(
139  const double *pa, const double *pb, const double *pc, const double *pd, const double *pe);
140 
142  public:
144  {
145  exactinit();
146  }
147 };
148 
150 
151 /* Routines for Arbitrary Precision Floating-point Arithmetic
152  * and Fast Robust Geometric Predicates
153  * (predicates.c)
154  *
155  * May 18, 1996
156  *
157  * Placed in the public domain by
158  * Jonathan Richard Shewchuk
159  * School of Computer Science
160  * Carnegie Mellon University
161  * 5000 Forbes Avenue
162  * Pittsburgh, Pennsylvania 15213-3891
163  * <jrs@cs.cmu.edu>
164  *
165  * This file contains C implementation of algorithms for exact addition
166  * and multiplication of floating-point numbers, and predicates for
167  * robustly performing the orientation and incircle tests used in
168  * computational geometry. The algorithms and underlying theory are
169  * described in Jonathan Richard Shewchuk. "Adaptive Precision Floating-
170  * Point Arithmetic and Fast Robust Geometric Predicates." Technical
171  * Report CMU-CS-96-140, School of Computer Science, Carnegie Mellon
172  * University, Pittsburgh, Pennsylvania, May 1996. (Submitted to
173  * Discrete & Computational Geometry.)
174  *
175  * This file, the paper listed above, and other information are available
176  * from the Web page http://www.cs.cmu.edu/~quake/robust.html .
177  *
178  *
179  * Using this code:
180  *
181  * First, read the short or long version of the paper (from the Web page above).
182  *
183  * Be sure to call #exactinit() once, before calling any of the arithmetic
184  * functions or geometric predicates. Also be sure to turn on the
185  * optimizer when compiling this file.
186  */
187 
188 /* On some machines, the exact arithmetic routines might be defeated by the
189  * use of internal extended precision floating-point registers. Sometimes
190  * this problem can be fixed by defining certain values to be volatile,
191  * thus forcing them to be stored to memory and rounded off. This isn't
192  * a great solution, though, as it slows the arithmetic down.
193  *
194  * To try this out, write "#define INEXACT volatile" below. Normally,
195  * however, INEXACT should be defined to be nothing. ("#define INEXACT".)
196  */
197 
198 #define INEXACT /* Nothing */
199 /* #define INEXACT volatile */
200 
201 /* Which of the following two methods of finding the absolute values is
202  * fastest is compiler-dependent. A few compilers can inline and optimize
203  * the fabs() call; but most will incur the overhead of a function call,
204  * which is disastrously slow. A faster way on IEEE machines might be to
205  * mask the appropriate bit, but that's difficult to do in C.
206  */
207 
208 #define Absolute(a) ((a) >= 0.0 ? (a) : -(a))
209 /* #define Absolute(a) fabs(a) */
210 
211 /* Many of the operations are broken up into two pieces, a main part that
212  * performs an approximate operation, and a "tail" that computes the
213  * round-off error of that operation.
214  *
215  * The operations Fast_Two_Sum(), Fast_Two_Diff(), Two_Sum(), Two_Diff(),
216  * Split(), and Two_Product() are all implemented as described in the
217  * reference. Each of these macros requires certain variables to be
218  * defined in the calling routine. The variables `bvirt', `c', `abig',
219  * `_i', `_j', `_k', `_l', `_m', and `_n' are declared `INEXACT' because
220  * they store the result of an operation that may incur round-off error.
221  * The input parameter `x' (or the highest numbered `x_' parameter) must
222  * also be declared `INEXACT'.
223  */
224 
225 #define Fast_Two_Sum_Tail(a, b, x, y) \
226  bvirt = x - a; \
227  y = b - bvirt
228 
229 #define Fast_Two_Sum(a, b, x, y) \
230  x = (double)(a + b); \
231  Fast_Two_Sum_Tail(a, b, x, y)
232 
233 #define Fast_Two_Diff_Tail(a, b, x, y) \
234  bvirt = a - x; \
235  y = bvirt - b
236 
237 #define Fast_Two_Diff(a, b, x, y) \
238  x = (double)(a - b); \
239  Fast_Two_Diff_Tail(a, b, x, y)
240 
241 #define Two_Sum_Tail(a, b, x, y) \
242  bvirt = (double)(x - a); \
243  avirt = x - bvirt; \
244  bround = b - bvirt; \
245  around = a - avirt; \
246  y = around + bround
247 
248 #define Two_Sum(a, b, x, y) \
249  x = (double)(a + b); \
250  Two_Sum_Tail(a, b, x, y)
251 
252 #define Two_Diff_Tail(a, b, x, y) \
253  bvirt = (double)(a - x); \
254  avirt = x + bvirt; \
255  bround = bvirt - b; \
256  around = a - avirt; \
257  y = around + bround
258 
259 #define Two_Diff(a, b, x, y) \
260  x = (double)(a - b); \
261  Two_Diff_Tail(a, b, x, y)
262 
263 #define Split(a, ahi, alo) \
264  c = (double)(splitter * a); \
265  abig = (double)(c - a); \
266  ahi = c - abig; \
267  alo = a - ahi
268 
269 #define Two_Product_Tail(a, b, x, y) \
270  Split(a, ahi, alo); \
271  Split(b, bhi, blo); \
272  err1 = x - (ahi * bhi); \
273  err2 = err1 - (alo * bhi); \
274  err3 = err2 - (ahi * blo); \
275  y = (alo * blo) - err3
276 
277 #define Two_Product(a, b, x, y) \
278  x = (double)(a * b); \
279  Two_Product_Tail(a, b, x, y)
280 
281 #define Two_Product_Presplit(a, b, bhi, blo, x, y) \
282  x = (double)(a * b); \
283  Split(a, ahi, alo); \
284  err1 = x - (ahi * bhi); \
285  err2 = err1 - (alo * bhi); \
286  err3 = err2 - (ahi * blo); \
287  y = (alo * blo) - err3
288 
289 #define Two_Product_2Presplit(a, ahi, alo, b, bhi, blo, x, y) \
290  x = (double)(a * b); \
291  err1 = x - (ahi * bhi); \
292  err2 = err1 - (alo * bhi); \
293  err3 = err2 - (ahi * blo); \
294  y = (alo * blo) - err3
295 
296 #define Square_Tail(a, x, y) \
297  Split(a, ahi, alo); \
298  err1 = x - (ahi * ahi); \
299  err3 = err1 - ((ahi + ahi) * alo); \
300  y = (alo * alo) - err3
301 
302 #define Square(a, x, y) \
303  x = (double)(a * a); \
304  Square_Tail(a, x, y)
305 
306 #define Two_One_Sum(a1, a0, b, x2, x1, x0) \
307  Two_Sum(a0, b, _i, x0); \
308  Two_Sum(a1, _i, x2, x1)
309 
310 #define Two_One_Diff(a1, a0, b, x2, x1, x0) \
311  Two_Diff(a0, b, _i, x0); \
312  Two_Sum(a1, _i, x2, x1)
313 
314 #define Two_Two_Sum(a1, a0, b1, b0, x3, x2, x1, x0) \
315  Two_One_Sum(a1, a0, b0, _j, _0, x0); \
316  Two_One_Sum(_j, _0, b1, x3, x2, x1)
317 
318 #define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0) \
319  Two_One_Diff(a1, a0, b0, _j, _0, x0); \
320  Two_One_Diff(_j, _0, b1, x3, x2, x1)
321 
322 #define Four_One_Sum(a3, a2, a1, a0, b, x4, x3, x2, x1, x0) \
323  Two_One_Sum(a1, a0, b, _j, x1, x0); \
324  Two_One_Sum(a3, a2, _j, x4, x3, x2)
325 
326 #define Four_Two_Sum(a3, a2, a1, a0, b1, b0, x5, x4, x3, x2, x1, x0) \
327  Four_One_Sum(a3, a2, a1, a0, b0, _k, _2, _1, _0, x0); \
328  Four_One_Sum(_k, _2, _1, _0, b1, x5, x4, x3, x2, x1)
329 
330 #define Four_Four_Sum(a3, a2, a1, a0, b4, b3, b1, b0, x7, x6, x5, x4, x3, x2, x1, x0) \
331  Four_Two_Sum(a3, a2, a1, a0, b1, b0, _l, _2, _1, _0, x1, x0); \
332  Four_Two_Sum(_l, _2, _1, _0, b4, b3, x7, x6, x5, x4, x3, x2)
333 
334 #define Eight_One_Sum(a7, a6, a5, a4, a3, a2, a1, a0, b, x8, x7, x6, x5, x4, x3, x2, x1, x0) \
335  Four_One_Sum(a3, a2, a1, a0, b, _j, x3, x2, x1, x0); \
336  Four_One_Sum(a7, a6, a5, a4, _j, x8, x7, x6, x5, x4)
337 
338 #define Eight_Two_Sum( \
339  a7, a6, a5, a4, a3, a2, a1, a0, b1, b0, x9, x8, x7, x6, x5, x4, x3, x2, x1, x0) \
340  Eight_One_Sum(a7, a6, a5, a4, a3, a2, a1, a0, b0, _k, _6, _5, _4, _3, _2, _1, _0, x0); \
341  Eight_One_Sum(_k, _6, _5, _4, _3, _2, _1, _0, b1, x9, x8, x7, x6, x5, x4, x3, x2, x1)
342 
343 #define Eight_Four_Sum(a7, \
344  a6, \
345  a5, \
346  a4, \
347  a3, \
348  a2, \
349  a1, \
350  a0, \
351  b4, \
352  b3, \
353  b1, \
354  b0, \
355  x11, \
356  x10, \
357  x9, \
358  x8, \
359  x7, \
360  x6, \
361  x5, \
362  x4, \
363  x3, \
364  x2, \
365  x1, \
366  x0) \
367  Eight_Two_Sum(a7, a6, a5, a4, a3, a2, a1, a0, b1, b0, _l, _6, _5, _4, _3, _2, _1, _0, x1, x0); \
368  Eight_Two_Sum(_l, _6, _5, _4, _3, _2, _1, _0, b4, b3, x11, x10, x9, x8, x7, x6, x5, x4, x3, x2)
369 
370 #define Two_One_Product(a1, a0, b, x3, x2, x1, x0) \
371  Split(b, bhi, blo); \
372  Two_Product_Presplit(a0, b, bhi, blo, _i, x0); \
373  Two_Product_Presplit(a1, b, bhi, blo, _j, _0); \
374  Two_Sum(_i, _0, _k, x1); \
375  Fast_Two_Sum(_j, _k, x3, x2)
376 
377 #define Four_One_Product(a3, a2, a1, a0, b, x7, x6, x5, x4, x3, x2, x1, x0) \
378  Split(b, bhi, blo); \
379  Two_Product_Presplit(a0, b, bhi, blo, _i, x0); \
380  Two_Product_Presplit(a1, b, bhi, blo, _j, _0); \
381  Two_Sum(_i, _0, _k, x1); \
382  Fast_Two_Sum(_j, _k, _i, x2); \
383  Two_Product_Presplit(a2, b, bhi, blo, _j, _0); \
384  Two_Sum(_i, _0, _k, x3); \
385  Fast_Two_Sum(_j, _k, _i, x4); \
386  Two_Product_Presplit(a3, b, bhi, blo, _j, _0); \
387  Two_Sum(_i, _0, _k, x5); \
388  Fast_Two_Sum(_j, _k, x7, x6)
389 
390 #define Two_Two_Product(a1, a0, b1, b0, x7, x6, x5, x4, x3, x2, x1, x0) \
391  Split(a0, a0hi, a0lo); \
392  Split(b0, bhi, blo); \
393  Two_Product_2Presplit(a0, a0hi, a0lo, b0, bhi, blo, _i, x0); \
394  Split(a1, a1hi, a1lo); \
395  Two_Product_2Presplit(a1, a1hi, a1lo, b0, bhi, blo, _j, _0); \
396  Two_Sum(_i, _0, _k, _1); \
397  Fast_Two_Sum(_j, _k, _l, _2); \
398  Split(b1, bhi, blo); \
399  Two_Product_2Presplit(a0, a0hi, a0lo, b1, bhi, blo, _i, _0); \
400  Two_Sum(_1, _0, _k, x1); \
401  Two_Sum(_2, _k, _j, _1); \
402  Two_Sum(_l, _j, _m, _2); \
403  Two_Product_2Presplit(a1, a1hi, a1lo, b1, bhi, blo, _j, _0); \
404  Two_Sum(_i, _0, _n, _0); \
405  Two_Sum(_1, _0, _i, x2); \
406  Two_Sum(_2, _i, _k, _1); \
407  Two_Sum(_m, _k, _l, _2); \
408  Two_Sum(_j, _n, _k, _0); \
409  Two_Sum(_1, _0, _j, x3); \
410  Two_Sum(_2, _j, _i, _1); \
411  Two_Sum(_l, _i, _m, _2); \
412  Two_Sum(_1, _k, _i, x4); \
413  Two_Sum(_2, _i, _k, x5); \
414  Two_Sum(_m, _k, x7, x6)
415 
416 #define Two_Square(a1, a0, x5, x4, x3, x2, x1, x0) \
417  Square(a0, _j, x0); \
418  _0 = a0 + a0; \
419  Two_Product(a1, _0, _k, _1); \
420  Two_One_Sum(_k, _1, _j, _l, _2, x1); \
421  Square(a1, _j, _1); \
422  Two_Two_Sum(_j, _1, _l, _2, x5, x4, x3, x2)
423 
424 static double splitter; /* = 2^ceiling(p / 2) + 1. Used to split floats in half. */
425 static double epsilon; /* = 2^(-p). Used to estimate round-off errors. */
426 /* A set of coefficients used to calculate maximum round-off errors. */
427 static double resulterrbound;
432 
450 void exactinit()
451 {
452  double half;
453  double check, lastcheck;
454  int every_other;
455 
456  every_other = 1;
457  half = 0.5;
458  epsilon = 1.0;
459  splitter = 1.0;
460  check = 1.0;
461  /* Repeatedly divide `epsilon' by two until it is too small to add to
462  * one without causing round-off. (Also check if the sum is equal to
463  * the previous sum, for machines that round up instead of using exact
464  * rounding. Not that this library will work on such machines anyway. */
465  do {
466  lastcheck = check;
467  epsilon *= half;
468  if (every_other) {
469  splitter *= 2.0;
470  }
471  every_other = !every_other;
472  check = 1.0 + epsilon;
473  } while (!ELEM(check, 1.0, lastcheck));
474  splitter += 1.0;
475 
476  /* Error bounds for orientation and #incircle tests. */
477  resulterrbound = (3.0 + 8.0 * epsilon) * epsilon;
478  ccwerrboundA = (3.0 + 16.0 * epsilon) * epsilon;
479  ccwerrboundB = (2.0 + 12.0 * epsilon) * epsilon;
480  ccwerrboundC = (9.0 + 64.0 * epsilon) * epsilon * epsilon;
481  o3derrboundA = (7.0 + 56.0 * epsilon) * epsilon;
482  o3derrboundB = (3.0 + 28.0 * epsilon) * epsilon;
483  o3derrboundC = (26.0 + 288.0 * epsilon) * epsilon * epsilon;
484  iccerrboundA = (10.0 + 96.0 * epsilon) * epsilon;
485  iccerrboundB = (4.0 + 48.0 * epsilon) * epsilon;
486  iccerrboundC = (44.0 + 576.0 * epsilon) * epsilon * epsilon;
487  isperrboundA = (16.0 + 224.0 * epsilon) * epsilon;
488  isperrboundB = (5.0 + 72.0 * epsilon) * epsilon;
489  isperrboundC = (71.0 + 1408.0 * epsilon) * epsilon * epsilon;
490 }
491 
500  int elen, const double *e, int flen, const double *f, double *h)
501 {
502  double Q;
503  INEXACT double Qnew;
504  INEXACT double hh;
505  INEXACT double bvirt;
506  double avirt, bround, around;
507  int eindex, findex, hindex;
508  double enow, fnow;
509 
510  enow = e[0];
511  fnow = f[0];
512  eindex = findex = 0;
513  if ((fnow > enow) == (fnow > -enow)) {
514  Q = enow;
515  enow = e[++eindex];
516  }
517  else {
518  Q = fnow;
519  fnow = f[++findex];
520  }
521  hindex = 0;
522  if ((eindex < elen) && (findex < flen)) {
523  if ((fnow > enow) == (fnow > -enow)) {
524  Fast_Two_Sum(enow, Q, Qnew, hh);
525  enow = e[++eindex];
526  }
527  else {
528  Fast_Two_Sum(fnow, Q, Qnew, hh);
529  fnow = f[++findex];
530  }
531  Q = Qnew;
532  if (hh != 0.0) {
533  h[hindex++] = hh;
534  }
535  while ((eindex < elen) && (findex < flen)) {
536  if ((fnow > enow) == (fnow > -enow)) {
537  Two_Sum(Q, enow, Qnew, hh);
538  enow = e[++eindex];
539  }
540  else {
541  Two_Sum(Q, fnow, Qnew, hh);
542  fnow = f[++findex];
543  }
544  Q = Qnew;
545  if (hh != 0.0) {
546  h[hindex++] = hh;
547  }
548  }
549  }
550  while (eindex < elen) {
551  Two_Sum(Q, enow, Qnew, hh);
552  enow = e[++eindex];
553  Q = Qnew;
554  if (hh != 0.0) {
555  h[hindex++] = hh;
556  }
557  }
558  while (findex < flen) {
559  Two_Sum(Q, fnow, Qnew, hh);
560  fnow = f[++findex];
561  Q = Qnew;
562  if (hh != 0.0) {
563  h[hindex++] = hh;
564  }
565  }
566  if ((Q != 0.0) || (hindex == 0)) {
567  h[hindex++] = Q;
568  }
569  return hindex;
570 }
571 
572 /* scale_expansion_zeroelim() Multiply an expansion by a scalar,
573  * eliminating zero components from the
574  * output expansion.
575  *
576  * Sets h = be. See either version of my paper for details.
577  * e and h cannot be the same.
578  */
579 static int scale_expansion_zeroelim(int elen, const double *e, double b, double *h)
580 {
581  INEXACT double Q, sum;
582  double hh;
583  INEXACT double product1;
584  double product0;
585  int eindex, hindex;
586  double enow;
587  INEXACT double bvirt;
588  double avirt, bround, around;
589  INEXACT double c;
590  INEXACT double abig;
591  double ahi, alo, bhi, blo;
592  double err1, err2, err3;
593 
594  Split(b, bhi, blo);
595  Two_Product_Presplit(e[0], b, bhi, blo, Q, hh);
596  hindex = 0;
597  if (hh != 0) {
598  h[hindex++] = hh;
599  }
600  for (eindex = 1; eindex < elen; eindex++) {
601  enow = e[eindex];
602  Two_Product_Presplit(enow, b, bhi, blo, product1, product0);
603  Two_Sum(Q, product0, sum, hh);
604  if (hh != 0) {
605  h[hindex++] = hh;
606  }
607  Fast_Two_Sum(product1, sum, Q, hh);
608  if (hh != 0) {
609  h[hindex++] = hh;
610  }
611  }
612  if ((Q != 0.0) || (hindex == 0)) {
613  h[hindex++] = Q;
614  }
615  return hindex;
616 }
617 
618 /* estimate() Produce a one-word estimate of an expansion's value. */
619 static double estimate(int elen, const double *e)
620 {
621  double Q;
622  int eindex;
623 
624  Q = e[0];
625  for (eindex = 1; eindex < elen; eindex++) {
626  Q += e[eindex];
627  }
628  return Q;
629 }
630 
649 double orient2dfast(const double *pa, const double *pb, const double *pc)
650 {
651  double acx, bcx, acy, bcy;
652 
653  acx = pa[0] - pc[0];
654  bcx = pb[0] - pc[0];
655  acy = pa[1] - pc[1];
656  bcy = pb[1] - pc[1];
657  return acx * bcy - acy * bcx;
658 }
659 
660 static double orient2dadapt(const double *pa, const double *pb, const double *pc, double detsum)
661 {
662  INEXACT double acx, acy, bcx, bcy;
663  double acxtail, acytail, bcxtail, bcytail;
664  INEXACT double detleft, detright;
665  double detlefttail, detrighttail;
666  double det, errbound;
667  double B[4], C1[8], C2[12], D[16];
668  INEXACT double B3;
669  int C1length, C2length, Dlength;
670  double u[4];
671  INEXACT double u3;
672  INEXACT double s1, t1;
673  double s0, t0;
674 
675  INEXACT double bvirt;
676  double avirt, bround, around;
677  INEXACT double c;
678  INEXACT double abig;
679  double ahi, alo, bhi, blo;
680  double err1, err2, err3;
681  INEXACT double _i, _j;
682  double _0;
683 
684  acx = (double)(pa[0] - pc[0]);
685  bcx = (double)(pb[0] - pc[0]);
686  acy = (double)(pa[1] - pc[1]);
687  bcy = (double)(pb[1] - pc[1]);
688 
689  Two_Product(acx, bcy, detleft, detlefttail);
690  Two_Product(acy, bcx, detright, detrighttail);
691 
692  Two_Two_Diff(detleft, detlefttail, detright, detrighttail, B3, B[2], B[1], B[0]);
693  B[3] = B3;
694 
695  det = estimate(4, B);
696  errbound = ccwerrboundB * detsum;
697  if ((det >= errbound) || (-det >= errbound)) {
698  return det;
699  }
700 
701  Two_Diff_Tail(pa[0], pc[0], acx, acxtail);
702  Two_Diff_Tail(pb[0], pc[0], bcx, bcxtail);
703  Two_Diff_Tail(pa[1], pc[1], acy, acytail);
704  Two_Diff_Tail(pb[1], pc[1], bcy, bcytail);
705 
706  if ((acxtail == 0.0) && (acytail == 0.0) && (bcxtail == 0.0) && (bcytail == 0.0)) {
707  return det;
708  }
709 
710  errbound = ccwerrboundC * detsum + resulterrbound * Absolute(det);
711  det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
712  if ((det >= errbound) || (-det >= errbound)) {
713  return det;
714  }
715 
716  Two_Product(acxtail, bcy, s1, s0);
717  Two_Product(acytail, bcx, t1, t0);
718  Two_Two_Diff(s1, s0, t1, t0, u3, u[2], u[1], u[0]);
719  u[3] = u3;
720  C1length = fast_expansion_sum_zeroelim(4, B, 4, u, C1);
721 
722  Two_Product(acx, bcytail, s1, s0);
723  Two_Product(acy, bcxtail, t1, t0);
724  Two_Two_Diff(s1, s0, t1, t0, u3, u[2], u[1], u[0]);
725  u[3] = u3;
726  C2length = fast_expansion_sum_zeroelim(C1length, C1, 4, u, C2);
727 
728  Two_Product(acxtail, bcytail, s1, s0);
729  Two_Product(acytail, bcxtail, t1, t0);
730  Two_Two_Diff(s1, s0, t1, t0, u3, u[2], u[1], u[0]);
731  u[3] = u3;
732  Dlength = fast_expansion_sum_zeroelim(C2length, C2, 4, u, D);
733 
734  return (D[Dlength - 1]);
735 }
736 
737 double orient2d(const double *pa, const double *pb, const double *pc)
738 {
739  double detleft, detright, det;
740  double detsum, errbound;
741 
742  detleft = (pa[0] - pc[0]) * (pb[1] - pc[1]);
743  detright = (pa[1] - pc[1]) * (pb[0] - pc[0]);
744  det = detleft - detright;
745 
746  if (detleft > 0.0) {
747  if (detright <= 0.0) {
748  return det;
749  }
750  detsum = detleft + detright;
751  }
752  else if (detleft < 0.0) {
753  if (detright >= 0.0) {
754  return det;
755  }
756  detsum = -detleft - detright;
757  }
758  else {
759  return det;
760  }
761 
762  errbound = ccwerrboundA * detsum;
763  if ((det >= errbound) || (-det >= errbound)) {
764  return det;
765  }
766 
767  return orient2dadapt(pa, pb, pc, detsum);
768 }
769 
792 double orient3dfast(const double *pa, const double *pb, const double *pc, const double *pd)
793 {
794  double adx, bdx, cdx;
795  double ady, bdy, cdy;
796  double adz, bdz, cdz;
797 
798  adx = pa[0] - pd[0];
799  bdx = pb[0] - pd[0];
800  cdx = pc[0] - pd[0];
801  ady = pa[1] - pd[1];
802  bdy = pb[1] - pd[1];
803  cdy = pc[1] - pd[1];
804  adz = pa[2] - pd[2];
805  bdz = pb[2] - pd[2];
806  cdz = pc[2] - pd[2];
807 
808  return adx * (bdy * cdz - bdz * cdy) + bdx * (cdy * adz - cdz * ady) +
809  cdx * (ady * bdz - adz * bdy);
810 }
811 
816 /* NOLINTNEXTLINE: readability-function-size */
817 static double orient3dadapt(
818  const double *pa, const double *pb, const double *pc, const double *pd, double permanent)
819 {
820  INEXACT double adx, bdx, cdx, ady, bdy, cdy, adz, bdz, cdz;
821  double det, errbound;
822 
823  INEXACT double bdxcdy1, cdxbdy1, cdxady1, adxcdy1, adxbdy1, bdxady1;
824  double bdxcdy0, cdxbdy0, cdxady0, adxcdy0, adxbdy0, bdxady0;
825  double bc[4], ca[4], ab[4];
826  INEXACT double bc3, ca3, ab3;
827  double adet[8], bdet[8], cdet[8];
828  int alen, blen, clen;
829  double abdet[16];
830  int ablen;
831  double *finnow, *finother, *finswap;
832  double fin1[192], fin2[192];
833  int finlength;
834 
835  double adxtail, bdxtail, cdxtail;
836  double adytail, bdytail, cdytail;
837  double adztail, bdztail, cdztail;
838  INEXACT double at_blarge, at_clarge;
839  INEXACT double bt_clarge, bt_alarge;
840  INEXACT double ct_alarge, ct_blarge;
841  double at_b[4], at_c[4], bt_c[4], bt_a[4], ct_a[4], ct_b[4];
842  int at_blen, at_clen, bt_clen, bt_alen, ct_alen, ct_blen;
843  INEXACT double bdxt_cdy1, cdxt_bdy1, cdxt_ady1;
844  INEXACT double adxt_cdy1, adxt_bdy1, bdxt_ady1;
845  double bdxt_cdy0, cdxt_bdy0, cdxt_ady0;
846  double adxt_cdy0, adxt_bdy0, bdxt_ady0;
847  INEXACT double bdyt_cdx1, cdyt_bdx1, cdyt_adx1;
848  INEXACT double adyt_cdx1, adyt_bdx1, bdyt_adx1;
849  double bdyt_cdx0, cdyt_bdx0, cdyt_adx0;
850  double adyt_cdx0, adyt_bdx0, bdyt_adx0;
851  double bct[8], cat[8], abt[8];
852  int bctlen, catlen, abtlen;
853  INEXACT double bdxt_cdyt1, cdxt_bdyt1, cdxt_adyt1;
854  INEXACT double adxt_cdyt1, adxt_bdyt1, bdxt_adyt1;
855  double bdxt_cdyt0, cdxt_bdyt0, cdxt_adyt0;
856  double adxt_cdyt0, adxt_bdyt0, bdxt_adyt0;
857  double u[4], v[12], w[16];
858  INEXACT double u3;
859  int vlength, wlength;
860  double negate;
861 
862  INEXACT double bvirt;
863  double avirt, bround, around;
864  INEXACT double c;
865  INEXACT double abig;
866  double ahi, alo, bhi, blo;
867  double err1, err2, err3;
868  INEXACT double _i, _j, _k;
869  double _0;
870 
871  adx = (double)(pa[0] - pd[0]);
872  bdx = (double)(pb[0] - pd[0]);
873  cdx = (double)(pc[0] - pd[0]);
874  ady = (double)(pa[1] - pd[1]);
875  bdy = (double)(pb[1] - pd[1]);
876  cdy = (double)(pc[1] - pd[1]);
877  adz = (double)(pa[2] - pd[2]);
878  bdz = (double)(pb[2] - pd[2]);
879  cdz = (double)(pc[2] - pd[2]);
880 
881  Two_Product(bdx, cdy, bdxcdy1, bdxcdy0);
882  Two_Product(cdx, bdy, cdxbdy1, cdxbdy0);
883  Two_Two_Diff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, bc3, bc[2], bc[1], bc[0]);
884  bc[3] = bc3;
885  alen = scale_expansion_zeroelim(4, bc, adz, adet);
886 
887  Two_Product(cdx, ady, cdxady1, cdxady0);
888  Two_Product(adx, cdy, adxcdy1, adxcdy0);
889  Two_Two_Diff(cdxady1, cdxady0, adxcdy1, adxcdy0, ca3, ca[2], ca[1], ca[0]);
890  ca[3] = ca3;
891  blen = scale_expansion_zeroelim(4, ca, bdz, bdet);
892 
893  Two_Product(adx, bdy, adxbdy1, adxbdy0);
894  Two_Product(bdx, ady, bdxady1, bdxady0);
895  Two_Two_Diff(adxbdy1, adxbdy0, bdxady1, bdxady0, ab3, ab[2], ab[1], ab[0]);
896  ab[3] = ab3;
897  clen = scale_expansion_zeroelim(4, ab, cdz, cdet);
898 
899  ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
900  finlength = fast_expansion_sum_zeroelim(ablen, abdet, clen, cdet, fin1);
901 
902  det = estimate(finlength, fin1);
903  errbound = o3derrboundB * permanent;
904  if ((det >= errbound) || (-det >= errbound)) {
905  return det;
906  }
907 
908  Two_Diff_Tail(pa[0], pd[0], adx, adxtail);
909  Two_Diff_Tail(pb[0], pd[0], bdx, bdxtail);
910  Two_Diff_Tail(pc[0], pd[0], cdx, cdxtail);
911  Two_Diff_Tail(pa[1], pd[1], ady, adytail);
912  Two_Diff_Tail(pb[1], pd[1], bdy, bdytail);
913  Two_Diff_Tail(pc[1], pd[1], cdy, cdytail);
914  Two_Diff_Tail(pa[2], pd[2], adz, adztail);
915  Two_Diff_Tail(pb[2], pd[2], bdz, bdztail);
916  Two_Diff_Tail(pc[2], pd[2], cdz, cdztail);
917 
918  if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) && (adytail == 0.0) &&
919  (bdytail == 0.0) && (cdytail == 0.0) && (adztail == 0.0) && (bdztail == 0.0) &&
920  (cdztail == 0.0)) {
921  return det;
922  }
923 
924  errbound = o3derrboundC * permanent + resulterrbound * Absolute(det);
925  det += (adz * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) +
926  adztail * (bdx * cdy - bdy * cdx)) +
927  (bdz * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) +
928  bdztail * (cdx * ady - cdy * adx)) +
929  (cdz * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) +
930  cdztail * (adx * bdy - ady * bdx));
931  if ((det >= errbound) || (-det >= errbound)) {
932  return det;
933  }
934 
935  finnow = fin1;
936  finother = fin2;
937 
938  if (adxtail == 0.0) {
939  if (adytail == 0.0) {
940  at_b[0] = 0.0;
941  at_blen = 1;
942  at_c[0] = 0.0;
943  at_clen = 1;
944  }
945  else {
946  negate = -adytail;
947  Two_Product(negate, bdx, at_blarge, at_b[0]);
948  at_b[1] = at_blarge;
949  at_blen = 2;
950  Two_Product(adytail, cdx, at_clarge, at_c[0]);
951  at_c[1] = at_clarge;
952  at_clen = 2;
953  }
954  }
955  else {
956  if (adytail == 0.0) {
957  Two_Product(adxtail, bdy, at_blarge, at_b[0]);
958  at_b[1] = at_blarge;
959  at_blen = 2;
960  negate = -adxtail;
961  Two_Product(negate, cdy, at_clarge, at_c[0]);
962  at_c[1] = at_clarge;
963  at_clen = 2;
964  }
965  else {
966  Two_Product(adxtail, bdy, adxt_bdy1, adxt_bdy0);
967  Two_Product(adytail, bdx, adyt_bdx1, adyt_bdx0);
968  Two_Two_Diff(
969  adxt_bdy1, adxt_bdy0, adyt_bdx1, adyt_bdx0, at_blarge, at_b[2], at_b[1], at_b[0]);
970  at_b[3] = at_blarge;
971  at_blen = 4;
972  Two_Product(adytail, cdx, adyt_cdx1, adyt_cdx0);
973  Two_Product(adxtail, cdy, adxt_cdy1, adxt_cdy0);
974  Two_Two_Diff(
975  adyt_cdx1, adyt_cdx0, adxt_cdy1, adxt_cdy0, at_clarge, at_c[2], at_c[1], at_c[0]);
976  at_c[3] = at_clarge;
977  at_clen = 4;
978  }
979  }
980  if (bdxtail == 0.0) {
981  if (bdytail == 0.0) {
982  bt_c[0] = 0.0;
983  bt_clen = 1;
984  bt_a[0] = 0.0;
985  bt_alen = 1;
986  }
987  else {
988  negate = -bdytail;
989  Two_Product(negate, cdx, bt_clarge, bt_c[0]);
990  bt_c[1] = bt_clarge;
991  bt_clen = 2;
992  Two_Product(bdytail, adx, bt_alarge, bt_a[0]);
993  bt_a[1] = bt_alarge;
994  bt_alen = 2;
995  }
996  }
997  else {
998  if (bdytail == 0.0) {
999  Two_Product(bdxtail, cdy, bt_clarge, bt_c[0]);
1000  bt_c[1] = bt_clarge;
1001  bt_clen = 2;
1002  negate = -bdxtail;
1003  Two_Product(negate, ady, bt_alarge, bt_a[0]);
1004  bt_a[1] = bt_alarge;
1005  bt_alen = 2;
1006  }
1007  else {
1008  Two_Product(bdxtail, cdy, bdxt_cdy1, bdxt_cdy0);
1009  Two_Product(bdytail, cdx, bdyt_cdx1, bdyt_cdx0);
1010  Two_Two_Diff(
1011  bdxt_cdy1, bdxt_cdy0, bdyt_cdx1, bdyt_cdx0, bt_clarge, bt_c[2], bt_c[1], bt_c[0]);
1012  bt_c[3] = bt_clarge;
1013  bt_clen = 4;
1014  Two_Product(bdytail, adx, bdyt_adx1, bdyt_adx0);
1015  Two_Product(bdxtail, ady, bdxt_ady1, bdxt_ady0);
1016  Two_Two_Diff(
1017  bdyt_adx1, bdyt_adx0, bdxt_ady1, bdxt_ady0, bt_alarge, bt_a[2], bt_a[1], bt_a[0]);
1018  bt_a[3] = bt_alarge;
1019  bt_alen = 4;
1020  }
1021  }
1022  if (cdxtail == 0.0) {
1023  if (cdytail == 0.0) {
1024  ct_a[0] = 0.0;
1025  ct_alen = 1;
1026  ct_b[0] = 0.0;
1027  ct_blen = 1;
1028  }
1029  else {
1030  negate = -cdytail;
1031  Two_Product(negate, adx, ct_alarge, ct_a[0]);
1032  ct_a[1] = ct_alarge;
1033  ct_alen = 2;
1034  Two_Product(cdytail, bdx, ct_blarge, ct_b[0]);
1035  ct_b[1] = ct_blarge;
1036  ct_blen = 2;
1037  }
1038  }
1039  else {
1040  if (cdytail == 0.0) {
1041  Two_Product(cdxtail, ady, ct_alarge, ct_a[0]);
1042  ct_a[1] = ct_alarge;
1043  ct_alen = 2;
1044  negate = -cdxtail;
1045  Two_Product(negate, bdy, ct_blarge, ct_b[0]);
1046  ct_b[1] = ct_blarge;
1047  ct_blen = 2;
1048  }
1049  else {
1050  Two_Product(cdxtail, ady, cdxt_ady1, cdxt_ady0);
1051  Two_Product(cdytail, adx, cdyt_adx1, cdyt_adx0);
1052  Two_Two_Diff(
1053  cdxt_ady1, cdxt_ady0, cdyt_adx1, cdyt_adx0, ct_alarge, ct_a[2], ct_a[1], ct_a[0]);
1054  ct_a[3] = ct_alarge;
1055  ct_alen = 4;
1056  Two_Product(cdytail, bdx, cdyt_bdx1, cdyt_bdx0);
1057  Two_Product(cdxtail, bdy, cdxt_bdy1, cdxt_bdy0);
1058  Two_Two_Diff(
1059  cdyt_bdx1, cdyt_bdx0, cdxt_bdy1, cdxt_bdy0, ct_blarge, ct_b[2], ct_b[1], ct_b[0]);
1060  ct_b[3] = ct_blarge;
1061  ct_blen = 4;
1062  }
1063  }
1064 
1065  bctlen = fast_expansion_sum_zeroelim(bt_clen, bt_c, ct_blen, ct_b, bct);
1066  wlength = scale_expansion_zeroelim(bctlen, bct, adz, w);
1067  finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother);
1068  finswap = finnow;
1069  finnow = finother;
1070  finother = finswap;
1071 
1072  catlen = fast_expansion_sum_zeroelim(ct_alen, ct_a, at_clen, at_c, cat);
1073  wlength = scale_expansion_zeroelim(catlen, cat, bdz, w);
1074  finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother);
1075  finswap = finnow;
1076  finnow = finother;
1077  finother = finswap;
1078 
1079  abtlen = fast_expansion_sum_zeroelim(at_blen, at_b, bt_alen, bt_a, abt);
1080  wlength = scale_expansion_zeroelim(abtlen, abt, cdz, w);
1081  finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother);
1082  finswap = finnow;
1083  finnow = finother;
1084  finother = finswap;
1085 
1086  if (adztail != 0.0) {
1087  vlength = scale_expansion_zeroelim(4, bc, adztail, v);
1088  finlength = fast_expansion_sum_zeroelim(finlength, finnow, vlength, v, finother);
1089  finswap = finnow;
1090  finnow = finother;
1091  finother = finswap;
1092  }
1093  if (bdztail != 0.0) {
1094  vlength = scale_expansion_zeroelim(4, ca, bdztail, v);
1095  finlength = fast_expansion_sum_zeroelim(finlength, finnow, vlength, v, finother);
1096  finswap = finnow;
1097  finnow = finother;
1098  finother = finswap;
1099  }
1100  if (cdztail != 0.0) {
1101  vlength = scale_expansion_zeroelim(4, ab, cdztail, v);
1102  finlength = fast_expansion_sum_zeroelim(finlength, finnow, vlength, v, finother);
1103  finswap = finnow;
1104  finnow = finother;
1105  finother = finswap;
1106  }
1107 
1108  if (adxtail != 0.0) {
1109  if (bdytail != 0.0) {
1110  Two_Product(adxtail, bdytail, adxt_bdyt1, adxt_bdyt0);
1111  Two_One_Product(adxt_bdyt1, adxt_bdyt0, cdz, u3, u[2], u[1], u[0]);
1112  u[3] = u3;
1113  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1114  finswap = finnow;
1115  finnow = finother;
1116  finother = finswap;
1117  if (cdztail != 0.0) {
1118  Two_One_Product(adxt_bdyt1, adxt_bdyt0, cdztail, u3, u[2], u[1], u[0]);
1119  u[3] = u3;
1120  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1121  finswap = finnow;
1122  finnow = finother;
1123  finother = finswap;
1124  }
1125  }
1126  if (cdytail != 0.0) {
1127  negate = -adxtail;
1128  Two_Product(negate, cdytail, adxt_cdyt1, adxt_cdyt0);
1129  Two_One_Product(adxt_cdyt1, adxt_cdyt0, bdz, u3, u[2], u[1], u[0]);
1130  u[3] = u3;
1131  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1132  finswap = finnow;
1133  finnow = finother;
1134  finother = finswap;
1135  if (bdztail != 0.0) {
1136  Two_One_Product(adxt_cdyt1, adxt_cdyt0, bdztail, u3, u[2], u[1], u[0]);
1137  u[3] = u3;
1138  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1139  finswap = finnow;
1140  finnow = finother;
1141  finother = finswap;
1142  }
1143  }
1144  }
1145  if (bdxtail != 0.0) {
1146  if (cdytail != 0.0) {
1147  Two_Product(bdxtail, cdytail, bdxt_cdyt1, bdxt_cdyt0);
1148  Two_One_Product(bdxt_cdyt1, bdxt_cdyt0, adz, u3, u[2], u[1], u[0]);
1149  u[3] = u3;
1150  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1151  finswap = finnow;
1152  finnow = finother;
1153  finother = finswap;
1154  if (adztail != 0.0) {
1155  Two_One_Product(bdxt_cdyt1, bdxt_cdyt0, adztail, u3, u[2], u[1], u[0]);
1156  u[3] = u3;
1157  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1158  finswap = finnow;
1159  finnow = finother;
1160  finother = finswap;
1161  }
1162  }
1163  if (adytail != 0.0) {
1164  negate = -bdxtail;
1165  Two_Product(negate, adytail, bdxt_adyt1, bdxt_adyt0);
1166  Two_One_Product(bdxt_adyt1, bdxt_adyt0, cdz, u3, u[2], u[1], u[0]);
1167  u[3] = u3;
1168  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1169  finswap = finnow;
1170  finnow = finother;
1171  finother = finswap;
1172  if (cdztail != 0.0) {
1173  Two_One_Product(bdxt_adyt1, bdxt_adyt0, cdztail, u3, u[2], u[1], u[0]);
1174  u[3] = u3;
1175  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1176  finswap = finnow;
1177  finnow = finother;
1178  finother = finswap;
1179  }
1180  }
1181  }
1182  if (cdxtail != 0.0) {
1183  if (adytail != 0.0) {
1184  Two_Product(cdxtail, adytail, cdxt_adyt1, cdxt_adyt0);
1185  Two_One_Product(cdxt_adyt1, cdxt_adyt0, bdz, u3, u[2], u[1], u[0]);
1186  u[3] = u3;
1187  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1188  finswap = finnow;
1189  finnow = finother;
1190  finother = finswap;
1191  if (bdztail != 0.0) {
1192  Two_One_Product(cdxt_adyt1, cdxt_adyt0, bdztail, u3, u[2], u[1], u[0]);
1193  u[3] = u3;
1194  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1195  finswap = finnow;
1196  finnow = finother;
1197  finother = finswap;
1198  }
1199  }
1200  if (bdytail != 0.0) {
1201  negate = -cdxtail;
1202  Two_Product(negate, bdytail, cdxt_bdyt1, cdxt_bdyt0);
1203  Two_One_Product(cdxt_bdyt1, cdxt_bdyt0, adz, u3, u[2], u[1], u[0]);
1204  u[3] = u3;
1205  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1206  finswap = finnow;
1207  finnow = finother;
1208  finother = finswap;
1209  if (adztail != 0.0) {
1210  Two_One_Product(cdxt_bdyt1, cdxt_bdyt0, adztail, u3, u[2], u[1], u[0]);
1211  u[3] = u3;
1212  finlength = fast_expansion_sum_zeroelim(finlength, finnow, 4, u, finother);
1213  finswap = finnow;
1214  finnow = finother;
1215  finother = finswap;
1216  }
1217  }
1218  }
1219 
1220  if (adztail != 0.0) {
1221  wlength = scale_expansion_zeroelim(bctlen, bct, adztail, w);
1222  finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother);
1223  finswap = finnow;
1224  finnow = finother;
1225  finother = finswap;
1226  }
1227  if (bdztail != 0.0) {
1228  wlength = scale_expansion_zeroelim(catlen, cat, bdztail, w);
1229  finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother);
1230  finswap = finnow;
1231  finnow = finother;
1232  finother = finswap;
1233  }
1234  if (cdztail != 0.0) {
1235  wlength = scale_expansion_zeroelim(abtlen, abt, cdztail, w);
1236  finlength = fast_expansion_sum_zeroelim(finlength, finnow, wlength, w, finother);
1237  finswap = finnow;
1238  finnow = finother;
1239  finother = finswap;
1240  }
1241 
1242  return finnow[finlength - 1];
1243 }
1244 
1245 double orient3d(const double *pa, const double *pb, const double *pc, const double *pd)
1246 {
1247  double adx, bdx, cdx, ady, bdy, cdy, adz, bdz, cdz;
1248  double bdxcdy, cdxbdy, cdxady, adxcdy, adxbdy, bdxady;
1249  double det;
1250  double permanent, errbound;
1251 
1252  adx = pa[0] - pd[0];
1253  bdx = pb[0] - pd[0];
1254  cdx = pc[0] - pd[0];
1255  ady = pa[1] - pd[1];
1256  bdy = pb[1] - pd[1];
1257  cdy = pc[1] - pd[1];
1258  adz = pa[2] - pd[2];
1259  bdz = pb[2] - pd[2];
1260  cdz = pc[2] - pd[2];
1261 
1262  bdxcdy = bdx * cdy;
1263  cdxbdy = cdx * bdy;
1264 
1265  cdxady = cdx * ady;
1266  adxcdy = adx * cdy;
1267 
1268  adxbdy = adx * bdy;
1269  bdxady = bdx * ady;
1270 
1271  det = adz * (bdxcdy - cdxbdy) + bdz * (cdxady - adxcdy) + cdz * (adxbdy - bdxady);
1272 
1273  permanent = (Absolute(bdxcdy) + Absolute(cdxbdy)) * Absolute(adz) +
1274  (Absolute(cdxady) + Absolute(adxcdy)) * Absolute(bdz) +
1275  (Absolute(adxbdy) + Absolute(bdxady)) * Absolute(cdz);
1276  errbound = o3derrboundA * permanent;
1277  if ((det > errbound) || (-det > errbound)) {
1278  return det;
1279  }
1280 
1281  return orient3dadapt(pa, pb, pc, pd, permanent);
1282 }
1283 
1303 double incirclefast(const double *pa, const double *pb, const double *pc, const double *pd)
1304 {
1305  double adx, ady, bdx, bdy, cdx, cdy;
1306  double abdet, bcdet, cadet;
1307  double alift, blift, clift;
1308 
1309  adx = pa[0] - pd[0];
1310  ady = pa[1] - pd[1];
1311  bdx = pb[0] - pd[0];
1312  bdy = pb[1] - pd[1];
1313  cdx = pc[0] - pd[0];
1314  cdy = pc[1] - pd[1];
1315 
1316  abdet = adx * bdy - bdx * ady;
1317  bcdet = bdx * cdy - cdx * bdy;
1318  cadet = cdx * ady - adx * cdy;
1319  alift = adx * adx + ady * ady;
1320  blift = bdx * bdx + bdy * bdy;
1321  clift = cdx * cdx + cdy * cdy;
1322 
1323  return alift * bcdet + blift * cadet + clift * abdet;
1324 }
1325 
1330 /* NOLINTNEXTLINE: readability-function-size */
1331 static double incircleadapt(
1332  const double *pa, const double *pb, const double *pc, const double *pd, double permanent)
1333 {
1334  INEXACT double adx, bdx, cdx, ady, bdy, cdy;
1335  double det, errbound;
1336 
1337  INEXACT double bdxcdy1, cdxbdy1, cdxady1, adxcdy1, adxbdy1, bdxady1;
1338  double bdxcdy0, cdxbdy0, cdxady0, adxcdy0, adxbdy0, bdxady0;
1339  double bc[4], ca[4], ab[4];
1340  INEXACT double bc3, ca3, ab3;
1341  double axbc[8], axxbc[16], aybc[8], ayybc[16], adet[32];
1342  int axbclen, axxbclen, aybclen, ayybclen, alen;
1343  double bxca[8], bxxca[16], byca[8], byyca[16], bdet[32];
1344  int bxcalen, bxxcalen, bycalen, byycalen, blen;
1345  double cxab[8], cxxab[16], cyab[8], cyyab[16], cdet[32];
1346  int cxablen, cxxablen, cyablen, cyyablen, clen;
1347  double abdet[64];
1348  int ablen;
1349  double fin1[1152], fin2[1152];
1350  double *finnow, *finother, *finswap;
1351  int finlength;
1352 
1353  double adxtail, bdxtail, cdxtail, adytail, bdytail, cdytail;
1354  INEXACT double adxadx1, adyady1, bdxbdx1, bdybdy1, cdxcdx1, cdycdy1;
1355  double adxadx0, adyady0, bdxbdx0, bdybdy0, cdxcdx0, cdycdy0;
1356  double aa[4], bb[4], cc[4];
1357  INEXACT double aa3, bb3, cc3;
1358  INEXACT double ti1, tj1;
1359  double ti0, tj0;
1360  double u[4], v[4];
1361  INEXACT double u3, v3;
1362  double temp8[8], temp16a[16], temp16b[16], temp16c[16];
1363  double temp32a[32], temp32b[32], temp48[48], temp64[64];
1364  int temp8len, temp16alen, temp16blen, temp16clen;
1365  int temp32alen, temp32blen, temp48len, temp64len;
1366  double axtbb[8], axtcc[8], aytbb[8], aytcc[8];
1367  int axtbblen, axtcclen, aytbblen, aytcclen;
1368  double bxtaa[8], bxtcc[8], bytaa[8], bytcc[8];
1369  int bxtaalen, bxtcclen, bytaalen, bytcclen;
1370  double cxtaa[8], cxtbb[8], cytaa[8], cytbb[8];
1371  int cxtaalen, cxtbblen, cytaalen, cytbblen;
1372  double axtbc[8], aytbc[8], bxtca[8], bytca[8], cxtab[8], cytab[8];
1373  int axtbclen, aytbclen, bxtcalen, bytcalen, cxtablen, cytablen;
1374  double axtbct[16], aytbct[16], bxtcat[16], bytcat[16], cxtabt[16], cytabt[16];
1375  int axtbctlen, aytbctlen, bxtcatlen, bytcatlen, cxtabtlen, cytabtlen;
1376  double axtbctt[8], aytbctt[8], bxtcatt[8];
1377  double bytcatt[8], cxtabtt[8], cytabtt[8];
1378  int axtbcttlen, aytbcttlen, bxtcattlen, bytcattlen, cxtabttlen, cytabttlen;
1379  double abt[8], bct[8], cat[8];
1380  int abtlen, bctlen, catlen;
1381  double abtt[4], bctt[4], catt[4];
1382  int abttlen, bcttlen, cattlen;
1383  INEXACT double abtt3, bctt3, catt3;
1384  double negate;
1385 
1386  INEXACT double bvirt;
1387  double avirt, bround, around;
1388  INEXACT double c;
1389  INEXACT double abig;
1390  double ahi, alo, bhi, blo;
1391  double err1, err2, err3;
1392  INEXACT double _i, _j;
1393  double _0;
1394 
1395  adx = (double)(pa[0] - pd[0]);
1396  bdx = (double)(pb[0] - pd[0]);
1397  cdx = (double)(pc[0] - pd[0]);
1398  ady = (double)(pa[1] - pd[1]);
1399  bdy = (double)(pb[1] - pd[1]);
1400  cdy = (double)(pc[1] - pd[1]);
1401 
1402  Two_Product(bdx, cdy, bdxcdy1, bdxcdy0);
1403  Two_Product(cdx, bdy, cdxbdy1, cdxbdy0);
1404  Two_Two_Diff(bdxcdy1, bdxcdy0, cdxbdy1, cdxbdy0, bc3, bc[2], bc[1], bc[0]);
1405  bc[3] = bc3;
1406  axbclen = scale_expansion_zeroelim(4, bc, adx, axbc);
1407  axxbclen = scale_expansion_zeroelim(axbclen, axbc, adx, axxbc);
1408  aybclen = scale_expansion_zeroelim(4, bc, ady, aybc);
1409  ayybclen = scale_expansion_zeroelim(aybclen, aybc, ady, ayybc);
1410  alen = fast_expansion_sum_zeroelim(axxbclen, axxbc, ayybclen, ayybc, adet);
1411 
1412  Two_Product(cdx, ady, cdxady1, cdxady0);
1413  Two_Product(adx, cdy, adxcdy1, adxcdy0);
1414  Two_Two_Diff(cdxady1, cdxady0, adxcdy1, adxcdy0, ca3, ca[2], ca[1], ca[0]);
1415  ca[3] = ca3;
1416  bxcalen = scale_expansion_zeroelim(4, ca, bdx, bxca);
1417  bxxcalen = scale_expansion_zeroelim(bxcalen, bxca, bdx, bxxca);
1418  bycalen = scale_expansion_zeroelim(4, ca, bdy, byca);
1419  byycalen = scale_expansion_zeroelim(bycalen, byca, bdy, byyca);
1420  blen = fast_expansion_sum_zeroelim(bxxcalen, bxxca, byycalen, byyca, bdet);
1421 
1422  Two_Product(adx, bdy, adxbdy1, adxbdy0);
1423  Two_Product(bdx, ady, bdxady1, bdxady0);
1424  Two_Two_Diff(adxbdy1, adxbdy0, bdxady1, bdxady0, ab3, ab[2], ab[1], ab[0]);
1425  ab[3] = ab3;
1426  cxablen = scale_expansion_zeroelim(4, ab, cdx, cxab);
1427  cxxablen = scale_expansion_zeroelim(cxablen, cxab, cdx, cxxab);
1428  cyablen = scale_expansion_zeroelim(4, ab, cdy, cyab);
1429  cyyablen = scale_expansion_zeroelim(cyablen, cyab, cdy, cyyab);
1430  clen = fast_expansion_sum_zeroelim(cxxablen, cxxab, cyyablen, cyyab, cdet);
1431 
1432  ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
1433  finlength = fast_expansion_sum_zeroelim(ablen, abdet, clen, cdet, fin1);
1434 
1435  det = estimate(finlength, fin1);
1436  errbound = iccerrboundB * permanent;
1437  if ((det >= errbound) || (-det >= errbound)) {
1438  return det;
1439  }
1440 
1441  Two_Diff_Tail(pa[0], pd[0], adx, adxtail);
1442  Two_Diff_Tail(pa[1], pd[1], ady, adytail);
1443  Two_Diff_Tail(pb[0], pd[0], bdx, bdxtail);
1444  Two_Diff_Tail(pb[1], pd[1], bdy, bdytail);
1445  Two_Diff_Tail(pc[0], pd[0], cdx, cdxtail);
1446  Two_Diff_Tail(pc[1], pd[1], cdy, cdytail);
1447  if ((adxtail == 0.0) && (bdxtail == 0.0) && (cdxtail == 0.0) && (adytail == 0.0) &&
1448  (bdytail == 0.0) && (cdytail == 0.0)) {
1449  return det;
1450  }
1451 
1452  errbound = iccerrboundC * permanent + resulterrbound * Absolute(det);
1453  det += ((adx * adx + ady * ady) *
1454  ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) +
1455  2.0 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx)) +
1456  ((bdx * bdx + bdy * bdy) *
1457  ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) +
1458  2.0 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx)) +
1459  ((cdx * cdx + cdy * cdy) *
1460  ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) +
1461  2.0 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx));
1462  if ((det >= errbound) || (-det >= errbound)) {
1463  return det;
1464  }
1465 
1466  finnow = fin1;
1467  finother = fin2;
1468 
1469  if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0)) {
1470  Square(adx, adxadx1, adxadx0);
1471  Square(ady, adyady1, adyady0);
1472  Two_Two_Sum(adxadx1, adxadx0, adyady1, adyady0, aa3, aa[2], aa[1], aa[0]);
1473  aa[3] = aa3;
1474  }
1475  if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0)) {
1476  Square(bdx, bdxbdx1, bdxbdx0);
1477  Square(bdy, bdybdy1, bdybdy0);
1478  Two_Two_Sum(bdxbdx1, bdxbdx0, bdybdy1, bdybdy0, bb3, bb[2], bb[1], bb[0]);
1479  bb[3] = bb3;
1480  }
1481  if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0)) {
1482  Square(cdx, cdxcdx1, cdxcdx0);
1483  Square(cdy, cdycdy1, cdycdy0);
1484  Two_Two_Sum(cdxcdx1, cdxcdx0, cdycdy1, cdycdy0, cc3, cc[2], cc[1], cc[0]);
1485  cc[3] = cc3;
1486  }
1487 
1488  if (adxtail != 0.0) {
1489  axtbclen = scale_expansion_zeroelim(4, bc, adxtail, axtbc);
1490  temp16alen = scale_expansion_zeroelim(axtbclen, axtbc, 2.0 * adx, temp16a);
1491 
1492  axtcclen = scale_expansion_zeroelim(4, cc, adxtail, axtcc);
1493  temp16blen = scale_expansion_zeroelim(axtcclen, axtcc, bdy, temp16b);
1494 
1495  axtbblen = scale_expansion_zeroelim(4, bb, adxtail, axtbb);
1496  temp16clen = scale_expansion_zeroelim(axtbblen, axtbb, -cdy, temp16c);
1497 
1498  temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1499  temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1500  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1501  finswap = finnow;
1502  finnow = finother;
1503  finother = finswap;
1504  }
1505  if (adytail != 0.0) {
1506  aytbclen = scale_expansion_zeroelim(4, bc, adytail, aytbc);
1507  temp16alen = scale_expansion_zeroelim(aytbclen, aytbc, 2.0 * ady, temp16a);
1508 
1509  aytbblen = scale_expansion_zeroelim(4, bb, adytail, aytbb);
1510  temp16blen = scale_expansion_zeroelim(aytbblen, aytbb, cdx, temp16b);
1511 
1512  aytcclen = scale_expansion_zeroelim(4, cc, adytail, aytcc);
1513  temp16clen = scale_expansion_zeroelim(aytcclen, aytcc, -bdx, temp16c);
1514 
1515  temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1516  temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1517  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1518  finswap = finnow;
1519  finnow = finother;
1520  finother = finswap;
1521  }
1522  if (bdxtail != 0.0) {
1523  bxtcalen = scale_expansion_zeroelim(4, ca, bdxtail, bxtca);
1524  temp16alen = scale_expansion_zeroelim(bxtcalen, bxtca, 2.0 * bdx, temp16a);
1525 
1526  bxtaalen = scale_expansion_zeroelim(4, aa, bdxtail, bxtaa);
1527  temp16blen = scale_expansion_zeroelim(bxtaalen, bxtaa, cdy, temp16b);
1528 
1529  bxtcclen = scale_expansion_zeroelim(4, cc, bdxtail, bxtcc);
1530  temp16clen = scale_expansion_zeroelim(bxtcclen, bxtcc, -ady, temp16c);
1531 
1532  temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1533  temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1534  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1535  finswap = finnow;
1536  finnow = finother;
1537  finother = finswap;
1538  }
1539  if (bdytail != 0.0) {
1540  bytcalen = scale_expansion_zeroelim(4, ca, bdytail, bytca);
1541  temp16alen = scale_expansion_zeroelim(bytcalen, bytca, 2.0 * bdy, temp16a);
1542 
1543  bytcclen = scale_expansion_zeroelim(4, cc, bdytail, bytcc);
1544  temp16blen = scale_expansion_zeroelim(bytcclen, bytcc, adx, temp16b);
1545 
1546  bytaalen = scale_expansion_zeroelim(4, aa, bdytail, bytaa);
1547  temp16clen = scale_expansion_zeroelim(bytaalen, bytaa, -cdx, temp16c);
1548 
1549  temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1550  temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1551  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1552  finswap = finnow;
1553  finnow = finother;
1554  finother = finswap;
1555  }
1556  if (cdxtail != 0.0) {
1557  cxtablen = scale_expansion_zeroelim(4, ab, cdxtail, cxtab);
1558  temp16alen = scale_expansion_zeroelim(cxtablen, cxtab, 2.0 * cdx, temp16a);
1559 
1560  cxtbblen = scale_expansion_zeroelim(4, bb, cdxtail, cxtbb);
1561  temp16blen = scale_expansion_zeroelim(cxtbblen, cxtbb, ady, temp16b);
1562 
1563  cxtaalen = scale_expansion_zeroelim(4, aa, cdxtail, cxtaa);
1564  temp16clen = scale_expansion_zeroelim(cxtaalen, cxtaa, -bdy, temp16c);
1565 
1566  temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1567  temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1568  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1569  finswap = finnow;
1570  finnow = finother;
1571  finother = finswap;
1572  }
1573  if (cdytail != 0.0) {
1574  cytablen = scale_expansion_zeroelim(4, ab, cdytail, cytab);
1575  temp16alen = scale_expansion_zeroelim(cytablen, cytab, 2.0 * cdy, temp16a);
1576 
1577  cytaalen = scale_expansion_zeroelim(4, aa, cdytail, cytaa);
1578  temp16blen = scale_expansion_zeroelim(cytaalen, cytaa, bdx, temp16b);
1579 
1580  cytbblen = scale_expansion_zeroelim(4, bb, cdytail, cytbb);
1581  temp16clen = scale_expansion_zeroelim(cytbblen, cytbb, -adx, temp16c);
1582 
1583  temp32alen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32a);
1584  temp48len = fast_expansion_sum_zeroelim(temp16clen, temp16c, temp32alen, temp32a, temp48);
1585  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1586  finswap = finnow;
1587  finnow = finother;
1588  finother = finswap;
1589  }
1590 
1591  if ((adxtail != 0.0) || (adytail != 0.0)) {
1592  if ((bdxtail != 0.0) || (bdytail != 0.0) || (cdxtail != 0.0) || (cdytail != 0.0)) {
1593  Two_Product(bdxtail, cdy, ti1, ti0);
1594  Two_Product(bdx, cdytail, tj1, tj0);
1595  Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
1596  u[3] = u3;
1597  negate = -bdy;
1598  Two_Product(cdxtail, negate, ti1, ti0);
1599  negate = -bdytail;
1600  Two_Product(cdx, negate, tj1, tj0);
1601  Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
1602  v[3] = v3;
1603  bctlen = fast_expansion_sum_zeroelim(4, u, 4, v, bct);
1604 
1605  Two_Product(bdxtail, cdytail, ti1, ti0);
1606  Two_Product(cdxtail, bdytail, tj1, tj0);
1607  Two_Two_Diff(ti1, ti0, tj1, tj0, bctt3, bctt[2], bctt[1], bctt[0]);
1608  bctt[3] = bctt3;
1609  bcttlen = 4;
1610  }
1611  else {
1612  bct[0] = 0.0;
1613  bctlen = 1;
1614  bctt[0] = 0.0;
1615  bcttlen = 1;
1616  }
1617 
1618  if (adxtail != 0.0) {
1619  temp16alen = scale_expansion_zeroelim(axtbclen, axtbc, adxtail, temp16a);
1620  axtbctlen = scale_expansion_zeroelim(bctlen, bct, adxtail, axtbct);
1621  temp32alen = scale_expansion_zeroelim(axtbctlen, axtbct, 2.0 * adx, temp32a);
1622  temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1623  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1624  finswap = finnow;
1625  finnow = finother;
1626  finother = finswap;
1627  if (bdytail != 0.0) {
1628  temp8len = scale_expansion_zeroelim(4, cc, adxtail, temp8);
1629  temp16alen = scale_expansion_zeroelim(temp8len, temp8, bdytail, temp16a);
1630  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother);
1631  finswap = finnow;
1632  finnow = finother;
1633  finother = finswap;
1634  }
1635  if (cdytail != 0.0) {
1636  temp8len = scale_expansion_zeroelim(4, bb, -adxtail, temp8);
1637  temp16alen = scale_expansion_zeroelim(temp8len, temp8, cdytail, temp16a);
1638  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother);
1639  finswap = finnow;
1640  finnow = finother;
1641  finother = finswap;
1642  }
1643 
1644  temp32alen = scale_expansion_zeroelim(axtbctlen, axtbct, adxtail, temp32a);
1645  axtbcttlen = scale_expansion_zeroelim(bcttlen, bctt, adxtail, axtbctt);
1646  temp16alen = scale_expansion_zeroelim(axtbcttlen, axtbctt, 2.0 * adx, temp16a);
1647  temp16blen = scale_expansion_zeroelim(axtbcttlen, axtbctt, adxtail, temp16b);
1648  temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1649  temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1650  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother);
1651  finswap = finnow;
1652  finnow = finother;
1653  finother = finswap;
1654  }
1655  if (adytail != 0.0) {
1656  temp16alen = scale_expansion_zeroelim(aytbclen, aytbc, adytail, temp16a);
1657  aytbctlen = scale_expansion_zeroelim(bctlen, bct, adytail, aytbct);
1658  temp32alen = scale_expansion_zeroelim(aytbctlen, aytbct, 2.0 * ady, temp32a);
1659  temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1660  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1661  finswap = finnow;
1662  finnow = finother;
1663  finother = finswap;
1664 
1665  temp32alen = scale_expansion_zeroelim(aytbctlen, aytbct, adytail, temp32a);
1666  aytbcttlen = scale_expansion_zeroelim(bcttlen, bctt, adytail, aytbctt);
1667  temp16alen = scale_expansion_zeroelim(aytbcttlen, aytbctt, 2.0 * ady, temp16a);
1668  temp16blen = scale_expansion_zeroelim(aytbcttlen, aytbctt, adytail, temp16b);
1669  temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1670  temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1671  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother);
1672  finswap = finnow;
1673  finnow = finother;
1674  finother = finswap;
1675  }
1676  }
1677  if ((bdxtail != 0.0) || (bdytail != 0.0)) {
1678  if ((cdxtail != 0.0) || (cdytail != 0.0) || (adxtail != 0.0) || (adytail != 0.0)) {
1679  Two_Product(cdxtail, ady, ti1, ti0);
1680  Two_Product(cdx, adytail, tj1, tj0);
1681  Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
1682  u[3] = u3;
1683  negate = -cdy;
1684  Two_Product(adxtail, negate, ti1, ti0);
1685  negate = -cdytail;
1686  Two_Product(adx, negate, tj1, tj0);
1687  Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
1688  v[3] = v3;
1689  catlen = fast_expansion_sum_zeroelim(4, u, 4, v, cat);
1690 
1691  Two_Product(cdxtail, adytail, ti1, ti0);
1692  Two_Product(adxtail, cdytail, tj1, tj0);
1693  Two_Two_Diff(ti1, ti0, tj1, tj0, catt3, catt[2], catt[1], catt[0]);
1694  catt[3] = catt3;
1695  cattlen = 4;
1696  }
1697  else {
1698  cat[0] = 0.0;
1699  catlen = 1;
1700  catt[0] = 0.0;
1701  cattlen = 1;
1702  }
1703 
1704  if (bdxtail != 0.0) {
1705  temp16alen = scale_expansion_zeroelim(bxtcalen, bxtca, bdxtail, temp16a);
1706  bxtcatlen = scale_expansion_zeroelim(catlen, cat, bdxtail, bxtcat);
1707  temp32alen = scale_expansion_zeroelim(bxtcatlen, bxtcat, 2.0 * bdx, temp32a);
1708  temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1709  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1710  finswap = finnow;
1711  finnow = finother;
1712  finother = finswap;
1713  if (cdytail != 0.0) {
1714  temp8len = scale_expansion_zeroelim(4, aa, bdxtail, temp8);
1715  temp16alen = scale_expansion_zeroelim(temp8len, temp8, cdytail, temp16a);
1716  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother);
1717  finswap = finnow;
1718  finnow = finother;
1719  finother = finswap;
1720  }
1721  if (adytail != 0.0) {
1722  temp8len = scale_expansion_zeroelim(4, cc, -bdxtail, temp8);
1723  temp16alen = scale_expansion_zeroelim(temp8len, temp8, adytail, temp16a);
1724  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother);
1725  finswap = finnow;
1726  finnow = finother;
1727  finother = finswap;
1728  }
1729 
1730  temp32alen = scale_expansion_zeroelim(bxtcatlen, bxtcat, bdxtail, temp32a);
1731  bxtcattlen = scale_expansion_zeroelim(cattlen, catt, bdxtail, bxtcatt);
1732  temp16alen = scale_expansion_zeroelim(bxtcattlen, bxtcatt, 2.0 * bdx, temp16a);
1733  temp16blen = scale_expansion_zeroelim(bxtcattlen, bxtcatt, bdxtail, temp16b);
1734  temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1735  temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1736  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother);
1737  finswap = finnow;
1738  finnow = finother;
1739  finother = finswap;
1740  }
1741  if (bdytail != 0.0) {
1742  temp16alen = scale_expansion_zeroelim(bytcalen, bytca, bdytail, temp16a);
1743  bytcatlen = scale_expansion_zeroelim(catlen, cat, bdytail, bytcat);
1744  temp32alen = scale_expansion_zeroelim(bytcatlen, bytcat, 2.0 * bdy, temp32a);
1745  temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1746  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1747  finswap = finnow;
1748  finnow = finother;
1749  finother = finswap;
1750 
1751  temp32alen = scale_expansion_zeroelim(bytcatlen, bytcat, bdytail, temp32a);
1752  bytcattlen = scale_expansion_zeroelim(cattlen, catt, bdytail, bytcatt);
1753  temp16alen = scale_expansion_zeroelim(bytcattlen, bytcatt, 2.0 * bdy, temp16a);
1754  temp16blen = scale_expansion_zeroelim(bytcattlen, bytcatt, bdytail, temp16b);
1755  temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1756  temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1757  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother);
1758  finswap = finnow;
1759  finnow = finother;
1760  finother = finswap;
1761  }
1762  }
1763  if ((cdxtail != 0.0) || (cdytail != 0.0)) {
1764  if ((adxtail != 0.0) || (adytail != 0.0) || (bdxtail != 0.0) || (bdytail != 0.0)) {
1765  Two_Product(adxtail, bdy, ti1, ti0);
1766  Two_Product(adx, bdytail, tj1, tj0);
1767  Two_Two_Sum(ti1, ti0, tj1, tj0, u3, u[2], u[1], u[0]);
1768  u[3] = u3;
1769  negate = -ady;
1770  Two_Product(bdxtail, negate, ti1, ti0);
1771  negate = -adytail;
1772  Two_Product(bdx, negate, tj1, tj0);
1773  Two_Two_Sum(ti1, ti0, tj1, tj0, v3, v[2], v[1], v[0]);
1774  v[3] = v3;
1775  abtlen = fast_expansion_sum_zeroelim(4, u, 4, v, abt);
1776 
1777  Two_Product(adxtail, bdytail, ti1, ti0);
1778  Two_Product(bdxtail, adytail, tj1, tj0);
1779  Two_Two_Diff(ti1, ti0, tj1, tj0, abtt3, abtt[2], abtt[1], abtt[0]);
1780  abtt[3] = abtt3;
1781  abttlen = 4;
1782  }
1783  else {
1784  abt[0] = 0.0;
1785  abtlen = 1;
1786  abtt[0] = 0.0;
1787  abttlen = 1;
1788  }
1789 
1790  if (cdxtail != 0.0) {
1791  temp16alen = scale_expansion_zeroelim(cxtablen, cxtab, cdxtail, temp16a);
1792  cxtabtlen = scale_expansion_zeroelim(abtlen, abt, cdxtail, cxtabt);
1793  temp32alen = scale_expansion_zeroelim(cxtabtlen, cxtabt, 2.0 * cdx, temp32a);
1794  temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1795  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1796  finswap = finnow;
1797  finnow = finother;
1798  finother = finswap;
1799  if (adytail != 0.0) {
1800  temp8len = scale_expansion_zeroelim(4, bb, cdxtail, temp8);
1801  temp16alen = scale_expansion_zeroelim(temp8len, temp8, adytail, temp16a);
1802  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother);
1803  finswap = finnow;
1804  finnow = finother;
1805  finother = finswap;
1806  }
1807  if (bdytail != 0.0) {
1808  temp8len = scale_expansion_zeroelim(4, aa, -cdxtail, temp8);
1809  temp16alen = scale_expansion_zeroelim(temp8len, temp8, bdytail, temp16a);
1810  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp16alen, temp16a, finother);
1811  finswap = finnow;
1812  finnow = finother;
1813  finother = finswap;
1814  }
1815 
1816  temp32alen = scale_expansion_zeroelim(cxtabtlen, cxtabt, cdxtail, temp32a);
1817  cxtabttlen = scale_expansion_zeroelim(abttlen, abtt, cdxtail, cxtabtt);
1818  temp16alen = scale_expansion_zeroelim(cxtabttlen, cxtabtt, 2.0 * cdx, temp16a);
1819  temp16blen = scale_expansion_zeroelim(cxtabttlen, cxtabtt, cdxtail, temp16b);
1820  temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1821  temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1822  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother);
1823  finswap = finnow;
1824  finnow = finother;
1825  finother = finswap;
1826  }
1827  if (cdytail != 0.0) {
1828  temp16alen = scale_expansion_zeroelim(cytablen, cytab, cdytail, temp16a);
1829  cytabtlen = scale_expansion_zeroelim(abtlen, abt, cdytail, cytabt);
1830  temp32alen = scale_expansion_zeroelim(cytabtlen, cytabt, 2.0 * cdy, temp32a);
1831  temp48len = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp32alen, temp32a, temp48);
1832  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp48len, temp48, finother);
1833  finswap = finnow;
1834  finnow = finother;
1835  finother = finswap;
1836 
1837  temp32alen = scale_expansion_zeroelim(cytabtlen, cytabt, cdytail, temp32a);
1838  cytabttlen = scale_expansion_zeroelim(abttlen, abtt, cdytail, cytabtt);
1839  temp16alen = scale_expansion_zeroelim(cytabttlen, cytabtt, 2.0 * cdy, temp16a);
1840  temp16blen = scale_expansion_zeroelim(cytabttlen, cytabtt, cdytail, temp16b);
1841  temp32blen = fast_expansion_sum_zeroelim(temp16alen, temp16a, temp16blen, temp16b, temp32b);
1842  temp64len = fast_expansion_sum_zeroelim(temp32alen, temp32a, temp32blen, temp32b, temp64);
1843  finlength = fast_expansion_sum_zeroelim(finlength, finnow, temp64len, temp64, finother);
1844  finswap = finnow;
1845  finnow = finother;
1846  finother = finswap;
1847  }
1848  }
1849 
1850  return finnow[finlength - 1];
1851 }
1852 
1853 double incircle(const double *pa, const double *pb, const double *pc, const double *pd)
1854 {
1855  double adx, bdx, cdx, ady, bdy, cdy;
1856  double bdxcdy, cdxbdy, cdxady, adxcdy, adxbdy, bdxady;
1857  double alift, blift, clift;
1858  double det;
1859  double permanent, errbound;
1860 
1861  adx = pa[0] - pd[0];
1862  bdx = pb[0] - pd[0];
1863  cdx = pc[0] - pd[0];
1864  ady = pa[1] - pd[1];
1865  bdy = pb[1] - pd[1];
1866  cdy = pc[1] - pd[1];
1867 
1868  bdxcdy = bdx * cdy;
1869  cdxbdy = cdx * bdy;
1870  alift = adx * adx + ady * ady;
1871 
1872  cdxady = cdx * ady;
1873  adxcdy = adx * cdy;
1874  blift = bdx * bdx + bdy * bdy;
1875 
1876  adxbdy = adx * bdy;
1877  bdxady = bdx * ady;
1878  clift = cdx * cdx + cdy * cdy;
1879 
1880  det = alift * (bdxcdy - cdxbdy) + blift * (cdxady - adxcdy) + clift * (adxbdy - bdxady);
1881 
1882  permanent = (Absolute(bdxcdy) + Absolute(cdxbdy)) * alift +
1883  (Absolute(cdxady) + Absolute(adxcdy)) * blift +
1884  (Absolute(adxbdy) + Absolute(bdxady)) * clift;
1885  errbound = iccerrboundA * permanent;
1886  if ((det > errbound) || (-det > errbound)) {
1887  return det;
1888  }
1889 
1890  return incircleadapt(pa, pb, pc, pd, permanent);
1891 }
1892 
1914  const double *pa, const double *pb, const double *pc, const double *pd, const double *pe)
1915 {
1916  double aex, bex, cex, dex;
1917  double aey, bey, cey, dey;
1918  double aez, bez, cez, dez;
1919  double alift, blift, clift, dlift;
1920  double ab, bc, cd, da, ac, bd;
1921  double abc, bcd, cda, dab;
1922 
1923  aex = pa[0] - pe[0];
1924  bex = pb[0] - pe[0];
1925  cex = pc[0] - pe[0];
1926  dex = pd[0] - pe[0];
1927  aey = pa[1] - pe[1];
1928  bey = pb[1] - pe[1];
1929  cey = pc[1] - pe[1];
1930  dey = pd[1] - pe[1];
1931  aez = pa[2] - pe[2];
1932  bez = pb[2] - pe[2];
1933  cez = pc[2] - pe[2];
1934  dez = pd[2] - pe[2];
1935 
1936  ab = aex * bey - bex * aey;
1937  bc = bex * cey - cex * bey;
1938  cd = cex * dey - dex * cey;
1939  da = dex * aey - aex * dey;
1940 
1941  ac = aex * cey - cex * aey;
1942  bd = bex * dey - dex * bey;
1943 
1944  abc = aez * bc - bez * ac + cez * ab;
1945  bcd = bez * cd - cez * bd + dez * bc;
1946  cda = cez * da + dez * ac + aez * cd;
1947  dab = dez * ab + aez * bd + bez * da;
1948 
1949  alift = aex * aex + aey * aey + aez * aez;
1950  blift = bex * bex + bey * bey + bez * bez;
1951  clift = cex * cex + cey * cey + cez * cez;
1952  dlift = dex * dex + dey * dey + dez * dez;
1953 
1954  return (dlift * abc - clift * dab) + (blift * cda - alift * bcd);
1955 }
1956 
1957 static double insphereexact(
1958  const double *pa, const double *pb, const double *pc, const double *pd, const double *pe)
1959 {
1960  INEXACT double axby1, bxcy1, cxdy1, dxey1, exay1;
1961  INEXACT double bxay1, cxby1, dxcy1, exdy1, axey1;
1962  INEXACT double axcy1, bxdy1, cxey1, dxay1, exby1;
1963  INEXACT double cxay1, dxby1, excy1, axdy1, bxey1;
1964  double axby0, bxcy0, cxdy0, dxey0, exay0;
1965  double bxay0, cxby0, dxcy0, exdy0, axey0;
1966  double axcy0, bxdy0, cxey0, dxay0, exby0;
1967  double cxay0, dxby0, excy0, axdy0, bxey0;
1968  double ab[4], bc[4], cd[4], de[4], ea[4];
1969  double ac[4], bd[4], ce[4], da[4], eb[4];
1970  double temp8a[8], temp8b[8], temp16[16];
1971  int temp8alen, temp8blen, temp16len;
1972  double abc[24], bcd[24], cde[24], dea[24], eab[24];
1973  double abd[24], bce[24], cda[24], deb[24], eac[24];
1974  int abclen, bcdlen, cdelen, dealen, eablen;
1975  int abdlen, bcelen, cdalen, deblen, eaclen;
1976  double temp48a[48], temp48b[48];
1977  int temp48alen, temp48blen;
1978  double abcd[96], bcde[96], cdea[96], deab[96], eabc[96];
1979  int abcdlen, bcdelen, cdealen, deablen, eabclen;
1980  double temp192[192];
1981  double det384x[384], det384y[384], det384z[384];
1982  int xlen, ylen, zlen;
1983  double detxy[768];
1984  int xylen;
1985  double adet[1152], bdet[1152], cdet[1152], ddet[1152], edet[1152];
1986  int alen, blen, clen, dlen, elen;
1987  double abdet[2304], cddet[2304], cdedet[3456];
1988  int ablen, cdlen;
1989  double deter[5760];
1990  int deterlen;
1991  int i;
1992 
1993  INEXACT double bvirt;
1994  double avirt, bround, around;
1995  INEXACT double c;
1996  INEXACT double abig;
1997  double ahi, alo, bhi, blo;
1998  double err1, err2, err3;
1999  INEXACT double _i, _j;
2000  double _0;
2001 
2002  Two_Product(pa[0], pb[1], axby1, axby0);
2003  Two_Product(pb[0], pa[1], bxay1, bxay0);
2004  Two_Two_Diff(axby1, axby0, bxay1, bxay0, ab[3], ab[2], ab[1], ab[0]);
2005 
2006  Two_Product(pb[0], pc[1], bxcy1, bxcy0);
2007  Two_Product(pc[0], pb[1], cxby1, cxby0);
2008  Two_Two_Diff(bxcy1, bxcy0, cxby1, cxby0, bc[3], bc[2], bc[1], bc[0]);
2009 
2010  Two_Product(pc[0], pd[1], cxdy1, cxdy0);
2011  Two_Product(pd[0], pc[1], dxcy1, dxcy0);
2012  Two_Two_Diff(cxdy1, cxdy0, dxcy1, dxcy0, cd[3], cd[2], cd[1], cd[0]);
2013 
2014  Two_Product(pd[0], pe[1], dxey1, dxey0);
2015  Two_Product(pe[0], pd[1], exdy1, exdy0);
2016  Two_Two_Diff(dxey1, dxey0, exdy1, exdy0, de[3], de[2], de[1], de[0]);
2017 
2018  Two_Product(pe[0], pa[1], exay1, exay0);
2019  Two_Product(pa[0], pe[1], axey1, axey0);
2020  Two_Two_Diff(exay1, exay0, axey1, axey0, ea[3], ea[2], ea[1], ea[0]);
2021 
2022  Two_Product(pa[0], pc[1], axcy1, axcy0);
2023  Two_Product(pc[0], pa[1], cxay1, cxay0);
2024  Two_Two_Diff(axcy1, axcy0, cxay1, cxay0, ac[3], ac[2], ac[1], ac[0]);
2025 
2026  Two_Product(pb[0], pd[1], bxdy1, bxdy0);
2027  Two_Product(pd[0], pb[1], dxby1, dxby0);
2028  Two_Two_Diff(bxdy1, bxdy0, dxby1, dxby0, bd[3], bd[2], bd[1], bd[0]);
2029 
2030  Two_Product(pc[0], pe[1], cxey1, cxey0);
2031  Two_Product(pe[0], pc[1], excy1, excy0);
2032  Two_Two_Diff(cxey1, cxey0, excy1, excy0, ce[3], ce[2], ce[1], ce[0]);
2033 
2034  Two_Product(pd[0], pa[1], dxay1, dxay0);
2035  Two_Product(pa[0], pd[1], axdy1, axdy0);
2036  Two_Two_Diff(dxay1, dxay0, axdy1, axdy0, da[3], da[2], da[1], da[0]);
2037 
2038  Two_Product(pe[0], pb[1], exby1, exby0);
2039  Two_Product(pb[0], pe[1], bxey1, bxey0);
2040  Two_Two_Diff(exby1, exby0, bxey1, bxey0, eb[3], eb[2], eb[1], eb[0]);
2041 
2042  temp8alen = scale_expansion_zeroelim(4, bc, pa[2], temp8a);
2043  temp8blen = scale_expansion_zeroelim(4, ac, -pb[2], temp8b);
2044  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2045  temp8alen = scale_expansion_zeroelim(4, ab, pc[2], temp8a);
2046  abclen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16, abc);
2047 
2048  temp8alen = scale_expansion_zeroelim(4, cd, pb[2], temp8a);
2049  temp8blen = scale_expansion_zeroelim(4, bd, -pc[2], temp8b);
2050  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2051  temp8alen = scale_expansion_zeroelim(4, bc, pd[2], temp8a);
2052  bcdlen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16, bcd);
2053 
2054  temp8alen = scale_expansion_zeroelim(4, de, pc[2], temp8a);
2055  temp8blen = scale_expansion_zeroelim(4, ce, -pd[2], temp8b);
2056  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2057  temp8alen = scale_expansion_zeroelim(4, cd, pe[2], temp8a);
2058  cdelen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16, cde);
2059 
2060  temp8alen = scale_expansion_zeroelim(4, ea, pd[2], temp8a);
2061  temp8blen = scale_expansion_zeroelim(4, da, -pe[2], temp8b);
2062  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2063  temp8alen = scale_expansion_zeroelim(4, de, pa[2], temp8a);
2064  dealen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16, dea);
2065 
2066  temp8alen = scale_expansion_zeroelim(4, ab, pe[2], temp8a);
2067  temp8blen = scale_expansion_zeroelim(4, eb, -pa[2], temp8b);
2068  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2069  temp8alen = scale_expansion_zeroelim(4, ea, pb[2], temp8a);
2070  eablen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16, eab);
2071 
2072  temp8alen = scale_expansion_zeroelim(4, bd, pa[2], temp8a);
2073  temp8blen = scale_expansion_zeroelim(4, da, pb[2], temp8b);
2074  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2075  temp8alen = scale_expansion_zeroelim(4, ab, pd[2], temp8a);
2076  abdlen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16, abd);
2077 
2078  temp8alen = scale_expansion_zeroelim(4, ce, pb[2], temp8a);
2079  temp8blen = scale_expansion_zeroelim(4, eb, pc[2], temp8b);
2080  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2081  temp8alen = scale_expansion_zeroelim(4, bc, pe[2], temp8a);
2082  bcelen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16, bce);
2083 
2084  temp8alen = scale_expansion_zeroelim(4, da, pc[2], temp8a);
2085  temp8blen = scale_expansion_zeroelim(4, ac, pd[2], temp8b);
2086  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2087  temp8alen = scale_expansion_zeroelim(4, cd, pa[2], temp8a);
2088  cdalen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16, cda);
2089 
2090  temp8alen = scale_expansion_zeroelim(4, eb, pd[2], temp8a);
2091  temp8blen = scale_expansion_zeroelim(4, bd, pe[2], temp8b);
2092  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2093  temp8alen = scale_expansion_zeroelim(4, de, pb[2], temp8a);
2094  deblen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16, deb);
2095 
2096  temp8alen = scale_expansion_zeroelim(4, ac, pe[2], temp8a);
2097  temp8blen = scale_expansion_zeroelim(4, ce, pa[2], temp8b);
2098  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2099  temp8alen = scale_expansion_zeroelim(4, ea, pc[2], temp8a);
2100  eaclen = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp16len, temp16, eac);
2101 
2102  temp48alen = fast_expansion_sum_zeroelim(cdelen, cde, bcelen, bce, temp48a);
2103  temp48blen = fast_expansion_sum_zeroelim(deblen, deb, bcdlen, bcd, temp48b);
2104  for (i = 0; i < temp48blen; i++) {
2105  temp48b[i] = -temp48b[i];
2106  }
2107  bcdelen = fast_expansion_sum_zeroelim(temp48alen, temp48a, temp48blen, temp48b, bcde);
2108  xlen = scale_expansion_zeroelim(bcdelen, bcde, pa[0], temp192);
2109  xlen = scale_expansion_zeroelim(xlen, temp192, pa[0], det384x);
2110  ylen = scale_expansion_zeroelim(bcdelen, bcde, pa[1], temp192);
2111  ylen = scale_expansion_zeroelim(ylen, temp192, pa[1], det384y);
2112  zlen = scale_expansion_zeroelim(bcdelen, bcde, pa[2], temp192);
2113  zlen = scale_expansion_zeroelim(zlen, temp192, pa[2], det384z);
2114  xylen = fast_expansion_sum_zeroelim(xlen, det384x, ylen, det384y, detxy);
2115  alen = fast_expansion_sum_zeroelim(xylen, detxy, zlen, det384z, adet);
2116 
2117  temp48alen = fast_expansion_sum_zeroelim(dealen, dea, cdalen, cda, temp48a);
2118  temp48blen = fast_expansion_sum_zeroelim(eaclen, eac, cdelen, cde, temp48b);
2119  for (i = 0; i < temp48blen; i++) {
2120  temp48b[i] = -temp48b[i];
2121  }
2122  cdealen = fast_expansion_sum_zeroelim(temp48alen, temp48a, temp48blen, temp48b, cdea);
2123  xlen = scale_expansion_zeroelim(cdealen, cdea, pb[0], temp192);
2124  xlen = scale_expansion_zeroelim(xlen, temp192, pb[0], det384x);
2125  ylen = scale_expansion_zeroelim(cdealen, cdea, pb[1], temp192);
2126  ylen = scale_expansion_zeroelim(ylen, temp192, pb[1], det384y);
2127  zlen = scale_expansion_zeroelim(cdealen, cdea, pb[2], temp192);
2128  zlen = scale_expansion_zeroelim(zlen, temp192, pb[2], det384z);
2129  xylen = fast_expansion_sum_zeroelim(xlen, det384x, ylen, det384y, detxy);
2130  blen = fast_expansion_sum_zeroelim(xylen, detxy, zlen, det384z, bdet);
2131 
2132  temp48alen = fast_expansion_sum_zeroelim(eablen, eab, deblen, deb, temp48a);
2133  temp48blen = fast_expansion_sum_zeroelim(abdlen, abd, dealen, dea, temp48b);
2134  for (i = 0; i < temp48blen; i++) {
2135  temp48b[i] = -temp48b[i];
2136  }
2137  deablen = fast_expansion_sum_zeroelim(temp48alen, temp48a, temp48blen, temp48b, deab);
2138  xlen = scale_expansion_zeroelim(deablen, deab, pc[0], temp192);
2139  xlen = scale_expansion_zeroelim(xlen, temp192, pc[0], det384x);
2140  ylen = scale_expansion_zeroelim(deablen, deab, pc[1], temp192);
2141  ylen = scale_expansion_zeroelim(ylen, temp192, pc[1], det384y);
2142  zlen = scale_expansion_zeroelim(deablen, deab, pc[2], temp192);
2143  zlen = scale_expansion_zeroelim(zlen, temp192, pc[2], det384z);
2144  xylen = fast_expansion_sum_zeroelim(xlen, det384x, ylen, det384y, detxy);
2145  clen = fast_expansion_sum_zeroelim(xylen, detxy, zlen, det384z, cdet);
2146 
2147  temp48alen = fast_expansion_sum_zeroelim(abclen, abc, eaclen, eac, temp48a);
2148  temp48blen = fast_expansion_sum_zeroelim(bcelen, bce, eablen, eab, temp48b);
2149  for (i = 0; i < temp48blen; i++) {
2150  temp48b[i] = -temp48b[i];
2151  }
2152  eabclen = fast_expansion_sum_zeroelim(temp48alen, temp48a, temp48blen, temp48b, eabc);
2153  xlen = scale_expansion_zeroelim(eabclen, eabc, pd[0], temp192);
2154  xlen = scale_expansion_zeroelim(xlen, temp192, pd[0], det384x);
2155  ylen = scale_expansion_zeroelim(eabclen, eabc, pd[1], temp192);
2156  ylen = scale_expansion_zeroelim(ylen, temp192, pd[1], det384y);
2157  zlen = scale_expansion_zeroelim(eabclen, eabc, pd[2], temp192);
2158  zlen = scale_expansion_zeroelim(zlen, temp192, pd[2], det384z);
2159  xylen = fast_expansion_sum_zeroelim(xlen, det384x, ylen, det384y, detxy);
2160  dlen = fast_expansion_sum_zeroelim(xylen, detxy, zlen, det384z, ddet);
2161 
2162  temp48alen = fast_expansion_sum_zeroelim(bcdlen, bcd, abdlen, abd, temp48a);
2163  temp48blen = fast_expansion_sum_zeroelim(cdalen, cda, abclen, abc, temp48b);
2164  for (i = 0; i < temp48blen; i++) {
2165  temp48b[i] = -temp48b[i];
2166  }
2167  abcdlen = fast_expansion_sum_zeroelim(temp48alen, temp48a, temp48blen, temp48b, abcd);
2168  xlen = scale_expansion_zeroelim(abcdlen, abcd, pe[0], temp192);
2169  xlen = scale_expansion_zeroelim(xlen, temp192, pe[0], det384x);
2170  ylen = scale_expansion_zeroelim(abcdlen, abcd, pe[1], temp192);
2171  ylen = scale_expansion_zeroelim(ylen, temp192, pe[1], det384y);
2172  zlen = scale_expansion_zeroelim(abcdlen, abcd, pe[2], temp192);
2173  zlen = scale_expansion_zeroelim(zlen, temp192, pe[2], det384z);
2174  xylen = fast_expansion_sum_zeroelim(xlen, det384x, ylen, det384y, detxy);
2175  elen = fast_expansion_sum_zeroelim(xylen, detxy, zlen, det384z, edet);
2176 
2177  ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
2178  cdlen = fast_expansion_sum_zeroelim(clen, cdet, dlen, ddet, cddet);
2179  cdelen = fast_expansion_sum_zeroelim(cdlen, cddet, elen, edet, cdedet);
2180  deterlen = fast_expansion_sum_zeroelim(ablen, abdet, cdelen, cdedet, deter);
2181 
2182  return deter[deterlen - 1];
2183 }
2184 
2185 static double insphereadapt(const double *pa,
2186  const double *pb,
2187  const double *pc,
2188  const double *pd,
2189  const double *pe,
2190  double permanent)
2191 {
2192  INEXACT double aex, bex, cex, dex, aey, bey, cey, dey, aez, bez, cez, dez;
2193  double det, errbound;
2194 
2195  INEXACT double aexbey1, bexaey1, bexcey1, cexbey1;
2196  INEXACT double cexdey1, dexcey1, dexaey1, aexdey1;
2197  INEXACT double aexcey1, cexaey1, bexdey1, dexbey1;
2198  double aexbey0, bexaey0, bexcey0, cexbey0;
2199  double cexdey0, dexcey0, dexaey0, aexdey0;
2200  double aexcey0, cexaey0, bexdey0, dexbey0;
2201  double ab[4], bc[4], cd[4], da[4], ac[4], bd[4];
2202  INEXACT double ab3, bc3, cd3, da3, ac3, bd3;
2203  double abeps, bceps, cdeps, daeps, aceps, bdeps;
2204  double temp8a[8], temp8b[8], temp8c[8], temp16[16], temp24[24], temp48[48];
2205  int temp8alen, temp8blen, temp8clen, temp16len, temp24len, temp48len;
2206  double xdet[96], ydet[96], zdet[96], xydet[192];
2207  int xlen, ylen, zlen, xylen;
2208  double adet[288], bdet[288], cdet[288], ddet[288];
2209  int alen, blen, clen, dlen;
2210  double abdet[576], cddet[576];
2211  int ablen, cdlen;
2212  double fin1[1152];
2213  int finlength;
2214 
2215  double aextail, bextail, cextail, dextail;
2216  double aeytail, beytail, ceytail, deytail;
2217  double aeztail, beztail, ceztail, deztail;
2218 
2219  INEXACT double bvirt;
2220  double avirt, bround, around;
2221  INEXACT double c;
2222  INEXACT double abig;
2223  double ahi, alo, bhi, blo;
2224  double err1, err2, err3;
2225  INEXACT double _i, _j;
2226  double _0;
2227 
2228  aex = (double)(pa[0] - pe[0]);
2229  bex = (double)(pb[0] - pe[0]);
2230  cex = (double)(pc[0] - pe[0]);
2231  dex = (double)(pd[0] - pe[0]);
2232  aey = (double)(pa[1] - pe[1]);
2233  bey = (double)(pb[1] - pe[1]);
2234  cey = (double)(pc[1] - pe[1]);
2235  dey = (double)(pd[1] - pe[1]);
2236  aez = (double)(pa[2] - pe[2]);
2237  bez = (double)(pb[2] - pe[2]);
2238  cez = (double)(pc[2] - pe[2]);
2239  dez = (double)(pd[2] - pe[2]);
2240 
2241  Two_Product(aex, bey, aexbey1, aexbey0);
2242  Two_Product(bex, aey, bexaey1, bexaey0);
2243  Two_Two_Diff(aexbey1, aexbey0, bexaey1, bexaey0, ab3, ab[2], ab[1], ab[0]);
2244  ab[3] = ab3;
2245 
2246  Two_Product(bex, cey, bexcey1, bexcey0);
2247  Two_Product(cex, bey, cexbey1, cexbey0);
2248  Two_Two_Diff(bexcey1, bexcey0, cexbey1, cexbey0, bc3, bc[2], bc[1], bc[0]);
2249  bc[3] = bc3;
2250 
2251  Two_Product(cex, dey, cexdey1, cexdey0);
2252  Two_Product(dex, cey, dexcey1, dexcey0);
2253  Two_Two_Diff(cexdey1, cexdey0, dexcey1, dexcey0, cd3, cd[2], cd[1], cd[0]);
2254  cd[3] = cd3;
2255 
2256  Two_Product(dex, aey, dexaey1, dexaey0);
2257  Two_Product(aex, dey, aexdey1, aexdey0);
2258  Two_Two_Diff(dexaey1, dexaey0, aexdey1, aexdey0, da3, da[2], da[1], da[0]);
2259  da[3] = da3;
2260 
2261  Two_Product(aex, cey, aexcey1, aexcey0);
2262  Two_Product(cex, aey, cexaey1, cexaey0);
2263  Two_Two_Diff(aexcey1, aexcey0, cexaey1, cexaey0, ac3, ac[2], ac[1], ac[0]);
2264  ac[3] = ac3;
2265 
2266  Two_Product(bex, dey, bexdey1, bexdey0);
2267  Two_Product(dex, bey, dexbey1, dexbey0);
2268  Two_Two_Diff(bexdey1, bexdey0, dexbey1, dexbey0, bd3, bd[2], bd[1], bd[0]);
2269  bd[3] = bd3;
2270 
2271  temp8alen = scale_expansion_zeroelim(4, cd, bez, temp8a);
2272  temp8blen = scale_expansion_zeroelim(4, bd, -cez, temp8b);
2273  temp8clen = scale_expansion_zeroelim(4, bc, dez, temp8c);
2274  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2275  temp24len = fast_expansion_sum_zeroelim(temp8clen, temp8c, temp16len, temp16, temp24);
2276  temp48len = scale_expansion_zeroelim(temp24len, temp24, aex, temp48);
2277  xlen = scale_expansion_zeroelim(temp48len, temp48, -aex, xdet);
2278  temp48len = scale_expansion_zeroelim(temp24len, temp24, aey, temp48);
2279  ylen = scale_expansion_zeroelim(temp48len, temp48, -aey, ydet);
2280  temp48len = scale_expansion_zeroelim(temp24len, temp24, aez, temp48);
2281  zlen = scale_expansion_zeroelim(temp48len, temp48, -aez, zdet);
2282  xylen = fast_expansion_sum_zeroelim(xlen, xdet, ylen, ydet, xydet);
2283  alen = fast_expansion_sum_zeroelim(xylen, xydet, zlen, zdet, adet);
2284 
2285  temp8alen = scale_expansion_zeroelim(4, da, cez, temp8a);
2286  temp8blen = scale_expansion_zeroelim(4, ac, dez, temp8b);
2287  temp8clen = scale_expansion_zeroelim(4, cd, aez, temp8c);
2288  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2289  temp24len = fast_expansion_sum_zeroelim(temp8clen, temp8c, temp16len, temp16, temp24);
2290  temp48len = scale_expansion_zeroelim(temp24len, temp24, bex, temp48);
2291  xlen = scale_expansion_zeroelim(temp48len, temp48, bex, xdet);
2292  temp48len = scale_expansion_zeroelim(temp24len, temp24, bey, temp48);
2293  ylen = scale_expansion_zeroelim(temp48len, temp48, bey, ydet);
2294  temp48len = scale_expansion_zeroelim(temp24len, temp24, bez, temp48);
2295  zlen = scale_expansion_zeroelim(temp48len, temp48, bez, zdet);
2296  xylen = fast_expansion_sum_zeroelim(xlen, xdet, ylen, ydet, xydet);
2297  blen = fast_expansion_sum_zeroelim(xylen, xydet, zlen, zdet, bdet);
2298 
2299  temp8alen = scale_expansion_zeroelim(4, ab, dez, temp8a);
2300  temp8blen = scale_expansion_zeroelim(4, bd, aez, temp8b);
2301  temp8clen = scale_expansion_zeroelim(4, da, bez, temp8c);
2302  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2303  temp24len = fast_expansion_sum_zeroelim(temp8clen, temp8c, temp16len, temp16, temp24);
2304  temp48len = scale_expansion_zeroelim(temp24len, temp24, cex, temp48);
2305  xlen = scale_expansion_zeroelim(temp48len, temp48, -cex, xdet);
2306  temp48len = scale_expansion_zeroelim(temp24len, temp24, cey, temp48);
2307  ylen = scale_expansion_zeroelim(temp48len, temp48, -cey, ydet);
2308  temp48len = scale_expansion_zeroelim(temp24len, temp24, cez, temp48);
2309  zlen = scale_expansion_zeroelim(temp48len, temp48, -cez, zdet);
2310  xylen = fast_expansion_sum_zeroelim(xlen, xdet, ylen, ydet, xydet);
2311  clen = fast_expansion_sum_zeroelim(xylen, xydet, zlen, zdet, cdet);
2312 
2313  temp8alen = scale_expansion_zeroelim(4, bc, aez, temp8a);
2314  temp8blen = scale_expansion_zeroelim(4, ac, -bez, temp8b);
2315  temp8clen = scale_expansion_zeroelim(4, ab, cez, temp8c);
2316  temp16len = fast_expansion_sum_zeroelim(temp8alen, temp8a, temp8blen, temp8b, temp16);
2317  temp24len = fast_expansion_sum_zeroelim(temp8clen, temp8c, temp16len, temp16, temp24);
2318  temp48len = scale_expansion_zeroelim(temp24len, temp24, dex, temp48);
2319  xlen = scale_expansion_zeroelim(temp48len, temp48, dex, xdet);
2320  temp48len = scale_expansion_zeroelim(temp24len, temp24, dey, temp48);
2321  ylen = scale_expansion_zeroelim(temp48len, temp48, dey, ydet);
2322  temp48len = scale_expansion_zeroelim(temp24len, temp24, dez, temp48);
2323  zlen = scale_expansion_zeroelim(temp48len, temp48, dez, zdet);
2324  xylen = fast_expansion_sum_zeroelim(xlen, xdet, ylen, ydet, xydet);
2325  dlen = fast_expansion_sum_zeroelim(xylen, xydet, zlen, zdet, ddet);
2326 
2327  ablen = fast_expansion_sum_zeroelim(alen, adet, blen, bdet, abdet);
2328  cdlen = fast_expansion_sum_zeroelim(clen, cdet, dlen, ddet, cddet);
2329  finlength = fast_expansion_sum_zeroelim(ablen, abdet, cdlen, cddet, fin1);
2330 
2331  det = estimate(finlength, fin1);
2332  errbound = isperrboundB * permanent;
2333  if ((det >= errbound) || (-det >= errbound)) {
2334  return det;
2335  }
2336 
2337  Two_Diff_Tail(pa[0], pe[0], aex, aextail);
2338  Two_Diff_Tail(pa[1], pe[1], aey, aeytail);
2339  Two_Diff_Tail(pa[2], pe[2], aez, aeztail);
2340  Two_Diff_Tail(pb[0], pe[0], bex, bextail);
2341  Two_Diff_Tail(pb[1], pe[1], bey, beytail);
2342  Two_Diff_Tail(pb[2], pe[2], bez, beztail);
2343  Two_Diff_Tail(pc[0], pe[0], cex, cextail);
2344  Two_Diff_Tail(pc[1], pe[1], cey, ceytail);
2345  Two_Diff_Tail(pc[2], pe[2], cez, ceztail);
2346  Two_Diff_Tail(pd[0], pe[0], dex, dextail);
2347  Two_Diff_Tail(pd[1], pe[1], dey, deytail);
2348  Two_Diff_Tail(pd[2], pe[2], dez, deztail);
2349  if ((aextail == 0.0) && (aeytail == 0.0) && (aeztail == 0.0) && (bextail == 0.0) &&
2350  (beytail == 0.0) && (beztail == 0.0) && (cextail == 0.0) && (ceytail == 0.0) &&
2351  (ceztail == 0.0) && (dextail == 0.0) && (deytail == 0.0) && (deztail == 0.0)) {
2352  return det;
2353  }
2354 
2355  errbound = isperrboundC * permanent + resulterrbound * Absolute(det);
2356  abeps = (aex * beytail + bey * aextail) - (aey * bextail + bex * aeytail);
2357  bceps = (bex * ceytail + cey * bextail) - (bey * cextail + cex * beytail);
2358  cdeps = (cex * deytail + dey * cextail) - (cey * dextail + dex * ceytail);
2359  daeps = (dex * aeytail + aey * dextail) - (dey * aextail + aex * deytail);
2360  aceps = (aex * ceytail + cey * aextail) - (aey * cextail + cex * aeytail);
2361  bdeps = (bex * deytail + dey * bextail) - (bey * dextail + dex * beytail);
2362  det +=
2363  (((bex * bex + bey * bey + bez * bez) * ((cez * daeps + dez * aceps + aez * cdeps) +
2364  (ceztail * da3 + deztail * ac3 + aeztail * cd3)) +
2365  (dex * dex + dey * dey + dez * dez) * ((aez * bceps - bez * aceps + cez * abeps) +
2366  (aeztail * bc3 - beztail * ac3 + ceztail * ab3))) -
2367  ((aex * aex + aey * aey + aez * aez) * ((bez * cdeps - cez * bdeps + dez * bceps) +
2368  (beztail * cd3 - ceztail * bd3 + deztail * bc3)) +
2369  (cex * cex + cey * cey + cez * cez) * ((dez * abeps + aez * bdeps + bez * daeps) +
2370  (deztail * ab3 + aeztail * bd3 + beztail * da3)))) +
2371  2.0 *
2372  (((bex * bextail + bey * beytail + bez * beztail) * (cez * da3 + dez * ac3 + aez * cd3) +
2373  (dex * dextail + dey * deytail + dez * deztail) *
2374  (aez * bc3 - bez * ac3 + cez * ab3)) -
2375  ((aex * aextail + aey * aeytail + aez * aeztail) * (bez * cd3 - cez * bd3 + dez * bc3) +
2376  (cex * cextail + cey * ceytail + cez * ceztail) *
2377  (dez * ab3 + aez * bd3 + bez * da3)));
2378  if ((det >= errbound) || (-det >= errbound)) {
2379  return det;
2380  }
2381 
2382  return insphereexact(pa, pb, pc, pd, pe);
2383 }
2384 
2385 double insphere(
2386  const double *pa, const double *pb, const double *pc, const double *pd, const double *pe)
2387 {
2388  double aex, bex, cex, dex;
2389  double aey, bey, cey, dey;
2390  double aez, bez, cez, dez;
2391  double aexbey, bexaey, bexcey, cexbey, cexdey, dexcey, dexaey, aexdey;
2392  double aexcey, cexaey, bexdey, dexbey;
2393  double alift, blift, clift, dlift;
2394  double ab, bc, cd, da, ac, bd;
2395  double abc, bcd, cda, dab;
2396  double aezplus, bezplus, cezplus, dezplus;
2397  double aexbeyplus, bexaeyplus, bexceyplus, cexbeyplus;
2398  double cexdeyplus, dexceyplus, dexaeyplus, aexdeyplus;
2399  double aexceyplus, cexaeyplus, bexdeyplus, dexbeyplus;
2400  double det;
2401  double permanent, errbound;
2402 
2403  aex = pa[0] - pe[0];
2404  bex = pb[0] - pe[0];
2405  cex = pc[0] - pe[0];
2406  dex = pd[0] - pe[0];
2407  aey = pa[1] - pe[1];
2408  bey = pb[1] - pe[1];
2409  cey = pc[1] - pe[1];
2410  dey = pd[1] - pe[1];
2411  aez = pa[2] - pe[2];
2412  bez = pb[2] - pe[2];
2413  cez = pc[2] - pe[2];
2414  dez = pd[2] - pe[2];
2415 
2416  aexbey = aex * bey;
2417  bexaey = bex * aey;
2418  ab = aexbey - bexaey;
2419  bexcey = bex * cey;
2420  cexbey = cex * bey;
2421  bc = bexcey - cexbey;
2422  cexdey = cex * dey;
2423  dexcey = dex * cey;
2424  cd = cexdey - dexcey;
2425  dexaey = dex * aey;
2426  aexdey = aex * dey;
2427  da = dexaey - aexdey;
2428 
2429  aexcey = aex * cey;
2430  cexaey = cex * aey;
2431  ac = aexcey - cexaey;
2432  bexdey = bex * dey;
2433  dexbey = dex * bey;
2434  bd = bexdey - dexbey;
2435 
2436  abc = aez * bc - bez * ac + cez * ab;
2437  bcd = bez * cd - cez * bd + dez * bc;
2438  cda = cez * da + dez * ac + aez * cd;
2439  dab = dez * ab + aez * bd + bez * da;
2440 
2441  alift = aex * aex + aey * aey + aez * aez;
2442  blift = bex * bex + bey * bey + bez * bez;
2443  clift = cex * cex + cey * cey + cez * cez;
2444  dlift = dex * dex + dey * dey + dez * dez;
2445 
2446  det = (dlift * abc - clift * dab) + (blift * cda - alift * bcd);
2447 
2448  aezplus = Absolute(aez);
2449  bezplus = Absolute(bez);
2450  cezplus = Absolute(cez);
2451  dezplus = Absolute(dez);
2452  aexbeyplus = Absolute(aexbey);
2453  bexaeyplus = Absolute(bexaey);
2454  bexceyplus = Absolute(bexcey);
2455  cexbeyplus = Absolute(cexbey);
2456  cexdeyplus = Absolute(cexdey);
2457  dexceyplus = Absolute(dexcey);
2458  dexaeyplus = Absolute(dexaey);
2459  aexdeyplus = Absolute(aexdey);
2460  aexceyplus = Absolute(aexcey);
2461  cexaeyplus = Absolute(cexaey);
2462  bexdeyplus = Absolute(bexdey);
2463  dexbeyplus = Absolute(dexbey);
2464  permanent = ((cexdeyplus + dexceyplus) * bezplus + (dexbeyplus + bexdeyplus) * cezplus +
2465  (bexceyplus + cexbeyplus) * dezplus) *
2466  alift +
2467  ((dexaeyplus + aexdeyplus) * cezplus + (aexceyplus + cexaeyplus) * dezplus +
2468  (cexdeyplus + dexceyplus) * aezplus) *
2469  blift +
2470  ((aexbeyplus + bexaeyplus) * dezplus + (bexdeyplus + dexbeyplus) * aezplus +
2471  (dexaeyplus + aexdeyplus) * bezplus) *
2472  clift +
2473  ((bexceyplus + cexbeyplus) * aezplus + (cexaeyplus + aexceyplus) * bezplus +
2474  (aexbeyplus + bexaeyplus) * cezplus) *
2475  dlift;
2476  errbound = isperrboundA * permanent;
2477  if ((det > errbound) || (-det > errbound)) {
2478  return det;
2479  }
2480 
2481  return insphereadapt(pa, pb, pc, pd, pe, permanent);
2482 }
2483 
2484 } /* namespace robust_pred */
2485 
2486 static int sgn(double x)
2487 {
2488  return (x > 0) ? 1 : ((x < 0) ? -1 : 0);
2489 }
2490 
2491 int orient2d(const double2 &a, const double2 &b, const double2 &c)
2492 {
2493  return sgn(blender::robust_pred::orient2d(a, b, c));
2494 }
2495 
2496 int orient2d_fast(const double2 &a, const double2 &b, const double2 &c)
2497 {
2499 }
2500 
2501 int incircle(const double2 &a, const double2 &b, const double2 &c, const double2 &d)
2502 {
2503  return sgn(robust_pred::incircle(a, b, c, d));
2504 }
2505 
2506 int incircle_fast(const double2 &a, const double2 &b, const double2 &c, const double2 &d)
2507 {
2508  return sgn(robust_pred::incirclefast(a, b, c, d));
2509 }
2510 
2511 int orient3d(const double3 &a, const double3 &b, const double3 &c, const double3 &d)
2512 {
2513  return sgn(robust_pred::orient3d(a, b, c, d));
2514 }
2515 
2516 int orient3d_fast(const double3 &a, const double3 &b, const double3 &c, const double3 &d)
2517 {
2518  return sgn(robust_pred::orient3dfast(a, b, c, d));
2519 }
2520 
2522  const double3 &a, const double3 &b, const double3 &c, const double3 &d, const double3 &e)
2523 {
2524  return sgn(robust_pred::insphere(a, b, c, d, e));
2525 }
2526 
2528  const double3 &a, const double3 &b, const double3 &c, const double3 &d, const double3 &e)
2529 {
2530  return sgn(robust_pred::inspherefast(a, b, c, d, e));
2531 }
2532 
2533 } // namespace blender
#define D
Math vector functions needed specifically for mesh intersect and boolean.
#define ELEM(...)
typedef double(DMatrix)[4][4]
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
static T sum(const btAlignedObjectArray< T > &items)
Definition: util_half.h:41
unsigned short half
#define Square(a, x, y)
#define Two_Product(a, b, x, y)
#define Two_Product_Presplit(a, b, bhi, blo, x, y)
#define Two_Diff_Tail(a, b, x, y)
#define Two_Sum(a, b, x, y)
#define Two_One_Product(a1, a0, b, x3, x2, x1, x0)
#define Two_Two_Diff(a1, a0, b1, b0, x3, x2, x1, x0)
#define INEXACT
#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)
#define Absolute(a)
#define B
static unsigned c
Definition: RandGen.cpp:97
static double B3(double u)
Definition: FitCurve.cpp:330
static unsigned a[3]
Definition: RandGen.cpp:92
static int fast_expansion_sum_zeroelim(int elen, const double *e, int flen, const double *f, double *h)
static double iccerrboundA
double orient2dfast(const double *pa, const double *pb, const double *pc)
static double resulterrbound
static double ccwerrboundB
static double orient2dadapt(const double *pa, const double *pb, const double *pc, double detsum)
static double o3derrboundC
double incirclefast(const double *pa, const double *pb, const double *pc, const double *pd)
static double isperrboundB
static double o3derrboundB
double insphere(const double *pa, const double *pb, const double *pc, const double *pd, const double *pe)
static double isperrboundC
static double epsilon
static double splitter
static double ccwerrboundC
static double iccerrboundB
static double estimate(int elen, const double *e)
double orient3dfast(const double *pa, const double *pb, const double *pc, const double *pd)
static double isperrboundA
static RobustInitCaller init_caller
static double incircleadapt(const double *pa, const double *pb, const double *pc, const double *pd, double permanent)
static double insphereadapt(const double *pa, const double *pb, const double *pc, const double *pd, const double *pe, double permanent)
static double o3derrboundA
static double orient3dadapt(const double *pa, const double *pb, const double *pc, const double *pd, double permanent)
double orient3d(const double *pa, const double *pb, const double *pc, const double *pd)
static double iccerrboundC
double incircle(const double *pa, const double *pb, const double *pc, const double *pd)
static int scale_expansion_zeroelim(int elen, const double *e, double b, double *h)
double inspherefast(const double *pa, const double *pb, const double *pc, const double *pd, const double *pe)
double orient2d(const double *pa, const double *pb, const double *pc)
static double ccwerrboundA
static double insphereexact(const double *pa, const double *pb, const double *pc, const double *pd, const double *pe)
int orient3d_fast(const double3 &a, const double3 &b, const double3 &c, const double3 &d)
int orient2d(const double2 &a, const double2 &b, const double2 &c)
static int sgn(double x)
int incircle(const double2 &a, const double2 &b, const double2 &c, const double2 &d)
int orient3d(const double3 &a, const double3 &b, const double3 &c, const double3 &d)
int incircle_fast(const double2 &a, const double2 &b, const double2 &c, const double2 &d)
int orient2d_fast(const double2 &a, const double2 &b, const double2 &c)
int insphere_fast(const double3 &a, const double3 &b, const double3 &c, const double3 &d, const double3 &e)
int insphere(const double3 &a, const double3 &b, const double3 &c, const double3 &d, const double3 &e)