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