Node-Red configuration
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

insphere.js 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. import {epsilon, splitter, resulterrbound, estimate, vec, sum, sum_three, scale, negate} from './util.js';
  2. const isperrboundA = (16 + 224 * epsilon) * epsilon;
  3. const isperrboundB = (5 + 72 * epsilon) * epsilon;
  4. const isperrboundC = (71 + 1408 * epsilon) * epsilon * epsilon;
  5. const ab = vec(4);
  6. const bc = vec(4);
  7. const cd = vec(4);
  8. const de = vec(4);
  9. const ea = vec(4);
  10. const ac = vec(4);
  11. const bd = vec(4);
  12. const ce = vec(4);
  13. const da = vec(4);
  14. const eb = vec(4);
  15. const abc = vec(24);
  16. const bcd = vec(24);
  17. const cde = vec(24);
  18. const dea = vec(24);
  19. const eab = vec(24);
  20. const abd = vec(24);
  21. const bce = vec(24);
  22. const cda = vec(24);
  23. const deb = vec(24);
  24. const eac = vec(24);
  25. const adet = vec(1152);
  26. const bdet = vec(1152);
  27. const cdet = vec(1152);
  28. const ddet = vec(1152);
  29. const edet = vec(1152);
  30. const abdet = vec(2304);
  31. const cddet = vec(2304);
  32. const cdedet = vec(3456);
  33. const deter = vec(5760);
  34. const _8 = vec(8);
  35. const _8b = vec(8);
  36. const _8c = vec(8);
  37. const _16 = vec(16);
  38. const _24 = vec(24);
  39. const _48 = vec(48);
  40. const _48b = vec(48);
  41. const _96 = vec(96);
  42. const _192 = vec(192);
  43. const _384x = vec(384);
  44. const _384y = vec(384);
  45. const _384z = vec(384);
  46. const _768 = vec(768);
  47. function sum_three_scale(a, b, c, az, bz, cz, out) {
  48. return sum_three(
  49. scale(4, a, az, _8), _8,
  50. scale(4, b, bz, _8b), _8b,
  51. scale(4, c, cz, _8c), _8c, _16, out);
  52. }
  53. function liftexact(alen, a, blen, b, clen, c, dlen, d, x, y, z, out) {
  54. const len = sum(
  55. sum(alen, a, blen, b, _48), _48,
  56. negate(sum(clen, c, dlen, d, _48b), _48b), _48b, _96);
  57. return sum_three(
  58. scale(scale(len, _96, x, _192), _192, x, _384x), _384x,
  59. scale(scale(len, _96, y, _192), _192, y, _384y), _384y,
  60. scale(scale(len, _96, z, _192), _192, z, _384z), _384z, _768, out);
  61. }
  62. function insphereexact(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez) {
  63. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  64. s1 = ax * by;
  65. c = splitter * ax;
  66. ahi = c - (c - ax);
  67. alo = ax - ahi;
  68. c = splitter * by;
  69. bhi = c - (c - by);
  70. blo = by - bhi;
  71. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  72. t1 = bx * ay;
  73. c = splitter * bx;
  74. ahi = c - (c - bx);
  75. alo = bx - ahi;
  76. c = splitter * ay;
  77. bhi = c - (c - ay);
  78. blo = ay - bhi;
  79. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  80. _i = s0 - t0;
  81. bvirt = s0 - _i;
  82. ab[0] = s0 - (_i + bvirt) + (bvirt - t0);
  83. _j = s1 + _i;
  84. bvirt = _j - s1;
  85. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  86. _i = _0 - t1;
  87. bvirt = _0 - _i;
  88. ab[1] = _0 - (_i + bvirt) + (bvirt - t1);
  89. u3 = _j + _i;
  90. bvirt = u3 - _j;
  91. ab[2] = _j - (u3 - bvirt) + (_i - bvirt);
  92. ab[3] = u3;
  93. s1 = bx * cy;
  94. c = splitter * bx;
  95. ahi = c - (c - bx);
  96. alo = bx - ahi;
  97. c = splitter * cy;
  98. bhi = c - (c - cy);
  99. blo = cy - bhi;
  100. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  101. t1 = cx * by;
  102. c = splitter * cx;
  103. ahi = c - (c - cx);
  104. alo = cx - ahi;
  105. c = splitter * by;
  106. bhi = c - (c - by);
  107. blo = by - bhi;
  108. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  109. _i = s0 - t0;
  110. bvirt = s0 - _i;
  111. bc[0] = s0 - (_i + bvirt) + (bvirt - t0);
  112. _j = s1 + _i;
  113. bvirt = _j - s1;
  114. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  115. _i = _0 - t1;
  116. bvirt = _0 - _i;
  117. bc[1] = _0 - (_i + bvirt) + (bvirt - t1);
  118. u3 = _j + _i;
  119. bvirt = u3 - _j;
  120. bc[2] = _j - (u3 - bvirt) + (_i - bvirt);
  121. bc[3] = u3;
  122. s1 = cx * dy;
  123. c = splitter * cx;
  124. ahi = c - (c - cx);
  125. alo = cx - ahi;
  126. c = splitter * dy;
  127. bhi = c - (c - dy);
  128. blo = dy - bhi;
  129. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  130. t1 = dx * cy;
  131. c = splitter * dx;
  132. ahi = c - (c - dx);
  133. alo = dx - ahi;
  134. c = splitter * cy;
  135. bhi = c - (c - cy);
  136. blo = cy - bhi;
  137. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  138. _i = s0 - t0;
  139. bvirt = s0 - _i;
  140. cd[0] = s0 - (_i + bvirt) + (bvirt - t0);
  141. _j = s1 + _i;
  142. bvirt = _j - s1;
  143. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  144. _i = _0 - t1;
  145. bvirt = _0 - _i;
  146. cd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  147. u3 = _j + _i;
  148. bvirt = u3 - _j;
  149. cd[2] = _j - (u3 - bvirt) + (_i - bvirt);
  150. cd[3] = u3;
  151. s1 = dx * ey;
  152. c = splitter * dx;
  153. ahi = c - (c - dx);
  154. alo = dx - ahi;
  155. c = splitter * ey;
  156. bhi = c - (c - ey);
  157. blo = ey - bhi;
  158. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  159. t1 = ex * dy;
  160. c = splitter * ex;
  161. ahi = c - (c - ex);
  162. alo = ex - ahi;
  163. c = splitter * dy;
  164. bhi = c - (c - dy);
  165. blo = dy - bhi;
  166. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  167. _i = s0 - t0;
  168. bvirt = s0 - _i;
  169. de[0] = s0 - (_i + bvirt) + (bvirt - t0);
  170. _j = s1 + _i;
  171. bvirt = _j - s1;
  172. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  173. _i = _0 - t1;
  174. bvirt = _0 - _i;
  175. de[1] = _0 - (_i + bvirt) + (bvirt - t1);
  176. u3 = _j + _i;
  177. bvirt = u3 - _j;
  178. de[2] = _j - (u3 - bvirt) + (_i - bvirt);
  179. de[3] = u3;
  180. s1 = ex * ay;
  181. c = splitter * ex;
  182. ahi = c - (c - ex);
  183. alo = ex - ahi;
  184. c = splitter * ay;
  185. bhi = c - (c - ay);
  186. blo = ay - bhi;
  187. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  188. t1 = ax * ey;
  189. c = splitter * ax;
  190. ahi = c - (c - ax);
  191. alo = ax - ahi;
  192. c = splitter * ey;
  193. bhi = c - (c - ey);
  194. blo = ey - bhi;
  195. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  196. _i = s0 - t0;
  197. bvirt = s0 - _i;
  198. ea[0] = s0 - (_i + bvirt) + (bvirt - t0);
  199. _j = s1 + _i;
  200. bvirt = _j - s1;
  201. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  202. _i = _0 - t1;
  203. bvirt = _0 - _i;
  204. ea[1] = _0 - (_i + bvirt) + (bvirt - t1);
  205. u3 = _j + _i;
  206. bvirt = u3 - _j;
  207. ea[2] = _j - (u3 - bvirt) + (_i - bvirt);
  208. ea[3] = u3;
  209. s1 = ax * cy;
  210. c = splitter * ax;
  211. ahi = c - (c - ax);
  212. alo = ax - ahi;
  213. c = splitter * cy;
  214. bhi = c - (c - cy);
  215. blo = cy - bhi;
  216. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  217. t1 = cx * ay;
  218. c = splitter * cx;
  219. ahi = c - (c - cx);
  220. alo = cx - ahi;
  221. c = splitter * ay;
  222. bhi = c - (c - ay);
  223. blo = ay - bhi;
  224. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  225. _i = s0 - t0;
  226. bvirt = s0 - _i;
  227. ac[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. ac[1] = _0 - (_i + bvirt) + (bvirt - t1);
  234. u3 = _j + _i;
  235. bvirt = u3 - _j;
  236. ac[2] = _j - (u3 - bvirt) + (_i - bvirt);
  237. ac[3] = u3;
  238. s1 = bx * dy;
  239. c = splitter * bx;
  240. ahi = c - (c - bx);
  241. alo = bx - ahi;
  242. c = splitter * dy;
  243. bhi = c - (c - dy);
  244. blo = dy - bhi;
  245. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  246. t1 = dx * by;
  247. c = splitter * dx;
  248. ahi = c - (c - dx);
  249. alo = dx - 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. bd[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. bd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  263. u3 = _j + _i;
  264. bvirt = u3 - _j;
  265. bd[2] = _j - (u3 - bvirt) + (_i - bvirt);
  266. bd[3] = u3;
  267. s1 = cx * ey;
  268. c = splitter * cx;
  269. ahi = c - (c - cx);
  270. alo = cx - ahi;
  271. c = splitter * ey;
  272. bhi = c - (c - ey);
  273. blo = ey - bhi;
  274. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  275. t1 = ex * cy;
  276. c = splitter * ex;
  277. ahi = c - (c - ex);
  278. alo = ex - ahi;
  279. c = splitter * cy;
  280. bhi = c - (c - cy);
  281. blo = cy - bhi;
  282. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  283. _i = s0 - t0;
  284. bvirt = s0 - _i;
  285. ce[0] = s0 - (_i + bvirt) + (bvirt - t0);
  286. _j = s1 + _i;
  287. bvirt = _j - s1;
  288. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  289. _i = _0 - t1;
  290. bvirt = _0 - _i;
  291. ce[1] = _0 - (_i + bvirt) + (bvirt - t1);
  292. u3 = _j + _i;
  293. bvirt = u3 - _j;
  294. ce[2] = _j - (u3 - bvirt) + (_i - bvirt);
  295. ce[3] = u3;
  296. s1 = dx * ay;
  297. c = splitter * dx;
  298. ahi = c - (c - dx);
  299. alo = dx - ahi;
  300. c = splitter * ay;
  301. bhi = c - (c - ay);
  302. blo = ay - bhi;
  303. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  304. t1 = ax * dy;
  305. c = splitter * ax;
  306. ahi = c - (c - ax);
  307. alo = ax - ahi;
  308. c = splitter * dy;
  309. bhi = c - (c - dy);
  310. blo = dy - bhi;
  311. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  312. _i = s0 - t0;
  313. bvirt = s0 - _i;
  314. da[0] = s0 - (_i + bvirt) + (bvirt - t0);
  315. _j = s1 + _i;
  316. bvirt = _j - s1;
  317. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  318. _i = _0 - t1;
  319. bvirt = _0 - _i;
  320. da[1] = _0 - (_i + bvirt) + (bvirt - t1);
  321. u3 = _j + _i;
  322. bvirt = u3 - _j;
  323. da[2] = _j - (u3 - bvirt) + (_i - bvirt);
  324. da[3] = u3;
  325. s1 = ex * by;
  326. c = splitter * ex;
  327. ahi = c - (c - ex);
  328. alo = ex - ahi;
  329. c = splitter * by;
  330. bhi = c - (c - by);
  331. blo = by - bhi;
  332. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  333. t1 = bx * ey;
  334. c = splitter * bx;
  335. ahi = c - (c - bx);
  336. alo = bx - ahi;
  337. c = splitter * ey;
  338. bhi = c - (c - ey);
  339. blo = ey - bhi;
  340. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  341. _i = s0 - t0;
  342. bvirt = s0 - _i;
  343. eb[0] = s0 - (_i + bvirt) + (bvirt - t0);
  344. _j = s1 + _i;
  345. bvirt = _j - s1;
  346. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  347. _i = _0 - t1;
  348. bvirt = _0 - _i;
  349. eb[1] = _0 - (_i + bvirt) + (bvirt - t1);
  350. u3 = _j + _i;
  351. bvirt = u3 - _j;
  352. eb[2] = _j - (u3 - bvirt) + (_i - bvirt);
  353. eb[3] = u3;
  354. const abclen = sum_three_scale(ab, bc, ac, cz, az, -bz, abc);
  355. const bcdlen = sum_three_scale(bc, cd, bd, dz, bz, -cz, bcd);
  356. const cdelen = sum_three_scale(cd, de, ce, ez, cz, -dz, cde);
  357. const dealen = sum_three_scale(de, ea, da, az, dz, -ez, dea);
  358. const eablen = sum_three_scale(ea, ab, eb, bz, ez, -az, eab);
  359. const abdlen = sum_three_scale(ab, bd, da, dz, az, bz, abd);
  360. const bcelen = sum_three_scale(bc, ce, eb, ez, bz, cz, bce);
  361. const cdalen = sum_three_scale(cd, da, ac, az, cz, dz, cda);
  362. const deblen = sum_three_scale(de, eb, bd, bz, dz, ez, deb);
  363. const eaclen = sum_three_scale(ea, ac, ce, cz, ez, az, eac);
  364. const deterlen = sum_three(
  365. liftexact(cdelen, cde, bcelen, bce, deblen, deb, bcdlen, bcd, ax, ay, az, adet), adet,
  366. liftexact(dealen, dea, cdalen, cda, eaclen, eac, cdelen, cde, bx, by, bz, bdet), bdet,
  367. sum_three(
  368. liftexact(eablen, eab, deblen, deb, abdlen, abd, dealen, dea, cx, cy, cz, cdet), cdet,
  369. liftexact(abclen, abc, eaclen, eac, bcelen, bce, eablen, eab, dx, dy, dz, ddet), ddet,
  370. liftexact(bcdlen, bcd, abdlen, abd, cdalen, cda, abclen, abc, ex, ey, ez, edet), edet, cddet, cdedet), cdedet, abdet, deter);
  371. return deter[deterlen - 1];
  372. }
  373. const xdet = vec(96);
  374. const ydet = vec(96);
  375. const zdet = vec(96);
  376. const fin = vec(1152);
  377. function liftadapt(a, b, c, az, bz, cz, x, y, z, out) {
  378. const len = sum_three_scale(a, b, c, az, bz, cz, _24);
  379. return sum_three(
  380. scale(scale(len, _24, x, _48), _48, x, xdet), xdet,
  381. scale(scale(len, _24, y, _48), _48, y, ydet), ydet,
  382. scale(scale(len, _24, z, _48), _48, z, zdet), zdet, _192, out);
  383. }
  384. function insphereadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez, permanent) {
  385. let ab3, bc3, cd3, da3, ac3, bd3;
  386. let aextail, bextail, cextail, dextail;
  387. let aeytail, beytail, ceytail, deytail;
  388. let aeztail, beztail, ceztail, deztail;
  389. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0;
  390. const aex = ax - ex;
  391. const bex = bx - ex;
  392. const cex = cx - ex;
  393. const dex = dx - ex;
  394. const aey = ay - ey;
  395. const bey = by - ey;
  396. const cey = cy - ey;
  397. const dey = dy - ey;
  398. const aez = az - ez;
  399. const bez = bz - ez;
  400. const cez = cz - ez;
  401. const dez = dz - ez;
  402. s1 = aex * bey;
  403. c = splitter * aex;
  404. ahi = c - (c - aex);
  405. alo = aex - ahi;
  406. c = splitter * bey;
  407. bhi = c - (c - bey);
  408. blo = bey - bhi;
  409. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  410. t1 = bex * aey;
  411. c = splitter * bex;
  412. ahi = c - (c - bex);
  413. alo = bex - ahi;
  414. c = splitter * aey;
  415. bhi = c - (c - aey);
  416. blo = aey - bhi;
  417. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  418. _i = s0 - t0;
  419. bvirt = s0 - _i;
  420. ab[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. ab[1] = _0 - (_i + bvirt) + (bvirt - t1);
  427. ab3 = _j + _i;
  428. bvirt = ab3 - _j;
  429. ab[2] = _j - (ab3 - bvirt) + (_i - bvirt);
  430. ab[3] = ab3;
  431. s1 = bex * cey;
  432. c = splitter * bex;
  433. ahi = c - (c - bex);
  434. alo = bex - ahi;
  435. c = splitter * cey;
  436. bhi = c - (c - cey);
  437. blo = cey - bhi;
  438. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  439. t1 = cex * bey;
  440. c = splitter * cex;
  441. ahi = c - (c - cex);
  442. alo = cex - ahi;
  443. c = splitter * bey;
  444. bhi = c - (c - bey);
  445. blo = bey - bhi;
  446. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  447. _i = s0 - t0;
  448. bvirt = s0 - _i;
  449. bc[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. bc[1] = _0 - (_i + bvirt) + (bvirt - t1);
  456. bc3 = _j + _i;
  457. bvirt = bc3 - _j;
  458. bc[2] = _j - (bc3 - bvirt) + (_i - bvirt);
  459. bc[3] = bc3;
  460. s1 = cex * dey;
  461. c = splitter * cex;
  462. ahi = c - (c - cex);
  463. alo = cex - ahi;
  464. c = splitter * dey;
  465. bhi = c - (c - dey);
  466. blo = dey - bhi;
  467. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  468. t1 = dex * cey;
  469. c = splitter * dex;
  470. ahi = c - (c - dex);
  471. alo = dex - ahi;
  472. c = splitter * cey;
  473. bhi = c - (c - cey);
  474. blo = cey - bhi;
  475. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  476. _i = s0 - t0;
  477. bvirt = s0 - _i;
  478. cd[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. cd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  485. cd3 = _j + _i;
  486. bvirt = cd3 - _j;
  487. cd[2] = _j - (cd3 - bvirt) + (_i - bvirt);
  488. cd[3] = cd3;
  489. s1 = dex * aey;
  490. c = splitter * dex;
  491. ahi = c - (c - dex);
  492. alo = dex - ahi;
  493. c = splitter * aey;
  494. bhi = c - (c - aey);
  495. blo = aey - bhi;
  496. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  497. t1 = aex * dey;
  498. c = splitter * aex;
  499. ahi = c - (c - aex);
  500. alo = aex - ahi;
  501. c = splitter * dey;
  502. bhi = c - (c - dey);
  503. blo = dey - bhi;
  504. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  505. _i = s0 - t0;
  506. bvirt = s0 - _i;
  507. da[0] = s0 - (_i + bvirt) + (bvirt - t0);
  508. _j = s1 + _i;
  509. bvirt = _j - s1;
  510. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  511. _i = _0 - t1;
  512. bvirt = _0 - _i;
  513. da[1] = _0 - (_i + bvirt) + (bvirt - t1);
  514. da3 = _j + _i;
  515. bvirt = da3 - _j;
  516. da[2] = _j - (da3 - bvirt) + (_i - bvirt);
  517. da[3] = da3;
  518. s1 = aex * cey;
  519. c = splitter * aex;
  520. ahi = c - (c - aex);
  521. alo = aex - ahi;
  522. c = splitter * cey;
  523. bhi = c - (c - cey);
  524. blo = cey - bhi;
  525. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  526. t1 = cex * aey;
  527. c = splitter * cex;
  528. ahi = c - (c - cex);
  529. alo = cex - ahi;
  530. c = splitter * aey;
  531. bhi = c - (c - aey);
  532. blo = aey - bhi;
  533. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  534. _i = s0 - t0;
  535. bvirt = s0 - _i;
  536. ac[0] = s0 - (_i + bvirt) + (bvirt - t0);
  537. _j = s1 + _i;
  538. bvirt = _j - s1;
  539. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  540. _i = _0 - t1;
  541. bvirt = _0 - _i;
  542. ac[1] = _0 - (_i + bvirt) + (bvirt - t1);
  543. ac3 = _j + _i;
  544. bvirt = ac3 - _j;
  545. ac[2] = _j - (ac3 - bvirt) + (_i - bvirt);
  546. ac[3] = ac3;
  547. s1 = bex * dey;
  548. c = splitter * bex;
  549. ahi = c - (c - bex);
  550. alo = bex - ahi;
  551. c = splitter * dey;
  552. bhi = c - (c - dey);
  553. blo = dey - bhi;
  554. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  555. t1 = dex * bey;
  556. c = splitter * dex;
  557. ahi = c - (c - dex);
  558. alo = dex - ahi;
  559. c = splitter * bey;
  560. bhi = c - (c - bey);
  561. blo = bey - bhi;
  562. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  563. _i = s0 - t0;
  564. bvirt = s0 - _i;
  565. bd[0] = s0 - (_i + bvirt) + (bvirt - t0);
  566. _j = s1 + _i;
  567. bvirt = _j - s1;
  568. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  569. _i = _0 - t1;
  570. bvirt = _0 - _i;
  571. bd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  572. bd3 = _j + _i;
  573. bvirt = bd3 - _j;
  574. bd[2] = _j - (bd3 - bvirt) + (_i - bvirt);
  575. bd[3] = bd3;
  576. const finlen = sum(
  577. sum(
  578. negate(liftadapt(bc, cd, bd, dez, bez, -cez, aex, aey, aez, adet), adet), adet,
  579. liftadapt(cd, da, ac, aez, cez, dez, bex, bey, bez, bdet), bdet, abdet), abdet,
  580. sum(
  581. negate(liftadapt(da, ab, bd, bez, dez, aez, cex, cey, cez, cdet), cdet), cdet,
  582. liftadapt(ab, bc, ac, cez, aez, -bez, dex, dey, dez, ddet), ddet, cddet), cddet, fin);
  583. let det = estimate(finlen, fin);
  584. let errbound = isperrboundB * permanent;
  585. if (det >= errbound || -det >= errbound) {
  586. return det;
  587. }
  588. bvirt = ax - aex;
  589. aextail = ax - (aex + bvirt) + (bvirt - ex);
  590. bvirt = ay - aey;
  591. aeytail = ay - (aey + bvirt) + (bvirt - ey);
  592. bvirt = az - aez;
  593. aeztail = az - (aez + bvirt) + (bvirt - ez);
  594. bvirt = bx - bex;
  595. bextail = bx - (bex + bvirt) + (bvirt - ex);
  596. bvirt = by - bey;
  597. beytail = by - (bey + bvirt) + (bvirt - ey);
  598. bvirt = bz - bez;
  599. beztail = bz - (bez + bvirt) + (bvirt - ez);
  600. bvirt = cx - cex;
  601. cextail = cx - (cex + bvirt) + (bvirt - ex);
  602. bvirt = cy - cey;
  603. ceytail = cy - (cey + bvirt) + (bvirt - ey);
  604. bvirt = cz - cez;
  605. ceztail = cz - (cez + bvirt) + (bvirt - ez);
  606. bvirt = dx - dex;
  607. dextail = dx - (dex + bvirt) + (bvirt - ex);
  608. bvirt = dy - dey;
  609. deytail = dy - (dey + bvirt) + (bvirt - ey);
  610. bvirt = dz - dez;
  611. deztail = dz - (dez + bvirt) + (bvirt - ez);
  612. if (aextail === 0 && aeytail === 0 && aeztail === 0 &&
  613. bextail === 0 && beytail === 0 && beztail === 0 &&
  614. cextail === 0 && ceytail === 0 && ceztail === 0 &&
  615. dextail === 0 && deytail === 0 && deztail === 0) {
  616. return det;
  617. }
  618. errbound = isperrboundC * permanent + resulterrbound * Math.abs(det);
  619. const abeps = (aex * beytail + bey * aextail) - (aey * bextail + bex * aeytail);
  620. const bceps = (bex * ceytail + cey * bextail) - (bey * cextail + cex * beytail);
  621. const cdeps = (cex * deytail + dey * cextail) - (cey * dextail + dex * ceytail);
  622. const daeps = (dex * aeytail + aey * dextail) - (dey * aextail + aex * deytail);
  623. const aceps = (aex * ceytail + cey * aextail) - (aey * cextail + cex * aeytail);
  624. const bdeps = (bex * deytail + dey * bextail) - (bey * dextail + dex * beytail);
  625. det +=
  626. (((bex * bex + bey * bey + bez * bez) * ((cez * daeps + dez * aceps + aez * cdeps) +
  627. (ceztail * da3 + deztail * ac3 + aeztail * cd3)) + (dex * dex + dey * dey + dez * dez) *
  628. ((aez * bceps - bez * aceps + cez * abeps) + (aeztail * bc3 - beztail * ac3 + ceztail * ab3))) -
  629. ((aex * aex + aey * aey + aez * aez) * ((bez * cdeps - cez * bdeps + dez * bceps) +
  630. (beztail * cd3 - ceztail * bd3 + deztail * bc3)) + (cex * cex + cey * cey + cez * cez) *
  631. ((dez * abeps + aez * bdeps + bez * daeps) + (deztail * ab3 + aeztail * bd3 + beztail * da3)))) +
  632. 2 * (((bex * bextail + bey * beytail + bez * beztail) * (cez * da3 + dez * ac3 + aez * cd3) +
  633. (dex * dextail + dey * deytail + dez * deztail) * (aez * bc3 - bez * ac3 + cez * ab3)) -
  634. ((aex * aextail + aey * aeytail + aez * aeztail) * (bez * cd3 - cez * bd3 + dez * bc3) +
  635. (cex * cextail + cey * ceytail + cez * ceztail) * (dez * ab3 + aez * bd3 + bez * da3)));
  636. if (det >= errbound || -det >= errbound) {
  637. return det;
  638. }
  639. return insphereexact(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez);
  640. }
  641. export function insphere(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez) {
  642. const aex = ax - ex;
  643. const bex = bx - ex;
  644. const cex = cx - ex;
  645. const dex = dx - ex;
  646. const aey = ay - ey;
  647. const bey = by - ey;
  648. const cey = cy - ey;
  649. const dey = dy - ey;
  650. const aez = az - ez;
  651. const bez = bz - ez;
  652. const cez = cz - ez;
  653. const dez = dz - ez;
  654. const aexbey = aex * bey;
  655. const bexaey = bex * aey;
  656. const ab = aexbey - bexaey;
  657. const bexcey = bex * cey;
  658. const cexbey = cex * bey;
  659. const bc = bexcey - cexbey;
  660. const cexdey = cex * dey;
  661. const dexcey = dex * cey;
  662. const cd = cexdey - dexcey;
  663. const dexaey = dex * aey;
  664. const aexdey = aex * dey;
  665. const da = dexaey - aexdey;
  666. const aexcey = aex * cey;
  667. const cexaey = cex * aey;
  668. const ac = aexcey - cexaey;
  669. const bexdey = bex * dey;
  670. const dexbey = dex * bey;
  671. const bd = bexdey - dexbey;
  672. const alift = aex * aex + aey * aey + aez * aez;
  673. const blift = bex * bex + bey * bey + bez * bez;
  674. const clift = cex * cex + cey * cey + cez * cez;
  675. const dlift = dex * dex + dey * dey + dez * dez;
  676. const det =
  677. (clift * (dez * ab + aez * bd + bez * da) - dlift * (aez * bc - bez * ac + cez * ab)) +
  678. (alift * (bez * cd - cez * bd + dez * bc) - blift * (cez * da + dez * ac + aez * cd));
  679. const aezplus = Math.abs(aez);
  680. const bezplus = Math.abs(bez);
  681. const cezplus = Math.abs(cez);
  682. const dezplus = Math.abs(dez);
  683. const aexbeyplus = Math.abs(aexbey) + Math.abs(bexaey);
  684. const bexceyplus = Math.abs(bexcey) + Math.abs(cexbey);
  685. const cexdeyplus = Math.abs(cexdey) + Math.abs(dexcey);
  686. const dexaeyplus = Math.abs(dexaey) + Math.abs(aexdey);
  687. const aexceyplus = Math.abs(aexcey) + Math.abs(cexaey);
  688. const bexdeyplus = Math.abs(bexdey) + Math.abs(dexbey);
  689. const permanent =
  690. (cexdeyplus * bezplus + bexdeyplus * cezplus + bexceyplus * dezplus) * alift +
  691. (dexaeyplus * cezplus + aexceyplus * dezplus + cexdeyplus * aezplus) * blift +
  692. (aexbeyplus * dezplus + bexdeyplus * aezplus + dexaeyplus * bezplus) * clift +
  693. (bexceyplus * aezplus + aexceyplus * bezplus + aexbeyplus * cezplus) * dlift;
  694. const errbound = isperrboundA * permanent;
  695. if (det > errbound || -det > errbound) {
  696. return det;
  697. }
  698. return -insphereadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez, permanent);
  699. }
  700. export function inspherefast(pax, pay, paz, pbx, pby, pbz, pcx, pcy, pcz, pdx, pdy, pdz, pex, pey, pez) {
  701. const aex = pax - pex;
  702. const bex = pbx - pex;
  703. const cex = pcx - pex;
  704. const dex = pdx - pex;
  705. const aey = pay - pey;
  706. const bey = pby - pey;
  707. const cey = pcy - pey;
  708. const dey = pdy - pey;
  709. const aez = paz - pez;
  710. const bez = pbz - pez;
  711. const cez = pcz - pez;
  712. const dez = pdz - pez;
  713. const ab = aex * bey - bex * aey;
  714. const bc = bex * cey - cex * bey;
  715. const cd = cex * dey - dex * cey;
  716. const da = dex * aey - aex * dey;
  717. const ac = aex * cey - cex * aey;
  718. const bd = bex * dey - dex * bey;
  719. const abc = aez * bc - bez * ac + cez * ab;
  720. const bcd = bez * cd - cez * bd + dez * bc;
  721. const cda = cez * da + dez * ac + aez * cd;
  722. const dab = dez * ab + aez * bd + bez * da;
  723. const alift = aex * aex + aey * aey + aez * aez;
  724. const blift = bex * bex + bey * bey + bez * bez;
  725. const clift = cex * cex + cey * cey + cez * cez;
  726. const dlift = dex * dex + dey * dey + dez * dez;
  727. return (clift * dab - dlift * abc) + (alift * bcd - blift * cda);
  728. }