Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

orient3d.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.predicates = {}));
  5. })(this, (function (exports) { 'use strict';
  6. const epsilon = 1.1102230246251565e-16;
  7. const splitter = 134217729;
  8. const resulterrbound = (3 + 8 * epsilon) * epsilon;
  9. // fast_expansion_sum_zeroelim routine from oritinal code
  10. function sum(elen, e, flen, f, h) {
  11. let Q, Qnew, hh, bvirt;
  12. let enow = e[0];
  13. let fnow = f[0];
  14. let eindex = 0;
  15. let findex = 0;
  16. if ((fnow > enow) === (fnow > -enow)) {
  17. Q = enow;
  18. enow = e[++eindex];
  19. } else {
  20. Q = fnow;
  21. fnow = f[++findex];
  22. }
  23. let hindex = 0;
  24. if (eindex < elen && findex < flen) {
  25. if ((fnow > enow) === (fnow > -enow)) {
  26. Qnew = enow + Q;
  27. hh = Q - (Qnew - enow);
  28. enow = e[++eindex];
  29. } else {
  30. Qnew = fnow + Q;
  31. hh = Q - (Qnew - fnow);
  32. fnow = f[++findex];
  33. }
  34. Q = Qnew;
  35. if (hh !== 0) {
  36. h[hindex++] = hh;
  37. }
  38. while (eindex < elen && findex < flen) {
  39. if ((fnow > enow) === (fnow > -enow)) {
  40. Qnew = Q + enow;
  41. bvirt = Qnew - Q;
  42. hh = Q - (Qnew - bvirt) + (enow - bvirt);
  43. enow = e[++eindex];
  44. } else {
  45. Qnew = Q + fnow;
  46. bvirt = Qnew - Q;
  47. hh = Q - (Qnew - bvirt) + (fnow - bvirt);
  48. fnow = f[++findex];
  49. }
  50. Q = Qnew;
  51. if (hh !== 0) {
  52. h[hindex++] = hh;
  53. }
  54. }
  55. }
  56. while (eindex < elen) {
  57. Qnew = Q + enow;
  58. bvirt = Qnew - Q;
  59. hh = Q - (Qnew - bvirt) + (enow - bvirt);
  60. enow = e[++eindex];
  61. Q = Qnew;
  62. if (hh !== 0) {
  63. h[hindex++] = hh;
  64. }
  65. }
  66. while (findex < flen) {
  67. Qnew = Q + fnow;
  68. bvirt = Qnew - Q;
  69. hh = Q - (Qnew - bvirt) + (fnow - bvirt);
  70. fnow = f[++findex];
  71. Q = Qnew;
  72. if (hh !== 0) {
  73. h[hindex++] = hh;
  74. }
  75. }
  76. if (Q !== 0 || hindex === 0) {
  77. h[hindex++] = Q;
  78. }
  79. return hindex;
  80. }
  81. // scale_expansion_zeroelim routine from oritinal code
  82. function scale(elen, e, b, h) {
  83. let Q, sum, hh, product1, product0;
  84. let bvirt, c, ahi, alo, bhi, blo;
  85. c = splitter * b;
  86. bhi = c - (c - b);
  87. blo = b - bhi;
  88. let enow = e[0];
  89. Q = enow * b;
  90. c = splitter * enow;
  91. ahi = c - (c - enow);
  92. alo = enow - ahi;
  93. hh = alo * blo - (Q - ahi * bhi - alo * bhi - ahi * blo);
  94. let hindex = 0;
  95. if (hh !== 0) {
  96. h[hindex++] = hh;
  97. }
  98. for (let i = 1; i < elen; i++) {
  99. enow = e[i];
  100. product1 = enow * b;
  101. c = splitter * enow;
  102. ahi = c - (c - enow);
  103. alo = enow - ahi;
  104. product0 = alo * blo - (product1 - ahi * bhi - alo * bhi - ahi * blo);
  105. sum = Q + product0;
  106. bvirt = sum - Q;
  107. hh = Q - (sum - bvirt) + (product0 - bvirt);
  108. if (hh !== 0) {
  109. h[hindex++] = hh;
  110. }
  111. Q = product1 + sum;
  112. hh = sum - (Q - product1);
  113. if (hh !== 0) {
  114. h[hindex++] = hh;
  115. }
  116. }
  117. if (Q !== 0 || hindex === 0) {
  118. h[hindex++] = Q;
  119. }
  120. return hindex;
  121. }
  122. function estimate(elen, e) {
  123. let Q = e[0];
  124. for (let i = 1; i < elen; i++) Q += e[i];
  125. return Q;
  126. }
  127. function vec(n) {
  128. return new Float64Array(n);
  129. }
  130. const o3derrboundA = (7 + 56 * epsilon) * epsilon;
  131. const o3derrboundB = (3 + 28 * epsilon) * epsilon;
  132. const o3derrboundC = (26 + 288 * epsilon) * epsilon * epsilon;
  133. const bc = vec(4);
  134. const ca = vec(4);
  135. const ab = vec(4);
  136. const at_b = vec(4);
  137. const at_c = vec(4);
  138. const bt_c = vec(4);
  139. const bt_a = vec(4);
  140. const ct_a = vec(4);
  141. const ct_b = vec(4);
  142. const bct = vec(8);
  143. const cat = vec(8);
  144. const abt = vec(8);
  145. const u = vec(4);
  146. const _8 = vec(8);
  147. const _8b = vec(8);
  148. const _16 = vec(8);
  149. const _12 = vec(12);
  150. let fin = vec(192);
  151. let fin2 = vec(192);
  152. function finadd(finlen, alen, a) {
  153. finlen = sum(finlen, fin, alen, a, fin2);
  154. const tmp = fin; fin = fin2; fin2 = tmp;
  155. return finlen;
  156. }
  157. function tailinit(xtail, ytail, ax, ay, bx, by, a, b) {
  158. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3, negate;
  159. if (xtail === 0) {
  160. if (ytail === 0) {
  161. a[0] = 0;
  162. b[0] = 0;
  163. return 1;
  164. } else {
  165. negate = -ytail;
  166. s1 = negate * ax;
  167. c = splitter * negate;
  168. ahi = c - (c - negate);
  169. alo = negate - ahi;
  170. c = splitter * ax;
  171. bhi = c - (c - ax);
  172. blo = ax - bhi;
  173. a[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  174. a[1] = s1;
  175. s1 = ytail * bx;
  176. c = splitter * ytail;
  177. ahi = c - (c - ytail);
  178. alo = ytail - ahi;
  179. c = splitter * bx;
  180. bhi = c - (c - bx);
  181. blo = bx - bhi;
  182. b[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  183. b[1] = s1;
  184. return 2;
  185. }
  186. } else {
  187. if (ytail === 0) {
  188. s1 = xtail * ay;
  189. c = splitter * xtail;
  190. ahi = c - (c - xtail);
  191. alo = xtail - ahi;
  192. c = splitter * ay;
  193. bhi = c - (c - ay);
  194. blo = ay - bhi;
  195. a[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  196. a[1] = s1;
  197. negate = -xtail;
  198. s1 = negate * by;
  199. c = splitter * negate;
  200. ahi = c - (c - negate);
  201. alo = negate - ahi;
  202. c = splitter * by;
  203. bhi = c - (c - by);
  204. blo = by - bhi;
  205. b[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  206. b[1] = s1;
  207. return 2;
  208. } else {
  209. s1 = xtail * ay;
  210. c = splitter * xtail;
  211. ahi = c - (c - xtail);
  212. alo = xtail - ahi;
  213. c = splitter * ay;
  214. bhi = c - (c - ay);
  215. blo = ay - bhi;
  216. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  217. t1 = ytail * ax;
  218. c = splitter * ytail;
  219. ahi = c - (c - ytail);
  220. alo = ytail - ahi;
  221. c = splitter * ax;
  222. bhi = c - (c - ax);
  223. blo = ax - bhi;
  224. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  225. _i = s0 - t0;
  226. bvirt = s0 - _i;
  227. a[0] = s0 - (_i + bvirt) + (bvirt - t0);
  228. _j = s1 + _i;
  229. bvirt = _j - s1;
  230. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  231. _i = _0 - t1;
  232. bvirt = _0 - _i;
  233. a[1] = _0 - (_i + bvirt) + (bvirt - t1);
  234. u3 = _j + _i;
  235. bvirt = u3 - _j;
  236. a[2] = _j - (u3 - bvirt) + (_i - bvirt);
  237. a[3] = u3;
  238. s1 = ytail * bx;
  239. c = splitter * ytail;
  240. ahi = c - (c - ytail);
  241. alo = ytail - ahi;
  242. c = splitter * bx;
  243. bhi = c - (c - bx);
  244. blo = bx - bhi;
  245. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  246. t1 = xtail * by;
  247. c = splitter * xtail;
  248. ahi = c - (c - xtail);
  249. alo = xtail - ahi;
  250. c = splitter * by;
  251. bhi = c - (c - by);
  252. blo = by - bhi;
  253. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  254. _i = s0 - t0;
  255. bvirt = s0 - _i;
  256. b[0] = s0 - (_i + bvirt) + (bvirt - t0);
  257. _j = s1 + _i;
  258. bvirt = _j - s1;
  259. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  260. _i = _0 - t1;
  261. bvirt = _0 - _i;
  262. b[1] = _0 - (_i + bvirt) + (bvirt - t1);
  263. u3 = _j + _i;
  264. bvirt = u3 - _j;
  265. b[2] = _j - (u3 - bvirt) + (_i - bvirt);
  266. b[3] = u3;
  267. return 4;
  268. }
  269. }
  270. }
  271. function tailadd(finlen, a, b, k, z) {
  272. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _k, _0, s1, s0, u3;
  273. s1 = a * b;
  274. c = splitter * a;
  275. ahi = c - (c - a);
  276. alo = a - ahi;
  277. c = splitter * b;
  278. bhi = c - (c - b);
  279. blo = b - bhi;
  280. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  281. c = splitter * k;
  282. bhi = c - (c - k);
  283. blo = k - bhi;
  284. _i = s0 * k;
  285. c = splitter * s0;
  286. ahi = c - (c - s0);
  287. alo = s0 - ahi;
  288. u[0] = alo * blo - (_i - ahi * bhi - alo * bhi - ahi * blo);
  289. _j = s1 * k;
  290. c = splitter * s1;
  291. ahi = c - (c - s1);
  292. alo = s1 - ahi;
  293. _0 = alo * blo - (_j - ahi * bhi - alo * bhi - ahi * blo);
  294. _k = _i + _0;
  295. bvirt = _k - _i;
  296. u[1] = _i - (_k - bvirt) + (_0 - bvirt);
  297. u3 = _j + _k;
  298. u[2] = _k - (u3 - _j);
  299. u[3] = u3;
  300. finlen = finadd(finlen, 4, u);
  301. if (z !== 0) {
  302. c = splitter * z;
  303. bhi = c - (c - z);
  304. blo = z - bhi;
  305. _i = s0 * z;
  306. c = splitter * s0;
  307. ahi = c - (c - s0);
  308. alo = s0 - ahi;
  309. u[0] = alo * blo - (_i - ahi * bhi - alo * bhi - ahi * blo);
  310. _j = s1 * z;
  311. c = splitter * s1;
  312. ahi = c - (c - s1);
  313. alo = s1 - ahi;
  314. _0 = alo * blo - (_j - ahi * bhi - alo * bhi - ahi * blo);
  315. _k = _i + _0;
  316. bvirt = _k - _i;
  317. u[1] = _i - (_k - bvirt) + (_0 - bvirt);
  318. u3 = _j + _k;
  319. u[2] = _k - (u3 - _j);
  320. u[3] = u3;
  321. finlen = finadd(finlen, 4, u);
  322. }
  323. return finlen;
  324. }
  325. function orient3dadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, permanent) {
  326. let finlen;
  327. let adxtail, bdxtail, cdxtail;
  328. let adytail, bdytail, cdytail;
  329. let adztail, bdztail, cdztail;
  330. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  331. const adx = ax - dx;
  332. const bdx = bx - dx;
  333. const cdx = cx - dx;
  334. const ady = ay - dy;
  335. const bdy = by - dy;
  336. const cdy = cy - dy;
  337. const adz = az - dz;
  338. const bdz = bz - dz;
  339. const cdz = cz - dz;
  340. s1 = bdx * cdy;
  341. c = splitter * bdx;
  342. ahi = c - (c - bdx);
  343. alo = bdx - ahi;
  344. c = splitter * cdy;
  345. bhi = c - (c - cdy);
  346. blo = cdy - bhi;
  347. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  348. t1 = cdx * bdy;
  349. c = splitter * cdx;
  350. ahi = c - (c - cdx);
  351. alo = cdx - ahi;
  352. c = splitter * bdy;
  353. bhi = c - (c - bdy);
  354. blo = bdy - bhi;
  355. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  356. _i = s0 - t0;
  357. bvirt = s0 - _i;
  358. bc[0] = s0 - (_i + bvirt) + (bvirt - t0);
  359. _j = s1 + _i;
  360. bvirt = _j - s1;
  361. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  362. _i = _0 - t1;
  363. bvirt = _0 - _i;
  364. bc[1] = _0 - (_i + bvirt) + (bvirt - t1);
  365. u3 = _j + _i;
  366. bvirt = u3 - _j;
  367. bc[2] = _j - (u3 - bvirt) + (_i - bvirt);
  368. bc[3] = u3;
  369. s1 = cdx * ady;
  370. c = splitter * cdx;
  371. ahi = c - (c - cdx);
  372. alo = cdx - ahi;
  373. c = splitter * ady;
  374. bhi = c - (c - ady);
  375. blo = ady - bhi;
  376. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  377. t1 = adx * cdy;
  378. c = splitter * adx;
  379. ahi = c - (c - adx);
  380. alo = adx - ahi;
  381. c = splitter * cdy;
  382. bhi = c - (c - cdy);
  383. blo = cdy - bhi;
  384. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  385. _i = s0 - t0;
  386. bvirt = s0 - _i;
  387. ca[0] = s0 - (_i + bvirt) + (bvirt - t0);
  388. _j = s1 + _i;
  389. bvirt = _j - s1;
  390. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  391. _i = _0 - t1;
  392. bvirt = _0 - _i;
  393. ca[1] = _0 - (_i + bvirt) + (bvirt - t1);
  394. u3 = _j + _i;
  395. bvirt = u3 - _j;
  396. ca[2] = _j - (u3 - bvirt) + (_i - bvirt);
  397. ca[3] = u3;
  398. s1 = adx * bdy;
  399. c = splitter * adx;
  400. ahi = c - (c - adx);
  401. alo = adx - ahi;
  402. c = splitter * bdy;
  403. bhi = c - (c - bdy);
  404. blo = bdy - bhi;
  405. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  406. t1 = bdx * ady;
  407. c = splitter * bdx;
  408. ahi = c - (c - bdx);
  409. alo = bdx - ahi;
  410. c = splitter * ady;
  411. bhi = c - (c - ady);
  412. blo = ady - bhi;
  413. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  414. _i = s0 - t0;
  415. bvirt = s0 - _i;
  416. ab[0] = s0 - (_i + bvirt) + (bvirt - t0);
  417. _j = s1 + _i;
  418. bvirt = _j - s1;
  419. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  420. _i = _0 - t1;
  421. bvirt = _0 - _i;
  422. ab[1] = _0 - (_i + bvirt) + (bvirt - t1);
  423. u3 = _j + _i;
  424. bvirt = u3 - _j;
  425. ab[2] = _j - (u3 - bvirt) + (_i - bvirt);
  426. ab[3] = u3;
  427. finlen = sum(
  428. sum(
  429. scale(4, bc, adz, _8), _8,
  430. scale(4, ca, bdz, _8b), _8b, _16), _16,
  431. scale(4, ab, cdz, _8), _8, fin);
  432. let det = estimate(finlen, fin);
  433. let errbound = o3derrboundB * permanent;
  434. if (det >= errbound || -det >= errbound) {
  435. return det;
  436. }
  437. bvirt = ax - adx;
  438. adxtail = ax - (adx + bvirt) + (bvirt - dx);
  439. bvirt = bx - bdx;
  440. bdxtail = bx - (bdx + bvirt) + (bvirt - dx);
  441. bvirt = cx - cdx;
  442. cdxtail = cx - (cdx + bvirt) + (bvirt - dx);
  443. bvirt = ay - ady;
  444. adytail = ay - (ady + bvirt) + (bvirt - dy);
  445. bvirt = by - bdy;
  446. bdytail = by - (bdy + bvirt) + (bvirt - dy);
  447. bvirt = cy - cdy;
  448. cdytail = cy - (cdy + bvirt) + (bvirt - dy);
  449. bvirt = az - adz;
  450. adztail = az - (adz + bvirt) + (bvirt - dz);
  451. bvirt = bz - bdz;
  452. bdztail = bz - (bdz + bvirt) + (bvirt - dz);
  453. bvirt = cz - cdz;
  454. cdztail = cz - (cdz + bvirt) + (bvirt - dz);
  455. if (adxtail === 0 && bdxtail === 0 && cdxtail === 0 &&
  456. adytail === 0 && bdytail === 0 && cdytail === 0 &&
  457. adztail === 0 && bdztail === 0 && cdztail === 0) {
  458. return det;
  459. }
  460. errbound = o3derrboundC * permanent + resulterrbound * Math.abs(det);
  461. det +=
  462. adz * (bdx * cdytail + cdy * bdxtail - (bdy * cdxtail + cdx * bdytail)) + adztail * (bdx * cdy - bdy * cdx) +
  463. bdz * (cdx * adytail + ady * cdxtail - (cdy * adxtail + adx * cdytail)) + bdztail * (cdx * ady - cdy * adx) +
  464. cdz * (adx * bdytail + bdy * adxtail - (ady * bdxtail + bdx * adytail)) + cdztail * (adx * bdy - ady * bdx);
  465. if (det >= errbound || -det >= errbound) {
  466. return det;
  467. }
  468. const at_len = tailinit(adxtail, adytail, bdx, bdy, cdx, cdy, at_b, at_c);
  469. const bt_len = tailinit(bdxtail, bdytail, cdx, cdy, adx, ady, bt_c, bt_a);
  470. const ct_len = tailinit(cdxtail, cdytail, adx, ady, bdx, bdy, ct_a, ct_b);
  471. const bctlen = sum(bt_len, bt_c, ct_len, ct_b, bct);
  472. finlen = finadd(finlen, scale(bctlen, bct, adz, _16), _16);
  473. const catlen = sum(ct_len, ct_a, at_len, at_c, cat);
  474. finlen = finadd(finlen, scale(catlen, cat, bdz, _16), _16);
  475. const abtlen = sum(at_len, at_b, bt_len, bt_a, abt);
  476. finlen = finadd(finlen, scale(abtlen, abt, cdz, _16), _16);
  477. if (adztail !== 0) {
  478. finlen = finadd(finlen, scale(4, bc, adztail, _12), _12);
  479. finlen = finadd(finlen, scale(bctlen, bct, adztail, _16), _16);
  480. }
  481. if (bdztail !== 0) {
  482. finlen = finadd(finlen, scale(4, ca, bdztail, _12), _12);
  483. finlen = finadd(finlen, scale(catlen, cat, bdztail, _16), _16);
  484. }
  485. if (cdztail !== 0) {
  486. finlen = finadd(finlen, scale(4, ab, cdztail, _12), _12);
  487. finlen = finadd(finlen, scale(abtlen, abt, cdztail, _16), _16);
  488. }
  489. if (adxtail !== 0) {
  490. if (bdytail !== 0) {
  491. finlen = tailadd(finlen, adxtail, bdytail, cdz, cdztail);
  492. }
  493. if (cdytail !== 0) {
  494. finlen = tailadd(finlen, -adxtail, cdytail, bdz, bdztail);
  495. }
  496. }
  497. if (bdxtail !== 0) {
  498. if (cdytail !== 0) {
  499. finlen = tailadd(finlen, bdxtail, cdytail, adz, adztail);
  500. }
  501. if (adytail !== 0) {
  502. finlen = tailadd(finlen, -bdxtail, adytail, cdz, cdztail);
  503. }
  504. }
  505. if (cdxtail !== 0) {
  506. if (adytail !== 0) {
  507. finlen = tailadd(finlen, cdxtail, adytail, bdz, bdztail);
  508. }
  509. if (bdytail !== 0) {
  510. finlen = tailadd(finlen, -cdxtail, bdytail, adz, adztail);
  511. }
  512. }
  513. return fin[finlen - 1];
  514. }
  515. function orient3d(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz) {
  516. const adx = ax - dx;
  517. const bdx = bx - dx;
  518. const cdx = cx - dx;
  519. const ady = ay - dy;
  520. const bdy = by - dy;
  521. const cdy = cy - dy;
  522. const adz = az - dz;
  523. const bdz = bz - dz;
  524. const cdz = cz - dz;
  525. const bdxcdy = bdx * cdy;
  526. const cdxbdy = cdx * bdy;
  527. const cdxady = cdx * ady;
  528. const adxcdy = adx * cdy;
  529. const adxbdy = adx * bdy;
  530. const bdxady = bdx * ady;
  531. const det =
  532. adz * (bdxcdy - cdxbdy) +
  533. bdz * (cdxady - adxcdy) +
  534. cdz * (adxbdy - bdxady);
  535. const permanent =
  536. (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * Math.abs(adz) +
  537. (Math.abs(cdxady) + Math.abs(adxcdy)) * Math.abs(bdz) +
  538. (Math.abs(adxbdy) + Math.abs(bdxady)) * Math.abs(cdz);
  539. const errbound = o3derrboundA * permanent;
  540. if (det > errbound || -det > errbound) {
  541. return det;
  542. }
  543. return orient3dadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, permanent);
  544. }
  545. function orient3dfast(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz) {
  546. const adx = ax - dx;
  547. const bdx = bx - dx;
  548. const cdx = cx - dx;
  549. const ady = ay - dy;
  550. const bdy = by - dy;
  551. const cdy = cy - dy;
  552. const adz = az - dz;
  553. const bdz = bz - dz;
  554. const cdz = cz - dz;
  555. return adx * (bdy * cdz - bdz * cdy) +
  556. bdx * (cdy * adz - cdz * ady) +
  557. cdx * (ady * bdz - adz * bdy);
  558. }
  559. exports.orient3d = orient3d;
  560. exports.orient3dfast = orient3dfast;
  561. }));