Node-Red configuration
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

insphere.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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. function sum_three(alen, a, blen, b, clen, c, tmp, out) {
  82. return sum(sum(alen, a, blen, b, tmp), tmp, clen, c, out);
  83. }
  84. // scale_expansion_zeroelim routine from oritinal code
  85. function scale(elen, e, b, h) {
  86. let Q, sum, hh, product1, product0;
  87. let bvirt, c, ahi, alo, bhi, blo;
  88. c = splitter * b;
  89. bhi = c - (c - b);
  90. blo = b - bhi;
  91. let enow = e[0];
  92. Q = enow * b;
  93. c = splitter * enow;
  94. ahi = c - (c - enow);
  95. alo = enow - ahi;
  96. hh = alo * blo - (Q - ahi * bhi - alo * bhi - ahi * blo);
  97. let hindex = 0;
  98. if (hh !== 0) {
  99. h[hindex++] = hh;
  100. }
  101. for (let i = 1; i < elen; i++) {
  102. enow = e[i];
  103. product1 = enow * b;
  104. c = splitter * enow;
  105. ahi = c - (c - enow);
  106. alo = enow - ahi;
  107. product0 = alo * blo - (product1 - ahi * bhi - alo * bhi - ahi * blo);
  108. sum = Q + product0;
  109. bvirt = sum - Q;
  110. hh = Q - (sum - bvirt) + (product0 - bvirt);
  111. if (hh !== 0) {
  112. h[hindex++] = hh;
  113. }
  114. Q = product1 + sum;
  115. hh = sum - (Q - product1);
  116. if (hh !== 0) {
  117. h[hindex++] = hh;
  118. }
  119. }
  120. if (Q !== 0 || hindex === 0) {
  121. h[hindex++] = Q;
  122. }
  123. return hindex;
  124. }
  125. function negate(elen, e) {
  126. for (let i = 0; i < elen; i++) e[i] = -e[i];
  127. return elen;
  128. }
  129. function estimate(elen, e) {
  130. let Q = e[0];
  131. for (let i = 1; i < elen; i++) Q += e[i];
  132. return Q;
  133. }
  134. function vec(n) {
  135. return new Float64Array(n);
  136. }
  137. const isperrboundA = (16 + 224 * epsilon) * epsilon;
  138. const isperrboundB = (5 + 72 * epsilon) * epsilon;
  139. const isperrboundC = (71 + 1408 * epsilon) * epsilon * epsilon;
  140. const ab = vec(4);
  141. const bc = vec(4);
  142. const cd = vec(4);
  143. const de = vec(4);
  144. const ea = vec(4);
  145. const ac = vec(4);
  146. const bd = vec(4);
  147. const ce = vec(4);
  148. const da = vec(4);
  149. const eb = vec(4);
  150. const abc = vec(24);
  151. const bcd = vec(24);
  152. const cde = vec(24);
  153. const dea = vec(24);
  154. const eab = vec(24);
  155. const abd = vec(24);
  156. const bce = vec(24);
  157. const cda = vec(24);
  158. const deb = vec(24);
  159. const eac = vec(24);
  160. const adet = vec(1152);
  161. const bdet = vec(1152);
  162. const cdet = vec(1152);
  163. const ddet = vec(1152);
  164. const edet = vec(1152);
  165. const abdet = vec(2304);
  166. const cddet = vec(2304);
  167. const cdedet = vec(3456);
  168. const deter = vec(5760);
  169. const _8 = vec(8);
  170. const _8b = vec(8);
  171. const _8c = vec(8);
  172. const _16 = vec(16);
  173. const _24 = vec(24);
  174. const _48 = vec(48);
  175. const _48b = vec(48);
  176. const _96 = vec(96);
  177. const _192 = vec(192);
  178. const _384x = vec(384);
  179. const _384y = vec(384);
  180. const _384z = vec(384);
  181. const _768 = vec(768);
  182. function sum_three_scale(a, b, c, az, bz, cz, out) {
  183. return sum_three(
  184. scale(4, a, az, _8), _8,
  185. scale(4, b, bz, _8b), _8b,
  186. scale(4, c, cz, _8c), _8c, _16, out);
  187. }
  188. function liftexact(alen, a, blen, b, clen, c, dlen, d, x, y, z, out) {
  189. const len = sum(
  190. sum(alen, a, blen, b, _48), _48,
  191. negate(sum(clen, c, dlen, d, _48b), _48b), _48b, _96);
  192. return sum_three(
  193. scale(scale(len, _96, x, _192), _192, x, _384x), _384x,
  194. scale(scale(len, _96, y, _192), _192, y, _384y), _384y,
  195. scale(scale(len, _96, z, _192), _192, z, _384z), _384z, _768, out);
  196. }
  197. function insphereexact(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez) {
  198. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  199. s1 = ax * by;
  200. c = splitter * ax;
  201. ahi = c - (c - ax);
  202. alo = ax - ahi;
  203. c = splitter * by;
  204. bhi = c - (c - by);
  205. blo = by - bhi;
  206. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  207. t1 = bx * ay;
  208. c = splitter * bx;
  209. ahi = c - (c - bx);
  210. alo = bx - ahi;
  211. c = splitter * ay;
  212. bhi = c - (c - ay);
  213. blo = ay - bhi;
  214. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  215. _i = s0 - t0;
  216. bvirt = s0 - _i;
  217. ab[0] = s0 - (_i + bvirt) + (bvirt - t0);
  218. _j = s1 + _i;
  219. bvirt = _j - s1;
  220. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  221. _i = _0 - t1;
  222. bvirt = _0 - _i;
  223. ab[1] = _0 - (_i + bvirt) + (bvirt - t1);
  224. u3 = _j + _i;
  225. bvirt = u3 - _j;
  226. ab[2] = _j - (u3 - bvirt) + (_i - bvirt);
  227. ab[3] = u3;
  228. s1 = bx * cy;
  229. c = splitter * bx;
  230. ahi = c - (c - bx);
  231. alo = bx - ahi;
  232. c = splitter * cy;
  233. bhi = c - (c - cy);
  234. blo = cy - bhi;
  235. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  236. t1 = cx * by;
  237. c = splitter * cx;
  238. ahi = c - (c - cx);
  239. alo = cx - ahi;
  240. c = splitter * by;
  241. bhi = c - (c - by);
  242. blo = by - bhi;
  243. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  244. _i = s0 - t0;
  245. bvirt = s0 - _i;
  246. bc[0] = s0 - (_i + bvirt) + (bvirt - t0);
  247. _j = s1 + _i;
  248. bvirt = _j - s1;
  249. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  250. _i = _0 - t1;
  251. bvirt = _0 - _i;
  252. bc[1] = _0 - (_i + bvirt) + (bvirt - t1);
  253. u3 = _j + _i;
  254. bvirt = u3 - _j;
  255. bc[2] = _j - (u3 - bvirt) + (_i - bvirt);
  256. bc[3] = u3;
  257. s1 = cx * dy;
  258. c = splitter * cx;
  259. ahi = c - (c - cx);
  260. alo = cx - ahi;
  261. c = splitter * dy;
  262. bhi = c - (c - dy);
  263. blo = dy - bhi;
  264. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  265. t1 = dx * cy;
  266. c = splitter * dx;
  267. ahi = c - (c - dx);
  268. alo = dx - ahi;
  269. c = splitter * cy;
  270. bhi = c - (c - cy);
  271. blo = cy - bhi;
  272. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  273. _i = s0 - t0;
  274. bvirt = s0 - _i;
  275. cd[0] = s0 - (_i + bvirt) + (bvirt - t0);
  276. _j = s1 + _i;
  277. bvirt = _j - s1;
  278. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  279. _i = _0 - t1;
  280. bvirt = _0 - _i;
  281. cd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  282. u3 = _j + _i;
  283. bvirt = u3 - _j;
  284. cd[2] = _j - (u3 - bvirt) + (_i - bvirt);
  285. cd[3] = u3;
  286. s1 = dx * ey;
  287. c = splitter * dx;
  288. ahi = c - (c - dx);
  289. alo = dx - ahi;
  290. c = splitter * ey;
  291. bhi = c - (c - ey);
  292. blo = ey - bhi;
  293. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  294. t1 = ex * dy;
  295. c = splitter * ex;
  296. ahi = c - (c - ex);
  297. alo = ex - ahi;
  298. c = splitter * dy;
  299. bhi = c - (c - dy);
  300. blo = dy - bhi;
  301. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  302. _i = s0 - t0;
  303. bvirt = s0 - _i;
  304. de[0] = s0 - (_i + bvirt) + (bvirt - t0);
  305. _j = s1 + _i;
  306. bvirt = _j - s1;
  307. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  308. _i = _0 - t1;
  309. bvirt = _0 - _i;
  310. de[1] = _0 - (_i + bvirt) + (bvirt - t1);
  311. u3 = _j + _i;
  312. bvirt = u3 - _j;
  313. de[2] = _j - (u3 - bvirt) + (_i - bvirt);
  314. de[3] = u3;
  315. s1 = ex * ay;
  316. c = splitter * ex;
  317. ahi = c - (c - ex);
  318. alo = ex - ahi;
  319. c = splitter * ay;
  320. bhi = c - (c - ay);
  321. blo = ay - bhi;
  322. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  323. t1 = ax * ey;
  324. c = splitter * ax;
  325. ahi = c - (c - ax);
  326. alo = ax - ahi;
  327. c = splitter * ey;
  328. bhi = c - (c - ey);
  329. blo = ey - bhi;
  330. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  331. _i = s0 - t0;
  332. bvirt = s0 - _i;
  333. ea[0] = s0 - (_i + bvirt) + (bvirt - t0);
  334. _j = s1 + _i;
  335. bvirt = _j - s1;
  336. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  337. _i = _0 - t1;
  338. bvirt = _0 - _i;
  339. ea[1] = _0 - (_i + bvirt) + (bvirt - t1);
  340. u3 = _j + _i;
  341. bvirt = u3 - _j;
  342. ea[2] = _j - (u3 - bvirt) + (_i - bvirt);
  343. ea[3] = u3;
  344. s1 = ax * cy;
  345. c = splitter * ax;
  346. ahi = c - (c - ax);
  347. alo = ax - ahi;
  348. c = splitter * cy;
  349. bhi = c - (c - cy);
  350. blo = cy - bhi;
  351. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  352. t1 = cx * ay;
  353. c = splitter * cx;
  354. ahi = c - (c - cx);
  355. alo = cx - ahi;
  356. c = splitter * ay;
  357. bhi = c - (c - ay);
  358. blo = ay - bhi;
  359. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  360. _i = s0 - t0;
  361. bvirt = s0 - _i;
  362. ac[0] = s0 - (_i + bvirt) + (bvirt - t0);
  363. _j = s1 + _i;
  364. bvirt = _j - s1;
  365. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  366. _i = _0 - t1;
  367. bvirt = _0 - _i;
  368. ac[1] = _0 - (_i + bvirt) + (bvirt - t1);
  369. u3 = _j + _i;
  370. bvirt = u3 - _j;
  371. ac[2] = _j - (u3 - bvirt) + (_i - bvirt);
  372. ac[3] = u3;
  373. s1 = bx * dy;
  374. c = splitter * bx;
  375. ahi = c - (c - bx);
  376. alo = bx - ahi;
  377. c = splitter * dy;
  378. bhi = c - (c - dy);
  379. blo = dy - bhi;
  380. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  381. t1 = dx * by;
  382. c = splitter * dx;
  383. ahi = c - (c - dx);
  384. alo = dx - ahi;
  385. c = splitter * by;
  386. bhi = c - (c - by);
  387. blo = by - bhi;
  388. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  389. _i = s0 - t0;
  390. bvirt = s0 - _i;
  391. bd[0] = s0 - (_i + bvirt) + (bvirt - t0);
  392. _j = s1 + _i;
  393. bvirt = _j - s1;
  394. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  395. _i = _0 - t1;
  396. bvirt = _0 - _i;
  397. bd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  398. u3 = _j + _i;
  399. bvirt = u3 - _j;
  400. bd[2] = _j - (u3 - bvirt) + (_i - bvirt);
  401. bd[3] = u3;
  402. s1 = cx * ey;
  403. c = splitter * cx;
  404. ahi = c - (c - cx);
  405. alo = cx - ahi;
  406. c = splitter * ey;
  407. bhi = c - (c - ey);
  408. blo = ey - bhi;
  409. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  410. t1 = ex * cy;
  411. c = splitter * ex;
  412. ahi = c - (c - ex);
  413. alo = ex - ahi;
  414. c = splitter * cy;
  415. bhi = c - (c - cy);
  416. blo = cy - bhi;
  417. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  418. _i = s0 - t0;
  419. bvirt = s0 - _i;
  420. ce[0] = s0 - (_i + bvirt) + (bvirt - t0);
  421. _j = s1 + _i;
  422. bvirt = _j - s1;
  423. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  424. _i = _0 - t1;
  425. bvirt = _0 - _i;
  426. ce[1] = _0 - (_i + bvirt) + (bvirt - t1);
  427. u3 = _j + _i;
  428. bvirt = u3 - _j;
  429. ce[2] = _j - (u3 - bvirt) + (_i - bvirt);
  430. ce[3] = u3;
  431. s1 = dx * ay;
  432. c = splitter * dx;
  433. ahi = c - (c - dx);
  434. alo = dx - ahi;
  435. c = splitter * ay;
  436. bhi = c - (c - ay);
  437. blo = ay - bhi;
  438. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  439. t1 = ax * dy;
  440. c = splitter * ax;
  441. ahi = c - (c - ax);
  442. alo = ax - ahi;
  443. c = splitter * dy;
  444. bhi = c - (c - dy);
  445. blo = dy - bhi;
  446. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  447. _i = s0 - t0;
  448. bvirt = s0 - _i;
  449. da[0] = s0 - (_i + bvirt) + (bvirt - t0);
  450. _j = s1 + _i;
  451. bvirt = _j - s1;
  452. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  453. _i = _0 - t1;
  454. bvirt = _0 - _i;
  455. da[1] = _0 - (_i + bvirt) + (bvirt - t1);
  456. u3 = _j + _i;
  457. bvirt = u3 - _j;
  458. da[2] = _j - (u3 - bvirt) + (_i - bvirt);
  459. da[3] = u3;
  460. s1 = ex * by;
  461. c = splitter * ex;
  462. ahi = c - (c - ex);
  463. alo = ex - ahi;
  464. c = splitter * by;
  465. bhi = c - (c - by);
  466. blo = by - bhi;
  467. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  468. t1 = bx * ey;
  469. c = splitter * bx;
  470. ahi = c - (c - bx);
  471. alo = bx - ahi;
  472. c = splitter * ey;
  473. bhi = c - (c - ey);
  474. blo = ey - bhi;
  475. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  476. _i = s0 - t0;
  477. bvirt = s0 - _i;
  478. eb[0] = s0 - (_i + bvirt) + (bvirt - t0);
  479. _j = s1 + _i;
  480. bvirt = _j - s1;
  481. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  482. _i = _0 - t1;
  483. bvirt = _0 - _i;
  484. eb[1] = _0 - (_i + bvirt) + (bvirt - t1);
  485. u3 = _j + _i;
  486. bvirt = u3 - _j;
  487. eb[2] = _j - (u3 - bvirt) + (_i - bvirt);
  488. eb[3] = u3;
  489. const abclen = sum_three_scale(ab, bc, ac, cz, az, -bz, abc);
  490. const bcdlen = sum_three_scale(bc, cd, bd, dz, bz, -cz, bcd);
  491. const cdelen = sum_three_scale(cd, de, ce, ez, cz, -dz, cde);
  492. const dealen = sum_three_scale(de, ea, da, az, dz, -ez, dea);
  493. const eablen = sum_three_scale(ea, ab, eb, bz, ez, -az, eab);
  494. const abdlen = sum_three_scale(ab, bd, da, dz, az, bz, abd);
  495. const bcelen = sum_three_scale(bc, ce, eb, ez, bz, cz, bce);
  496. const cdalen = sum_three_scale(cd, da, ac, az, cz, dz, cda);
  497. const deblen = sum_three_scale(de, eb, bd, bz, dz, ez, deb);
  498. const eaclen = sum_three_scale(ea, ac, ce, cz, ez, az, eac);
  499. const deterlen = sum_three(
  500. liftexact(cdelen, cde, bcelen, bce, deblen, deb, bcdlen, bcd, ax, ay, az, adet), adet,
  501. liftexact(dealen, dea, cdalen, cda, eaclen, eac, cdelen, cde, bx, by, bz, bdet), bdet,
  502. sum_three(
  503. liftexact(eablen, eab, deblen, deb, abdlen, abd, dealen, dea, cx, cy, cz, cdet), cdet,
  504. liftexact(abclen, abc, eaclen, eac, bcelen, bce, eablen, eab, dx, dy, dz, ddet), ddet,
  505. liftexact(bcdlen, bcd, abdlen, abd, cdalen, cda, abclen, abc, ex, ey, ez, edet), edet, cddet, cdedet), cdedet, abdet, deter);
  506. return deter[deterlen - 1];
  507. }
  508. const xdet = vec(96);
  509. const ydet = vec(96);
  510. const zdet = vec(96);
  511. const fin = vec(1152);
  512. function liftadapt(a, b, c, az, bz, cz, x, y, z, out) {
  513. const len = sum_three_scale(a, b, c, az, bz, cz, _24);
  514. return sum_three(
  515. scale(scale(len, _24, x, _48), _48, x, xdet), xdet,
  516. scale(scale(len, _24, y, _48), _48, y, ydet), ydet,
  517. scale(scale(len, _24, z, _48), _48, z, zdet), zdet, _192, out);
  518. }
  519. function insphereadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez, permanent) {
  520. let ab3, bc3, cd3, da3, ac3, bd3;
  521. let aextail, bextail, cextail, dextail;
  522. let aeytail, beytail, ceytail, deytail;
  523. let aeztail, beztail, ceztail, deztail;
  524. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0;
  525. const aex = ax - ex;
  526. const bex = bx - ex;
  527. const cex = cx - ex;
  528. const dex = dx - ex;
  529. const aey = ay - ey;
  530. const bey = by - ey;
  531. const cey = cy - ey;
  532. const dey = dy - ey;
  533. const aez = az - ez;
  534. const bez = bz - ez;
  535. const cez = cz - ez;
  536. const dez = dz - ez;
  537. s1 = aex * bey;
  538. c = splitter * aex;
  539. ahi = c - (c - aex);
  540. alo = aex - ahi;
  541. c = splitter * bey;
  542. bhi = c - (c - bey);
  543. blo = bey - bhi;
  544. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  545. t1 = bex * aey;
  546. c = splitter * bex;
  547. ahi = c - (c - bex);
  548. alo = bex - ahi;
  549. c = splitter * aey;
  550. bhi = c - (c - aey);
  551. blo = aey - bhi;
  552. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  553. _i = s0 - t0;
  554. bvirt = s0 - _i;
  555. ab[0] = s0 - (_i + bvirt) + (bvirt - t0);
  556. _j = s1 + _i;
  557. bvirt = _j - s1;
  558. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  559. _i = _0 - t1;
  560. bvirt = _0 - _i;
  561. ab[1] = _0 - (_i + bvirt) + (bvirt - t1);
  562. ab3 = _j + _i;
  563. bvirt = ab3 - _j;
  564. ab[2] = _j - (ab3 - bvirt) + (_i - bvirt);
  565. ab[3] = ab3;
  566. s1 = bex * cey;
  567. c = splitter * bex;
  568. ahi = c - (c - bex);
  569. alo = bex - ahi;
  570. c = splitter * cey;
  571. bhi = c - (c - cey);
  572. blo = cey - bhi;
  573. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  574. t1 = cex * bey;
  575. c = splitter * cex;
  576. ahi = c - (c - cex);
  577. alo = cex - ahi;
  578. c = splitter * bey;
  579. bhi = c - (c - bey);
  580. blo = bey - bhi;
  581. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  582. _i = s0 - t0;
  583. bvirt = s0 - _i;
  584. bc[0] = s0 - (_i + bvirt) + (bvirt - t0);
  585. _j = s1 + _i;
  586. bvirt = _j - s1;
  587. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  588. _i = _0 - t1;
  589. bvirt = _0 - _i;
  590. bc[1] = _0 - (_i + bvirt) + (bvirt - t1);
  591. bc3 = _j + _i;
  592. bvirt = bc3 - _j;
  593. bc[2] = _j - (bc3 - bvirt) + (_i - bvirt);
  594. bc[3] = bc3;
  595. s1 = cex * dey;
  596. c = splitter * cex;
  597. ahi = c - (c - cex);
  598. alo = cex - ahi;
  599. c = splitter * dey;
  600. bhi = c - (c - dey);
  601. blo = dey - bhi;
  602. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  603. t1 = dex * cey;
  604. c = splitter * dex;
  605. ahi = c - (c - dex);
  606. alo = dex - ahi;
  607. c = splitter * cey;
  608. bhi = c - (c - cey);
  609. blo = cey - bhi;
  610. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  611. _i = s0 - t0;
  612. bvirt = s0 - _i;
  613. cd[0] = s0 - (_i + bvirt) + (bvirt - t0);
  614. _j = s1 + _i;
  615. bvirt = _j - s1;
  616. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  617. _i = _0 - t1;
  618. bvirt = _0 - _i;
  619. cd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  620. cd3 = _j + _i;
  621. bvirt = cd3 - _j;
  622. cd[2] = _j - (cd3 - bvirt) + (_i - bvirt);
  623. cd[3] = cd3;
  624. s1 = dex * aey;
  625. c = splitter * dex;
  626. ahi = c - (c - dex);
  627. alo = dex - ahi;
  628. c = splitter * aey;
  629. bhi = c - (c - aey);
  630. blo = aey - bhi;
  631. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  632. t1 = aex * dey;
  633. c = splitter * aex;
  634. ahi = c - (c - aex);
  635. alo = aex - ahi;
  636. c = splitter * dey;
  637. bhi = c - (c - dey);
  638. blo = dey - bhi;
  639. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  640. _i = s0 - t0;
  641. bvirt = s0 - _i;
  642. da[0] = s0 - (_i + bvirt) + (bvirt - t0);
  643. _j = s1 + _i;
  644. bvirt = _j - s1;
  645. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  646. _i = _0 - t1;
  647. bvirt = _0 - _i;
  648. da[1] = _0 - (_i + bvirt) + (bvirt - t1);
  649. da3 = _j + _i;
  650. bvirt = da3 - _j;
  651. da[2] = _j - (da3 - bvirt) + (_i - bvirt);
  652. da[3] = da3;
  653. s1 = aex * cey;
  654. c = splitter * aex;
  655. ahi = c - (c - aex);
  656. alo = aex - ahi;
  657. c = splitter * cey;
  658. bhi = c - (c - cey);
  659. blo = cey - bhi;
  660. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  661. t1 = cex * aey;
  662. c = splitter * cex;
  663. ahi = c - (c - cex);
  664. alo = cex - ahi;
  665. c = splitter * aey;
  666. bhi = c - (c - aey);
  667. blo = aey - bhi;
  668. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  669. _i = s0 - t0;
  670. bvirt = s0 - _i;
  671. ac[0] = s0 - (_i + bvirt) + (bvirt - t0);
  672. _j = s1 + _i;
  673. bvirt = _j - s1;
  674. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  675. _i = _0 - t1;
  676. bvirt = _0 - _i;
  677. ac[1] = _0 - (_i + bvirt) + (bvirt - t1);
  678. ac3 = _j + _i;
  679. bvirt = ac3 - _j;
  680. ac[2] = _j - (ac3 - bvirt) + (_i - bvirt);
  681. ac[3] = ac3;
  682. s1 = bex * dey;
  683. c = splitter * bex;
  684. ahi = c - (c - bex);
  685. alo = bex - ahi;
  686. c = splitter * dey;
  687. bhi = c - (c - dey);
  688. blo = dey - bhi;
  689. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  690. t1 = dex * bey;
  691. c = splitter * dex;
  692. ahi = c - (c - dex);
  693. alo = dex - ahi;
  694. c = splitter * bey;
  695. bhi = c - (c - bey);
  696. blo = bey - bhi;
  697. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  698. _i = s0 - t0;
  699. bvirt = s0 - _i;
  700. bd[0] = s0 - (_i + bvirt) + (bvirt - t0);
  701. _j = s1 + _i;
  702. bvirt = _j - s1;
  703. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  704. _i = _0 - t1;
  705. bvirt = _0 - _i;
  706. bd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  707. bd3 = _j + _i;
  708. bvirt = bd3 - _j;
  709. bd[2] = _j - (bd3 - bvirt) + (_i - bvirt);
  710. bd[3] = bd3;
  711. const finlen = sum(
  712. sum(
  713. negate(liftadapt(bc, cd, bd, dez, bez, -cez, aex, aey, aez, adet), adet), adet,
  714. liftadapt(cd, da, ac, aez, cez, dez, bex, bey, bez, bdet), bdet, abdet), abdet,
  715. sum(
  716. negate(liftadapt(da, ab, bd, bez, dez, aez, cex, cey, cez, cdet), cdet), cdet,
  717. liftadapt(ab, bc, ac, cez, aez, -bez, dex, dey, dez, ddet), ddet, cddet), cddet, fin);
  718. let det = estimate(finlen, fin);
  719. let errbound = isperrboundB * permanent;
  720. if (det >= errbound || -det >= errbound) {
  721. return det;
  722. }
  723. bvirt = ax - aex;
  724. aextail = ax - (aex + bvirt) + (bvirt - ex);
  725. bvirt = ay - aey;
  726. aeytail = ay - (aey + bvirt) + (bvirt - ey);
  727. bvirt = az - aez;
  728. aeztail = az - (aez + bvirt) + (bvirt - ez);
  729. bvirt = bx - bex;
  730. bextail = bx - (bex + bvirt) + (bvirt - ex);
  731. bvirt = by - bey;
  732. beytail = by - (bey + bvirt) + (bvirt - ey);
  733. bvirt = bz - bez;
  734. beztail = bz - (bez + bvirt) + (bvirt - ez);
  735. bvirt = cx - cex;
  736. cextail = cx - (cex + bvirt) + (bvirt - ex);
  737. bvirt = cy - cey;
  738. ceytail = cy - (cey + bvirt) + (bvirt - ey);
  739. bvirt = cz - cez;
  740. ceztail = cz - (cez + bvirt) + (bvirt - ez);
  741. bvirt = dx - dex;
  742. dextail = dx - (dex + bvirt) + (bvirt - ex);
  743. bvirt = dy - dey;
  744. deytail = dy - (dey + bvirt) + (bvirt - ey);
  745. bvirt = dz - dez;
  746. deztail = dz - (dez + bvirt) + (bvirt - ez);
  747. if (aextail === 0 && aeytail === 0 && aeztail === 0 &&
  748. bextail === 0 && beytail === 0 && beztail === 0 &&
  749. cextail === 0 && ceytail === 0 && ceztail === 0 &&
  750. dextail === 0 && deytail === 0 && deztail === 0) {
  751. return det;
  752. }
  753. errbound = isperrboundC * permanent + resulterrbound * Math.abs(det);
  754. const abeps = (aex * beytail + bey * aextail) - (aey * bextail + bex * aeytail);
  755. const bceps = (bex * ceytail + cey * bextail) - (bey * cextail + cex * beytail);
  756. const cdeps = (cex * deytail + dey * cextail) - (cey * dextail + dex * ceytail);
  757. const daeps = (dex * aeytail + aey * dextail) - (dey * aextail + aex * deytail);
  758. const aceps = (aex * ceytail + cey * aextail) - (aey * cextail + cex * aeytail);
  759. const bdeps = (bex * deytail + dey * bextail) - (bey * dextail + dex * beytail);
  760. det +=
  761. (((bex * bex + bey * bey + bez * bez) * ((cez * daeps + dez * aceps + aez * cdeps) +
  762. (ceztail * da3 + deztail * ac3 + aeztail * cd3)) + (dex * dex + dey * dey + dez * dez) *
  763. ((aez * bceps - bez * aceps + cez * abeps) + (aeztail * bc3 - beztail * ac3 + ceztail * ab3))) -
  764. ((aex * aex + aey * aey + aez * aez) * ((bez * cdeps - cez * bdeps + dez * bceps) +
  765. (beztail * cd3 - ceztail * bd3 + deztail * bc3)) + (cex * cex + cey * cey + cez * cez) *
  766. ((dez * abeps + aez * bdeps + bez * daeps) + (deztail * ab3 + aeztail * bd3 + beztail * da3)))) +
  767. 2 * (((bex * bextail + bey * beytail + bez * beztail) * (cez * da3 + dez * ac3 + aez * cd3) +
  768. (dex * dextail + dey * deytail + dez * deztail) * (aez * bc3 - bez * ac3 + cez * ab3)) -
  769. ((aex * aextail + aey * aeytail + aez * aeztail) * (bez * cd3 - cez * bd3 + dez * bc3) +
  770. (cex * cextail + cey * ceytail + cez * ceztail) * (dez * ab3 + aez * bd3 + bez * da3)));
  771. if (det >= errbound || -det >= errbound) {
  772. return det;
  773. }
  774. return insphereexact(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez);
  775. }
  776. function insphere(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez) {
  777. const aex = ax - ex;
  778. const bex = bx - ex;
  779. const cex = cx - ex;
  780. const dex = dx - ex;
  781. const aey = ay - ey;
  782. const bey = by - ey;
  783. const cey = cy - ey;
  784. const dey = dy - ey;
  785. const aez = az - ez;
  786. const bez = bz - ez;
  787. const cez = cz - ez;
  788. const dez = dz - ez;
  789. const aexbey = aex * bey;
  790. const bexaey = bex * aey;
  791. const ab = aexbey - bexaey;
  792. const bexcey = bex * cey;
  793. const cexbey = cex * bey;
  794. const bc = bexcey - cexbey;
  795. const cexdey = cex * dey;
  796. const dexcey = dex * cey;
  797. const cd = cexdey - dexcey;
  798. const dexaey = dex * aey;
  799. const aexdey = aex * dey;
  800. const da = dexaey - aexdey;
  801. const aexcey = aex * cey;
  802. const cexaey = cex * aey;
  803. const ac = aexcey - cexaey;
  804. const bexdey = bex * dey;
  805. const dexbey = dex * bey;
  806. const bd = bexdey - dexbey;
  807. const alift = aex * aex + aey * aey + aez * aez;
  808. const blift = bex * bex + bey * bey + bez * bez;
  809. const clift = cex * cex + cey * cey + cez * cez;
  810. const dlift = dex * dex + dey * dey + dez * dez;
  811. const det =
  812. (clift * (dez * ab + aez * bd + bez * da) - dlift * (aez * bc - bez * ac + cez * ab)) +
  813. (alift * (bez * cd - cez * bd + dez * bc) - blift * (cez * da + dez * ac + aez * cd));
  814. const aezplus = Math.abs(aez);
  815. const bezplus = Math.abs(bez);
  816. const cezplus = Math.abs(cez);
  817. const dezplus = Math.abs(dez);
  818. const aexbeyplus = Math.abs(aexbey) + Math.abs(bexaey);
  819. const bexceyplus = Math.abs(bexcey) + Math.abs(cexbey);
  820. const cexdeyplus = Math.abs(cexdey) + Math.abs(dexcey);
  821. const dexaeyplus = Math.abs(dexaey) + Math.abs(aexdey);
  822. const aexceyplus = Math.abs(aexcey) + Math.abs(cexaey);
  823. const bexdeyplus = Math.abs(bexdey) + Math.abs(dexbey);
  824. const permanent =
  825. (cexdeyplus * bezplus + bexdeyplus * cezplus + bexceyplus * dezplus) * alift +
  826. (dexaeyplus * cezplus + aexceyplus * dezplus + cexdeyplus * aezplus) * blift +
  827. (aexbeyplus * dezplus + bexdeyplus * aezplus + dexaeyplus * bezplus) * clift +
  828. (bexceyplus * aezplus + aexceyplus * bezplus + aexbeyplus * cezplus) * dlift;
  829. const errbound = isperrboundA * permanent;
  830. if (det > errbound || -det > errbound) {
  831. return det;
  832. }
  833. return -insphereadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez, permanent);
  834. }
  835. function inspherefast(pax, pay, paz, pbx, pby, pbz, pcx, pcy, pcz, pdx, pdy, pdz, pex, pey, pez) {
  836. const aex = pax - pex;
  837. const bex = pbx - pex;
  838. const cex = pcx - pex;
  839. const dex = pdx - pex;
  840. const aey = pay - pey;
  841. const bey = pby - pey;
  842. const cey = pcy - pey;
  843. const dey = pdy - pey;
  844. const aez = paz - pez;
  845. const bez = pbz - pez;
  846. const cez = pcz - pez;
  847. const dez = pdz - pez;
  848. const ab = aex * bey - bex * aey;
  849. const bc = bex * cey - cex * bey;
  850. const cd = cex * dey - dex * cey;
  851. const da = dex * aey - aex * dey;
  852. const ac = aex * cey - cex * aey;
  853. const bd = bex * dey - dex * bey;
  854. const abc = aez * bc - bez * ac + cez * ab;
  855. const bcd = bez * cd - cez * bd + dez * bc;
  856. const cda = cez * da + dez * ac + aez * cd;
  857. const dab = dez * ab + aez * bd + bez * da;
  858. const alift = aex * aex + aey * aey + aez * aez;
  859. const blift = bex * bex + bey * bey + bez * bez;
  860. const clift = cex * cex + cey * cey + cez * cez;
  861. const dlift = dex * dex + dey * dey + dez * dez;
  862. return (clift * dab - dlift * abc) + (alift * bcd - blift * cda);
  863. }
  864. exports.insphere = insphere;
  865. exports.inspherefast = inspherefast;
  866. }));