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