Node-Red configuration
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

predicates.js 73KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328
  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 ccwerrboundA = (3 + 16 * epsilon) * epsilon;
  138. const ccwerrboundB = (2 + 12 * epsilon) * epsilon;
  139. const ccwerrboundC = (9 + 64 * epsilon) * epsilon * epsilon;
  140. const B = vec(4);
  141. const C1 = vec(8);
  142. const C2 = vec(12);
  143. const D = vec(16);
  144. const u$2 = vec(4);
  145. function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
  146. let acxtail, acytail, bcxtail, bcytail;
  147. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  148. const acx = ax - cx;
  149. const bcx = bx - cx;
  150. const acy = ay - cy;
  151. const bcy = by - cy;
  152. s1 = acx * bcy;
  153. c = splitter * acx;
  154. ahi = c - (c - acx);
  155. alo = acx - ahi;
  156. c = splitter * bcy;
  157. bhi = c - (c - bcy);
  158. blo = bcy - bhi;
  159. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  160. t1 = acy * bcx;
  161. c = splitter * acy;
  162. ahi = c - (c - acy);
  163. alo = acy - ahi;
  164. c = splitter * bcx;
  165. bhi = c - (c - bcx);
  166. blo = bcx - bhi;
  167. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  168. _i = s0 - t0;
  169. bvirt = s0 - _i;
  170. B[0] = s0 - (_i + bvirt) + (bvirt - t0);
  171. _j = s1 + _i;
  172. bvirt = _j - s1;
  173. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  174. _i = _0 - t1;
  175. bvirt = _0 - _i;
  176. B[1] = _0 - (_i + bvirt) + (bvirt - t1);
  177. u3 = _j + _i;
  178. bvirt = u3 - _j;
  179. B[2] = _j - (u3 - bvirt) + (_i - bvirt);
  180. B[3] = u3;
  181. let det = estimate(4, B);
  182. let errbound = ccwerrboundB * detsum;
  183. if (det >= errbound || -det >= errbound) {
  184. return det;
  185. }
  186. bvirt = ax - acx;
  187. acxtail = ax - (acx + bvirt) + (bvirt - cx);
  188. bvirt = bx - bcx;
  189. bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
  190. bvirt = ay - acy;
  191. acytail = ay - (acy + bvirt) + (bvirt - cy);
  192. bvirt = by - bcy;
  193. bcytail = by - (bcy + bvirt) + (bvirt - cy);
  194. if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
  195. return det;
  196. }
  197. errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
  198. det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
  199. if (det >= errbound || -det >= errbound) return det;
  200. s1 = acxtail * bcy;
  201. c = splitter * acxtail;
  202. ahi = c - (c - acxtail);
  203. alo = acxtail - ahi;
  204. c = splitter * bcy;
  205. bhi = c - (c - bcy);
  206. blo = bcy - bhi;
  207. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  208. t1 = acytail * bcx;
  209. c = splitter * acytail;
  210. ahi = c - (c - acytail);
  211. alo = acytail - ahi;
  212. c = splitter * bcx;
  213. bhi = c - (c - bcx);
  214. blo = bcx - bhi;
  215. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  216. _i = s0 - t0;
  217. bvirt = s0 - _i;
  218. u$2[0] = s0 - (_i + bvirt) + (bvirt - t0);
  219. _j = s1 + _i;
  220. bvirt = _j - s1;
  221. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  222. _i = _0 - t1;
  223. bvirt = _0 - _i;
  224. u$2[1] = _0 - (_i + bvirt) + (bvirt - t1);
  225. u3 = _j + _i;
  226. bvirt = u3 - _j;
  227. u$2[2] = _j - (u3 - bvirt) + (_i - bvirt);
  228. u$2[3] = u3;
  229. const C1len = sum(4, B, 4, u$2, C1);
  230. s1 = acx * bcytail;
  231. c = splitter * acx;
  232. ahi = c - (c - acx);
  233. alo = acx - ahi;
  234. c = splitter * bcytail;
  235. bhi = c - (c - bcytail);
  236. blo = bcytail - bhi;
  237. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  238. t1 = acy * bcxtail;
  239. c = splitter * acy;
  240. ahi = c - (c - acy);
  241. alo = acy - ahi;
  242. c = splitter * bcxtail;
  243. bhi = c - (c - bcxtail);
  244. blo = bcxtail - bhi;
  245. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  246. _i = s0 - t0;
  247. bvirt = s0 - _i;
  248. u$2[0] = s0 - (_i + bvirt) + (bvirt - t0);
  249. _j = s1 + _i;
  250. bvirt = _j - s1;
  251. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  252. _i = _0 - t1;
  253. bvirt = _0 - _i;
  254. u$2[1] = _0 - (_i + bvirt) + (bvirt - t1);
  255. u3 = _j + _i;
  256. bvirt = u3 - _j;
  257. u$2[2] = _j - (u3 - bvirt) + (_i - bvirt);
  258. u$2[3] = u3;
  259. const C2len = sum(C1len, C1, 4, u$2, C2);
  260. s1 = acxtail * bcytail;
  261. c = splitter * acxtail;
  262. ahi = c - (c - acxtail);
  263. alo = acxtail - ahi;
  264. c = splitter * bcytail;
  265. bhi = c - (c - bcytail);
  266. blo = bcytail - bhi;
  267. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  268. t1 = acytail * bcxtail;
  269. c = splitter * acytail;
  270. ahi = c - (c - acytail);
  271. alo = acytail - ahi;
  272. c = splitter * bcxtail;
  273. bhi = c - (c - bcxtail);
  274. blo = bcxtail - bhi;
  275. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  276. _i = s0 - t0;
  277. bvirt = s0 - _i;
  278. u$2[0] = s0 - (_i + bvirt) + (bvirt - t0);
  279. _j = s1 + _i;
  280. bvirt = _j - s1;
  281. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  282. _i = _0 - t1;
  283. bvirt = _0 - _i;
  284. u$2[1] = _0 - (_i + bvirt) + (bvirt - t1);
  285. u3 = _j + _i;
  286. bvirt = u3 - _j;
  287. u$2[2] = _j - (u3 - bvirt) + (_i - bvirt);
  288. u$2[3] = u3;
  289. const Dlen = sum(C2len, C2, 4, u$2, D);
  290. return D[Dlen - 1];
  291. }
  292. function orient2d(ax, ay, bx, by, cx, cy) {
  293. const detleft = (ay - cy) * (bx - cx);
  294. const detright = (ax - cx) * (by - cy);
  295. const det = detleft - detright;
  296. const detsum = Math.abs(detleft + detright);
  297. if (Math.abs(det) >= ccwerrboundA * detsum) return det;
  298. return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
  299. }
  300. function orient2dfast(ax, ay, bx, by, cx, cy) {
  301. return (ay - cy) * (bx - cx) - (ax - cx) * (by - cy);
  302. }
  303. const o3derrboundA = (7 + 56 * epsilon) * epsilon;
  304. const o3derrboundB = (3 + 28 * epsilon) * epsilon;
  305. const o3derrboundC = (26 + 288 * epsilon) * epsilon * epsilon;
  306. const bc$2 = vec(4);
  307. const ca$1 = vec(4);
  308. const ab$2 = vec(4);
  309. const at_b = vec(4);
  310. const at_c = vec(4);
  311. const bt_c = vec(4);
  312. const bt_a = vec(4);
  313. const ct_a = vec(4);
  314. const ct_b = vec(4);
  315. const bct$1 = vec(8);
  316. const cat$1 = vec(8);
  317. const abt$1 = vec(8);
  318. const u$1 = vec(4);
  319. const _8$2 = vec(8);
  320. const _8b$1 = vec(8);
  321. const _16$2 = vec(8);
  322. const _12 = vec(12);
  323. let fin$2 = vec(192);
  324. let fin2$1 = vec(192);
  325. function finadd$1(finlen, alen, a) {
  326. finlen = sum(finlen, fin$2, alen, a, fin2$1);
  327. const tmp = fin$2; fin$2 = fin2$1; fin2$1 = tmp;
  328. return finlen;
  329. }
  330. function tailinit(xtail, ytail, ax, ay, bx, by, a, b) {
  331. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3, negate;
  332. if (xtail === 0) {
  333. if (ytail === 0) {
  334. a[0] = 0;
  335. b[0] = 0;
  336. return 1;
  337. } else {
  338. negate = -ytail;
  339. s1 = negate * ax;
  340. c = splitter * negate;
  341. ahi = c - (c - negate);
  342. alo = negate - ahi;
  343. c = splitter * ax;
  344. bhi = c - (c - ax);
  345. blo = ax - bhi;
  346. a[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  347. a[1] = s1;
  348. s1 = ytail * bx;
  349. c = splitter * ytail;
  350. ahi = c - (c - ytail);
  351. alo = ytail - ahi;
  352. c = splitter * bx;
  353. bhi = c - (c - bx);
  354. blo = bx - bhi;
  355. b[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  356. b[1] = s1;
  357. return 2;
  358. }
  359. } else {
  360. if (ytail === 0) {
  361. s1 = xtail * ay;
  362. c = splitter * xtail;
  363. ahi = c - (c - xtail);
  364. alo = xtail - ahi;
  365. c = splitter * ay;
  366. bhi = c - (c - ay);
  367. blo = ay - bhi;
  368. a[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  369. a[1] = s1;
  370. negate = -xtail;
  371. s1 = negate * by;
  372. c = splitter * negate;
  373. ahi = c - (c - negate);
  374. alo = negate - ahi;
  375. c = splitter * by;
  376. bhi = c - (c - by);
  377. blo = by - bhi;
  378. b[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  379. b[1] = s1;
  380. return 2;
  381. } else {
  382. s1 = xtail * ay;
  383. c = splitter * xtail;
  384. ahi = c - (c - xtail);
  385. alo = xtail - ahi;
  386. c = splitter * ay;
  387. bhi = c - (c - ay);
  388. blo = ay - bhi;
  389. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  390. t1 = ytail * ax;
  391. c = splitter * ytail;
  392. ahi = c - (c - ytail);
  393. alo = ytail - ahi;
  394. c = splitter * ax;
  395. bhi = c - (c - ax);
  396. blo = ax - bhi;
  397. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  398. _i = s0 - t0;
  399. bvirt = s0 - _i;
  400. a[0] = s0 - (_i + bvirt) + (bvirt - t0);
  401. _j = s1 + _i;
  402. bvirt = _j - s1;
  403. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  404. _i = _0 - t1;
  405. bvirt = _0 - _i;
  406. a[1] = _0 - (_i + bvirt) + (bvirt - t1);
  407. u3 = _j + _i;
  408. bvirt = u3 - _j;
  409. a[2] = _j - (u3 - bvirt) + (_i - bvirt);
  410. a[3] = u3;
  411. s1 = ytail * bx;
  412. c = splitter * ytail;
  413. ahi = c - (c - ytail);
  414. alo = ytail - ahi;
  415. c = splitter * bx;
  416. bhi = c - (c - bx);
  417. blo = bx - bhi;
  418. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  419. t1 = xtail * by;
  420. c = splitter * xtail;
  421. ahi = c - (c - xtail);
  422. alo = xtail - ahi;
  423. c = splitter * by;
  424. bhi = c - (c - by);
  425. blo = by - bhi;
  426. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  427. _i = s0 - t0;
  428. bvirt = s0 - _i;
  429. b[0] = s0 - (_i + bvirt) + (bvirt - t0);
  430. _j = s1 + _i;
  431. bvirt = _j - s1;
  432. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  433. _i = _0 - t1;
  434. bvirt = _0 - _i;
  435. b[1] = _0 - (_i + bvirt) + (bvirt - t1);
  436. u3 = _j + _i;
  437. bvirt = u3 - _j;
  438. b[2] = _j - (u3 - bvirt) + (_i - bvirt);
  439. b[3] = u3;
  440. return 4;
  441. }
  442. }
  443. }
  444. function tailadd(finlen, a, b, k, z) {
  445. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _k, _0, s1, s0, u3;
  446. s1 = a * b;
  447. c = splitter * a;
  448. ahi = c - (c - a);
  449. alo = a - ahi;
  450. c = splitter * b;
  451. bhi = c - (c - b);
  452. blo = b - bhi;
  453. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  454. c = splitter * k;
  455. bhi = c - (c - k);
  456. blo = k - bhi;
  457. _i = s0 * k;
  458. c = splitter * s0;
  459. ahi = c - (c - s0);
  460. alo = s0 - ahi;
  461. u$1[0] = alo * blo - (_i - ahi * bhi - alo * bhi - ahi * blo);
  462. _j = s1 * k;
  463. c = splitter * s1;
  464. ahi = c - (c - s1);
  465. alo = s1 - ahi;
  466. _0 = alo * blo - (_j - ahi * bhi - alo * bhi - ahi * blo);
  467. _k = _i + _0;
  468. bvirt = _k - _i;
  469. u$1[1] = _i - (_k - bvirt) + (_0 - bvirt);
  470. u3 = _j + _k;
  471. u$1[2] = _k - (u3 - _j);
  472. u$1[3] = u3;
  473. finlen = finadd$1(finlen, 4, u$1);
  474. if (z !== 0) {
  475. c = splitter * z;
  476. bhi = c - (c - z);
  477. blo = z - bhi;
  478. _i = s0 * z;
  479. c = splitter * s0;
  480. ahi = c - (c - s0);
  481. alo = s0 - ahi;
  482. u$1[0] = alo * blo - (_i - ahi * bhi - alo * bhi - ahi * blo);
  483. _j = s1 * z;
  484. c = splitter * s1;
  485. ahi = c - (c - s1);
  486. alo = s1 - ahi;
  487. _0 = alo * blo - (_j - ahi * bhi - alo * bhi - ahi * blo);
  488. _k = _i + _0;
  489. bvirt = _k - _i;
  490. u$1[1] = _i - (_k - bvirt) + (_0 - bvirt);
  491. u3 = _j + _k;
  492. u$1[2] = _k - (u3 - _j);
  493. u$1[3] = u3;
  494. finlen = finadd$1(finlen, 4, u$1);
  495. }
  496. return finlen;
  497. }
  498. function orient3dadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, permanent) {
  499. let finlen;
  500. let adxtail, bdxtail, cdxtail;
  501. let adytail, bdytail, cdytail;
  502. let adztail, bdztail, cdztail;
  503. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  504. const adx = ax - dx;
  505. const bdx = bx - dx;
  506. const cdx = cx - dx;
  507. const ady = ay - dy;
  508. const bdy = by - dy;
  509. const cdy = cy - dy;
  510. const adz = az - dz;
  511. const bdz = bz - dz;
  512. const cdz = cz - dz;
  513. s1 = bdx * cdy;
  514. c = splitter * bdx;
  515. ahi = c - (c - bdx);
  516. alo = bdx - ahi;
  517. c = splitter * cdy;
  518. bhi = c - (c - cdy);
  519. blo = cdy - bhi;
  520. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  521. t1 = cdx * bdy;
  522. c = splitter * cdx;
  523. ahi = c - (c - cdx);
  524. alo = cdx - ahi;
  525. c = splitter * bdy;
  526. bhi = c - (c - bdy);
  527. blo = bdy - bhi;
  528. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  529. _i = s0 - t0;
  530. bvirt = s0 - _i;
  531. bc$2[0] = s0 - (_i + bvirt) + (bvirt - t0);
  532. _j = s1 + _i;
  533. bvirt = _j - s1;
  534. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  535. _i = _0 - t1;
  536. bvirt = _0 - _i;
  537. bc$2[1] = _0 - (_i + bvirt) + (bvirt - t1);
  538. u3 = _j + _i;
  539. bvirt = u3 - _j;
  540. bc$2[2] = _j - (u3 - bvirt) + (_i - bvirt);
  541. bc$2[3] = u3;
  542. s1 = cdx * ady;
  543. c = splitter * cdx;
  544. ahi = c - (c - cdx);
  545. alo = cdx - ahi;
  546. c = splitter * ady;
  547. bhi = c - (c - ady);
  548. blo = ady - bhi;
  549. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  550. t1 = adx * cdy;
  551. c = splitter * adx;
  552. ahi = c - (c - adx);
  553. alo = adx - ahi;
  554. c = splitter * cdy;
  555. bhi = c - (c - cdy);
  556. blo = cdy - bhi;
  557. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  558. _i = s0 - t0;
  559. bvirt = s0 - _i;
  560. ca$1[0] = s0 - (_i + bvirt) + (bvirt - t0);
  561. _j = s1 + _i;
  562. bvirt = _j - s1;
  563. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  564. _i = _0 - t1;
  565. bvirt = _0 - _i;
  566. ca$1[1] = _0 - (_i + bvirt) + (bvirt - t1);
  567. u3 = _j + _i;
  568. bvirt = u3 - _j;
  569. ca$1[2] = _j - (u3 - bvirt) + (_i - bvirt);
  570. ca$1[3] = u3;
  571. s1 = adx * bdy;
  572. c = splitter * adx;
  573. ahi = c - (c - adx);
  574. alo = adx - ahi;
  575. c = splitter * bdy;
  576. bhi = c - (c - bdy);
  577. blo = bdy - bhi;
  578. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  579. t1 = bdx * ady;
  580. c = splitter * bdx;
  581. ahi = c - (c - bdx);
  582. alo = bdx - ahi;
  583. c = splitter * ady;
  584. bhi = c - (c - ady);
  585. blo = ady - bhi;
  586. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  587. _i = s0 - t0;
  588. bvirt = s0 - _i;
  589. ab$2[0] = s0 - (_i + bvirt) + (bvirt - t0);
  590. _j = s1 + _i;
  591. bvirt = _j - s1;
  592. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  593. _i = _0 - t1;
  594. bvirt = _0 - _i;
  595. ab$2[1] = _0 - (_i + bvirt) + (bvirt - t1);
  596. u3 = _j + _i;
  597. bvirt = u3 - _j;
  598. ab$2[2] = _j - (u3 - bvirt) + (_i - bvirt);
  599. ab$2[3] = u3;
  600. finlen = sum(
  601. sum(
  602. scale(4, bc$2, adz, _8$2), _8$2,
  603. scale(4, ca$1, bdz, _8b$1), _8b$1, _16$2), _16$2,
  604. scale(4, ab$2, cdz, _8$2), _8$2, fin$2);
  605. let det = estimate(finlen, fin$2);
  606. let errbound = o3derrboundB * permanent;
  607. if (det >= errbound || -det >= errbound) {
  608. return det;
  609. }
  610. bvirt = ax - adx;
  611. adxtail = ax - (adx + bvirt) + (bvirt - dx);
  612. bvirt = bx - bdx;
  613. bdxtail = bx - (bdx + bvirt) + (bvirt - dx);
  614. bvirt = cx - cdx;
  615. cdxtail = cx - (cdx + bvirt) + (bvirt - dx);
  616. bvirt = ay - ady;
  617. adytail = ay - (ady + bvirt) + (bvirt - dy);
  618. bvirt = by - bdy;
  619. bdytail = by - (bdy + bvirt) + (bvirt - dy);
  620. bvirt = cy - cdy;
  621. cdytail = cy - (cdy + bvirt) + (bvirt - dy);
  622. bvirt = az - adz;
  623. adztail = az - (adz + bvirt) + (bvirt - dz);
  624. bvirt = bz - bdz;
  625. bdztail = bz - (bdz + bvirt) + (bvirt - dz);
  626. bvirt = cz - cdz;
  627. cdztail = cz - (cdz + bvirt) + (bvirt - dz);
  628. if (adxtail === 0 && bdxtail === 0 && cdxtail === 0 &&
  629. adytail === 0 && bdytail === 0 && cdytail === 0 &&
  630. adztail === 0 && bdztail === 0 && cdztail === 0) {
  631. return det;
  632. }
  633. errbound = o3derrboundC * permanent + resulterrbound * Math.abs(det);
  634. det +=
  635. adz * (bdx * cdytail + cdy * bdxtail - (bdy * cdxtail + cdx * bdytail)) + adztail * (bdx * cdy - bdy * cdx) +
  636. bdz * (cdx * adytail + ady * cdxtail - (cdy * adxtail + adx * cdytail)) + bdztail * (cdx * ady - cdy * adx) +
  637. cdz * (adx * bdytail + bdy * adxtail - (ady * bdxtail + bdx * adytail)) + cdztail * (adx * bdy - ady * bdx);
  638. if (det >= errbound || -det >= errbound) {
  639. return det;
  640. }
  641. const at_len = tailinit(adxtail, adytail, bdx, bdy, cdx, cdy, at_b, at_c);
  642. const bt_len = tailinit(bdxtail, bdytail, cdx, cdy, adx, ady, bt_c, bt_a);
  643. const ct_len = tailinit(cdxtail, cdytail, adx, ady, bdx, bdy, ct_a, ct_b);
  644. const bctlen = sum(bt_len, bt_c, ct_len, ct_b, bct$1);
  645. finlen = finadd$1(finlen, scale(bctlen, bct$1, adz, _16$2), _16$2);
  646. const catlen = sum(ct_len, ct_a, at_len, at_c, cat$1);
  647. finlen = finadd$1(finlen, scale(catlen, cat$1, bdz, _16$2), _16$2);
  648. const abtlen = sum(at_len, at_b, bt_len, bt_a, abt$1);
  649. finlen = finadd$1(finlen, scale(abtlen, abt$1, cdz, _16$2), _16$2);
  650. if (adztail !== 0) {
  651. finlen = finadd$1(finlen, scale(4, bc$2, adztail, _12), _12);
  652. finlen = finadd$1(finlen, scale(bctlen, bct$1, adztail, _16$2), _16$2);
  653. }
  654. if (bdztail !== 0) {
  655. finlen = finadd$1(finlen, scale(4, ca$1, bdztail, _12), _12);
  656. finlen = finadd$1(finlen, scale(catlen, cat$1, bdztail, _16$2), _16$2);
  657. }
  658. if (cdztail !== 0) {
  659. finlen = finadd$1(finlen, scale(4, ab$2, cdztail, _12), _12);
  660. finlen = finadd$1(finlen, scale(abtlen, abt$1, cdztail, _16$2), _16$2);
  661. }
  662. if (adxtail !== 0) {
  663. if (bdytail !== 0) {
  664. finlen = tailadd(finlen, adxtail, bdytail, cdz, cdztail);
  665. }
  666. if (cdytail !== 0) {
  667. finlen = tailadd(finlen, -adxtail, cdytail, bdz, bdztail);
  668. }
  669. }
  670. if (bdxtail !== 0) {
  671. if (cdytail !== 0) {
  672. finlen = tailadd(finlen, bdxtail, cdytail, adz, adztail);
  673. }
  674. if (adytail !== 0) {
  675. finlen = tailadd(finlen, -bdxtail, adytail, cdz, cdztail);
  676. }
  677. }
  678. if (cdxtail !== 0) {
  679. if (adytail !== 0) {
  680. finlen = tailadd(finlen, cdxtail, adytail, bdz, bdztail);
  681. }
  682. if (bdytail !== 0) {
  683. finlen = tailadd(finlen, -cdxtail, bdytail, adz, adztail);
  684. }
  685. }
  686. return fin$2[finlen - 1];
  687. }
  688. function orient3d(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz) {
  689. const adx = ax - dx;
  690. const bdx = bx - dx;
  691. const cdx = cx - dx;
  692. const ady = ay - dy;
  693. const bdy = by - dy;
  694. const cdy = cy - dy;
  695. const adz = az - dz;
  696. const bdz = bz - dz;
  697. const cdz = cz - dz;
  698. const bdxcdy = bdx * cdy;
  699. const cdxbdy = cdx * bdy;
  700. const cdxady = cdx * ady;
  701. const adxcdy = adx * cdy;
  702. const adxbdy = adx * bdy;
  703. const bdxady = bdx * ady;
  704. const det =
  705. adz * (bdxcdy - cdxbdy) +
  706. bdz * (cdxady - adxcdy) +
  707. cdz * (adxbdy - bdxady);
  708. const permanent =
  709. (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * Math.abs(adz) +
  710. (Math.abs(cdxady) + Math.abs(adxcdy)) * Math.abs(bdz) +
  711. (Math.abs(adxbdy) + Math.abs(bdxady)) * Math.abs(cdz);
  712. const errbound = o3derrboundA * permanent;
  713. if (det > errbound || -det > errbound) {
  714. return det;
  715. }
  716. return orient3dadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, permanent);
  717. }
  718. function orient3dfast(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz) {
  719. const adx = ax - dx;
  720. const bdx = bx - dx;
  721. const cdx = cx - dx;
  722. const ady = ay - dy;
  723. const bdy = by - dy;
  724. const cdy = cy - dy;
  725. const adz = az - dz;
  726. const bdz = bz - dz;
  727. const cdz = cz - dz;
  728. return adx * (bdy * cdz - bdz * cdy) +
  729. bdx * (cdy * adz - cdz * ady) +
  730. cdx * (ady * bdz - adz * bdy);
  731. }
  732. const iccerrboundA = (10 + 96 * epsilon) * epsilon;
  733. const iccerrboundB = (4 + 48 * epsilon) * epsilon;
  734. const iccerrboundC = (44 + 576 * epsilon) * epsilon * epsilon;
  735. const bc$1 = vec(4);
  736. const ca = vec(4);
  737. const ab$1 = vec(4);
  738. const aa = vec(4);
  739. const bb = vec(4);
  740. const cc = vec(4);
  741. const u = vec(4);
  742. const v = vec(4);
  743. const axtbc = vec(8);
  744. const aytbc = vec(8);
  745. const bxtca = vec(8);
  746. const bytca = vec(8);
  747. const cxtab = vec(8);
  748. const cytab = vec(8);
  749. const abt = vec(8);
  750. const bct = vec(8);
  751. const cat = vec(8);
  752. const abtt = vec(4);
  753. const bctt = vec(4);
  754. const catt = vec(4);
  755. const _8$1 = vec(8);
  756. const _16$1 = vec(16);
  757. const _16b = vec(16);
  758. const _16c = vec(16);
  759. const _32 = vec(32);
  760. const _32b = vec(32);
  761. const _48$1 = vec(48);
  762. const _64 = vec(64);
  763. let fin$1 = vec(1152);
  764. let fin2 = vec(1152);
  765. function finadd(finlen, a, alen) {
  766. finlen = sum(finlen, fin$1, a, alen, fin2);
  767. const tmp = fin$1; fin$1 = fin2; fin2 = tmp;
  768. return finlen;
  769. }
  770. function incircleadapt(ax, ay, bx, by, cx, cy, dx, dy, permanent) {
  771. let finlen;
  772. let adxtail, bdxtail, cdxtail, adytail, bdytail, cdytail;
  773. let axtbclen, aytbclen, bxtcalen, bytcalen, cxtablen, cytablen;
  774. let abtlen, bctlen, catlen;
  775. let abttlen, bcttlen, cattlen;
  776. let n1, n0;
  777. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  778. const adx = ax - dx;
  779. const bdx = bx - dx;
  780. const cdx = cx - dx;
  781. const ady = ay - dy;
  782. const bdy = by - dy;
  783. const cdy = cy - dy;
  784. s1 = bdx * cdy;
  785. c = splitter * bdx;
  786. ahi = c - (c - bdx);
  787. alo = bdx - ahi;
  788. c = splitter * cdy;
  789. bhi = c - (c - cdy);
  790. blo = cdy - bhi;
  791. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  792. t1 = cdx * bdy;
  793. c = splitter * cdx;
  794. ahi = c - (c - cdx);
  795. alo = cdx - ahi;
  796. c = splitter * bdy;
  797. bhi = c - (c - bdy);
  798. blo = bdy - bhi;
  799. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  800. _i = s0 - t0;
  801. bvirt = s0 - _i;
  802. bc$1[0] = s0 - (_i + bvirt) + (bvirt - t0);
  803. _j = s1 + _i;
  804. bvirt = _j - s1;
  805. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  806. _i = _0 - t1;
  807. bvirt = _0 - _i;
  808. bc$1[1] = _0 - (_i + bvirt) + (bvirt - t1);
  809. u3 = _j + _i;
  810. bvirt = u3 - _j;
  811. bc$1[2] = _j - (u3 - bvirt) + (_i - bvirt);
  812. bc$1[3] = u3;
  813. s1 = cdx * ady;
  814. c = splitter * cdx;
  815. ahi = c - (c - cdx);
  816. alo = cdx - ahi;
  817. c = splitter * ady;
  818. bhi = c - (c - ady);
  819. blo = ady - bhi;
  820. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  821. t1 = adx * cdy;
  822. c = splitter * adx;
  823. ahi = c - (c - adx);
  824. alo = adx - ahi;
  825. c = splitter * cdy;
  826. bhi = c - (c - cdy);
  827. blo = cdy - bhi;
  828. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  829. _i = s0 - t0;
  830. bvirt = s0 - _i;
  831. ca[0] = s0 - (_i + bvirt) + (bvirt - t0);
  832. _j = s1 + _i;
  833. bvirt = _j - s1;
  834. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  835. _i = _0 - t1;
  836. bvirt = _0 - _i;
  837. ca[1] = _0 - (_i + bvirt) + (bvirt - t1);
  838. u3 = _j + _i;
  839. bvirt = u3 - _j;
  840. ca[2] = _j - (u3 - bvirt) + (_i - bvirt);
  841. ca[3] = u3;
  842. s1 = adx * bdy;
  843. c = splitter * adx;
  844. ahi = c - (c - adx);
  845. alo = adx - ahi;
  846. c = splitter * bdy;
  847. bhi = c - (c - bdy);
  848. blo = bdy - bhi;
  849. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  850. t1 = bdx * ady;
  851. c = splitter * bdx;
  852. ahi = c - (c - bdx);
  853. alo = bdx - ahi;
  854. c = splitter * ady;
  855. bhi = c - (c - ady);
  856. blo = ady - bhi;
  857. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  858. _i = s0 - t0;
  859. bvirt = s0 - _i;
  860. ab$1[0] = s0 - (_i + bvirt) + (bvirt - t0);
  861. _j = s1 + _i;
  862. bvirt = _j - s1;
  863. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  864. _i = _0 - t1;
  865. bvirt = _0 - _i;
  866. ab$1[1] = _0 - (_i + bvirt) + (bvirt - t1);
  867. u3 = _j + _i;
  868. bvirt = u3 - _j;
  869. ab$1[2] = _j - (u3 - bvirt) + (_i - bvirt);
  870. ab$1[3] = u3;
  871. finlen = sum(
  872. sum(
  873. sum(
  874. scale(scale(4, bc$1, adx, _8$1), _8$1, adx, _16$1), _16$1,
  875. scale(scale(4, bc$1, ady, _8$1), _8$1, ady, _16b), _16b, _32), _32,
  876. sum(
  877. scale(scale(4, ca, bdx, _8$1), _8$1, bdx, _16$1), _16$1,
  878. scale(scale(4, ca, bdy, _8$1), _8$1, bdy, _16b), _16b, _32b), _32b, _64), _64,
  879. sum(
  880. scale(scale(4, ab$1, cdx, _8$1), _8$1, cdx, _16$1), _16$1,
  881. scale(scale(4, ab$1, cdy, _8$1), _8$1, cdy, _16b), _16b, _32), _32, fin$1);
  882. let det = estimate(finlen, fin$1);
  883. let errbound = iccerrboundB * permanent;
  884. if (det >= errbound || -det >= errbound) {
  885. return det;
  886. }
  887. bvirt = ax - adx;
  888. adxtail = ax - (adx + bvirt) + (bvirt - dx);
  889. bvirt = ay - ady;
  890. adytail = ay - (ady + bvirt) + (bvirt - dy);
  891. bvirt = bx - bdx;
  892. bdxtail = bx - (bdx + bvirt) + (bvirt - dx);
  893. bvirt = by - bdy;
  894. bdytail = by - (bdy + bvirt) + (bvirt - dy);
  895. bvirt = cx - cdx;
  896. cdxtail = cx - (cdx + bvirt) + (bvirt - dx);
  897. bvirt = cy - cdy;
  898. cdytail = cy - (cdy + bvirt) + (bvirt - dy);
  899. if (adxtail === 0 && bdxtail === 0 && cdxtail === 0 && adytail === 0 && bdytail === 0 && cdytail === 0) {
  900. return det;
  901. }
  902. errbound = iccerrboundC * permanent + resulterrbound * Math.abs(det);
  903. det += ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) +
  904. 2 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx)) +
  905. ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) +
  906. 2 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx)) +
  907. ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) +
  908. 2 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx));
  909. if (det >= errbound || -det >= errbound) {
  910. return det;
  911. }
  912. if (bdxtail !== 0 || bdytail !== 0 || cdxtail !== 0 || cdytail !== 0) {
  913. s1 = adx * adx;
  914. c = splitter * adx;
  915. ahi = c - (c - adx);
  916. alo = adx - ahi;
  917. s0 = alo * alo - (s1 - ahi * ahi - (ahi + ahi) * alo);
  918. t1 = ady * ady;
  919. c = splitter * ady;
  920. ahi = c - (c - ady);
  921. alo = ady - ahi;
  922. t0 = alo * alo - (t1 - ahi * ahi - (ahi + ahi) * alo);
  923. _i = s0 + t0;
  924. bvirt = _i - s0;
  925. aa[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  926. _j = s1 + _i;
  927. bvirt = _j - s1;
  928. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  929. _i = _0 + t1;
  930. bvirt = _i - _0;
  931. aa[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  932. u3 = _j + _i;
  933. bvirt = u3 - _j;
  934. aa[2] = _j - (u3 - bvirt) + (_i - bvirt);
  935. aa[3] = u3;
  936. }
  937. if (cdxtail !== 0 || cdytail !== 0 || adxtail !== 0 || adytail !== 0) {
  938. s1 = bdx * bdx;
  939. c = splitter * bdx;
  940. ahi = c - (c - bdx);
  941. alo = bdx - ahi;
  942. s0 = alo * alo - (s1 - ahi * ahi - (ahi + ahi) * alo);
  943. t1 = bdy * bdy;
  944. c = splitter * bdy;
  945. ahi = c - (c - bdy);
  946. alo = bdy - ahi;
  947. t0 = alo * alo - (t1 - ahi * ahi - (ahi + ahi) * alo);
  948. _i = s0 + t0;
  949. bvirt = _i - s0;
  950. bb[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  951. _j = s1 + _i;
  952. bvirt = _j - s1;
  953. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  954. _i = _0 + t1;
  955. bvirt = _i - _0;
  956. bb[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  957. u3 = _j + _i;
  958. bvirt = u3 - _j;
  959. bb[2] = _j - (u3 - bvirt) + (_i - bvirt);
  960. bb[3] = u3;
  961. }
  962. if (adxtail !== 0 || adytail !== 0 || bdxtail !== 0 || bdytail !== 0) {
  963. s1 = cdx * cdx;
  964. c = splitter * cdx;
  965. ahi = c - (c - cdx);
  966. alo = cdx - ahi;
  967. s0 = alo * alo - (s1 - ahi * ahi - (ahi + ahi) * alo);
  968. t1 = cdy * cdy;
  969. c = splitter * cdy;
  970. ahi = c - (c - cdy);
  971. alo = cdy - ahi;
  972. t0 = alo * alo - (t1 - ahi * ahi - (ahi + ahi) * alo);
  973. _i = s0 + t0;
  974. bvirt = _i - s0;
  975. cc[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  976. _j = s1 + _i;
  977. bvirt = _j - s1;
  978. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  979. _i = _0 + t1;
  980. bvirt = _i - _0;
  981. cc[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  982. u3 = _j + _i;
  983. bvirt = u3 - _j;
  984. cc[2] = _j - (u3 - bvirt) + (_i - bvirt);
  985. cc[3] = u3;
  986. }
  987. if (adxtail !== 0) {
  988. axtbclen = scale(4, bc$1, adxtail, axtbc);
  989. finlen = finadd(finlen, sum_three(
  990. scale(axtbclen, axtbc, 2 * adx, _16$1), _16$1,
  991. scale(scale(4, cc, adxtail, _8$1), _8$1, bdy, _16b), _16b,
  992. scale(scale(4, bb, adxtail, _8$1), _8$1, -cdy, _16c), _16c, _32, _48$1), _48$1);
  993. }
  994. if (adytail !== 0) {
  995. aytbclen = scale(4, bc$1, adytail, aytbc);
  996. finlen = finadd(finlen, sum_three(
  997. scale(aytbclen, aytbc, 2 * ady, _16$1), _16$1,
  998. scale(scale(4, bb, adytail, _8$1), _8$1, cdx, _16b), _16b,
  999. scale(scale(4, cc, adytail, _8$1), _8$1, -bdx, _16c), _16c, _32, _48$1), _48$1);
  1000. }
  1001. if (bdxtail !== 0) {
  1002. bxtcalen = scale(4, ca, bdxtail, bxtca);
  1003. finlen = finadd(finlen, sum_three(
  1004. scale(bxtcalen, bxtca, 2 * bdx, _16$1), _16$1,
  1005. scale(scale(4, aa, bdxtail, _8$1), _8$1, cdy, _16b), _16b,
  1006. scale(scale(4, cc, bdxtail, _8$1), _8$1, -ady, _16c), _16c, _32, _48$1), _48$1);
  1007. }
  1008. if (bdytail !== 0) {
  1009. bytcalen = scale(4, ca, bdytail, bytca);
  1010. finlen = finadd(finlen, sum_three(
  1011. scale(bytcalen, bytca, 2 * bdy, _16$1), _16$1,
  1012. scale(scale(4, cc, bdytail, _8$1), _8$1, adx, _16b), _16b,
  1013. scale(scale(4, aa, bdytail, _8$1), _8$1, -cdx, _16c), _16c, _32, _48$1), _48$1);
  1014. }
  1015. if (cdxtail !== 0) {
  1016. cxtablen = scale(4, ab$1, cdxtail, cxtab);
  1017. finlen = finadd(finlen, sum_three(
  1018. scale(cxtablen, cxtab, 2 * cdx, _16$1), _16$1,
  1019. scale(scale(4, bb, cdxtail, _8$1), _8$1, ady, _16b), _16b,
  1020. scale(scale(4, aa, cdxtail, _8$1), _8$1, -bdy, _16c), _16c, _32, _48$1), _48$1);
  1021. }
  1022. if (cdytail !== 0) {
  1023. cytablen = scale(4, ab$1, cdytail, cytab);
  1024. finlen = finadd(finlen, sum_three(
  1025. scale(cytablen, cytab, 2 * cdy, _16$1), _16$1,
  1026. scale(scale(4, aa, cdytail, _8$1), _8$1, bdx, _16b), _16b,
  1027. scale(scale(4, bb, cdytail, _8$1), _8$1, -adx, _16c), _16c, _32, _48$1), _48$1);
  1028. }
  1029. if (adxtail !== 0 || adytail !== 0) {
  1030. if (bdxtail !== 0 || bdytail !== 0 || cdxtail !== 0 || cdytail !== 0) {
  1031. s1 = bdxtail * cdy;
  1032. c = splitter * bdxtail;
  1033. ahi = c - (c - bdxtail);
  1034. alo = bdxtail - ahi;
  1035. c = splitter * cdy;
  1036. bhi = c - (c - cdy);
  1037. blo = cdy - bhi;
  1038. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1039. t1 = bdx * cdytail;
  1040. c = splitter * bdx;
  1041. ahi = c - (c - bdx);
  1042. alo = bdx - ahi;
  1043. c = splitter * cdytail;
  1044. bhi = c - (c - cdytail);
  1045. blo = cdytail - bhi;
  1046. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1047. _i = s0 + t0;
  1048. bvirt = _i - s0;
  1049. u[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  1050. _j = s1 + _i;
  1051. bvirt = _j - s1;
  1052. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1053. _i = _0 + t1;
  1054. bvirt = _i - _0;
  1055. u[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  1056. u3 = _j + _i;
  1057. bvirt = u3 - _j;
  1058. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1059. u[3] = u3;
  1060. s1 = cdxtail * -bdy;
  1061. c = splitter * cdxtail;
  1062. ahi = c - (c - cdxtail);
  1063. alo = cdxtail - ahi;
  1064. c = splitter * -bdy;
  1065. bhi = c - (c - -bdy);
  1066. blo = -bdy - bhi;
  1067. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1068. t1 = cdx * -bdytail;
  1069. c = splitter * cdx;
  1070. ahi = c - (c - cdx);
  1071. alo = cdx - ahi;
  1072. c = splitter * -bdytail;
  1073. bhi = c - (c - -bdytail);
  1074. blo = -bdytail - bhi;
  1075. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1076. _i = s0 + t0;
  1077. bvirt = _i - s0;
  1078. v[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  1079. _j = s1 + _i;
  1080. bvirt = _j - s1;
  1081. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1082. _i = _0 + t1;
  1083. bvirt = _i - _0;
  1084. v[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  1085. u3 = _j + _i;
  1086. bvirt = u3 - _j;
  1087. v[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1088. v[3] = u3;
  1089. bctlen = sum(4, u, 4, v, bct);
  1090. s1 = bdxtail * cdytail;
  1091. c = splitter * bdxtail;
  1092. ahi = c - (c - bdxtail);
  1093. alo = bdxtail - ahi;
  1094. c = splitter * cdytail;
  1095. bhi = c - (c - cdytail);
  1096. blo = cdytail - bhi;
  1097. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1098. t1 = cdxtail * bdytail;
  1099. c = splitter * cdxtail;
  1100. ahi = c - (c - cdxtail);
  1101. alo = cdxtail - ahi;
  1102. c = splitter * bdytail;
  1103. bhi = c - (c - bdytail);
  1104. blo = bdytail - bhi;
  1105. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1106. _i = s0 - t0;
  1107. bvirt = s0 - _i;
  1108. bctt[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1109. _j = s1 + _i;
  1110. bvirt = _j - s1;
  1111. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1112. _i = _0 - t1;
  1113. bvirt = _0 - _i;
  1114. bctt[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1115. u3 = _j + _i;
  1116. bvirt = u3 - _j;
  1117. bctt[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1118. bctt[3] = u3;
  1119. bcttlen = 4;
  1120. } else {
  1121. bct[0] = 0;
  1122. bctlen = 1;
  1123. bctt[0] = 0;
  1124. bcttlen = 1;
  1125. }
  1126. if (adxtail !== 0) {
  1127. const len = scale(bctlen, bct, adxtail, _16c);
  1128. finlen = finadd(finlen, sum(
  1129. scale(axtbclen, axtbc, adxtail, _16$1), _16$1,
  1130. scale(len, _16c, 2 * adx, _32), _32, _48$1), _48$1);
  1131. const len2 = scale(bcttlen, bctt, adxtail, _8$1);
  1132. finlen = finadd(finlen, sum_three(
  1133. scale(len2, _8$1, 2 * adx, _16$1), _16$1,
  1134. scale(len2, _8$1, adxtail, _16b), _16b,
  1135. scale(len, _16c, adxtail, _32), _32, _32b, _64), _64);
  1136. if (bdytail !== 0) {
  1137. finlen = finadd(finlen, scale(scale(4, cc, adxtail, _8$1), _8$1, bdytail, _16$1), _16$1);
  1138. }
  1139. if (cdytail !== 0) {
  1140. finlen = finadd(finlen, scale(scale(4, bb, -adxtail, _8$1), _8$1, cdytail, _16$1), _16$1);
  1141. }
  1142. }
  1143. if (adytail !== 0) {
  1144. const len = scale(bctlen, bct, adytail, _16c);
  1145. finlen = finadd(finlen, sum(
  1146. scale(aytbclen, aytbc, adytail, _16$1), _16$1,
  1147. scale(len, _16c, 2 * ady, _32), _32, _48$1), _48$1);
  1148. const len2 = scale(bcttlen, bctt, adytail, _8$1);
  1149. finlen = finadd(finlen, sum_three(
  1150. scale(len2, _8$1, 2 * ady, _16$1), _16$1,
  1151. scale(len2, _8$1, adytail, _16b), _16b,
  1152. scale(len, _16c, adytail, _32), _32, _32b, _64), _64);
  1153. }
  1154. }
  1155. if (bdxtail !== 0 || bdytail !== 0) {
  1156. if (cdxtail !== 0 || cdytail !== 0 || adxtail !== 0 || adytail !== 0) {
  1157. s1 = cdxtail * ady;
  1158. c = splitter * cdxtail;
  1159. ahi = c - (c - cdxtail);
  1160. alo = cdxtail - ahi;
  1161. c = splitter * ady;
  1162. bhi = c - (c - ady);
  1163. blo = ady - bhi;
  1164. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1165. t1 = cdx * adytail;
  1166. c = splitter * cdx;
  1167. ahi = c - (c - cdx);
  1168. alo = cdx - ahi;
  1169. c = splitter * adytail;
  1170. bhi = c - (c - adytail);
  1171. blo = adytail - bhi;
  1172. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1173. _i = s0 + t0;
  1174. bvirt = _i - s0;
  1175. u[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  1176. _j = s1 + _i;
  1177. bvirt = _j - s1;
  1178. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1179. _i = _0 + t1;
  1180. bvirt = _i - _0;
  1181. u[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  1182. u3 = _j + _i;
  1183. bvirt = u3 - _j;
  1184. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1185. u[3] = u3;
  1186. n1 = -cdy;
  1187. n0 = -cdytail;
  1188. s1 = adxtail * n1;
  1189. c = splitter * adxtail;
  1190. ahi = c - (c - adxtail);
  1191. alo = adxtail - ahi;
  1192. c = splitter * n1;
  1193. bhi = c - (c - n1);
  1194. blo = n1 - bhi;
  1195. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1196. t1 = adx * n0;
  1197. c = splitter * adx;
  1198. ahi = c - (c - adx);
  1199. alo = adx - ahi;
  1200. c = splitter * n0;
  1201. bhi = c - (c - n0);
  1202. blo = n0 - bhi;
  1203. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1204. _i = s0 + t0;
  1205. bvirt = _i - s0;
  1206. v[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  1207. _j = s1 + _i;
  1208. bvirt = _j - s1;
  1209. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1210. _i = _0 + t1;
  1211. bvirt = _i - _0;
  1212. v[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  1213. u3 = _j + _i;
  1214. bvirt = u3 - _j;
  1215. v[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1216. v[3] = u3;
  1217. catlen = sum(4, u, 4, v, cat);
  1218. s1 = cdxtail * adytail;
  1219. c = splitter * cdxtail;
  1220. ahi = c - (c - cdxtail);
  1221. alo = cdxtail - ahi;
  1222. c = splitter * adytail;
  1223. bhi = c - (c - adytail);
  1224. blo = adytail - bhi;
  1225. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1226. t1 = adxtail * cdytail;
  1227. c = splitter * adxtail;
  1228. ahi = c - (c - adxtail);
  1229. alo = adxtail - ahi;
  1230. c = splitter * cdytail;
  1231. bhi = c - (c - cdytail);
  1232. blo = cdytail - bhi;
  1233. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1234. _i = s0 - t0;
  1235. bvirt = s0 - _i;
  1236. catt[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1237. _j = s1 + _i;
  1238. bvirt = _j - s1;
  1239. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1240. _i = _0 - t1;
  1241. bvirt = _0 - _i;
  1242. catt[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1243. u3 = _j + _i;
  1244. bvirt = u3 - _j;
  1245. catt[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1246. catt[3] = u3;
  1247. cattlen = 4;
  1248. } else {
  1249. cat[0] = 0;
  1250. catlen = 1;
  1251. catt[0] = 0;
  1252. cattlen = 1;
  1253. }
  1254. if (bdxtail !== 0) {
  1255. const len = scale(catlen, cat, bdxtail, _16c);
  1256. finlen = finadd(finlen, sum(
  1257. scale(bxtcalen, bxtca, bdxtail, _16$1), _16$1,
  1258. scale(len, _16c, 2 * bdx, _32), _32, _48$1), _48$1);
  1259. const len2 = scale(cattlen, catt, bdxtail, _8$1);
  1260. finlen = finadd(finlen, sum_three(
  1261. scale(len2, _8$1, 2 * bdx, _16$1), _16$1,
  1262. scale(len2, _8$1, bdxtail, _16b), _16b,
  1263. scale(len, _16c, bdxtail, _32), _32, _32b, _64), _64);
  1264. if (cdytail !== 0) {
  1265. finlen = finadd(finlen, scale(scale(4, aa, bdxtail, _8$1), _8$1, cdytail, _16$1), _16$1);
  1266. }
  1267. if (adytail !== 0) {
  1268. finlen = finadd(finlen, scale(scale(4, cc, -bdxtail, _8$1), _8$1, adytail, _16$1), _16$1);
  1269. }
  1270. }
  1271. if (bdytail !== 0) {
  1272. const len = scale(catlen, cat, bdytail, _16c);
  1273. finlen = finadd(finlen, sum(
  1274. scale(bytcalen, bytca, bdytail, _16$1), _16$1,
  1275. scale(len, _16c, 2 * bdy, _32), _32, _48$1), _48$1);
  1276. const len2 = scale(cattlen, catt, bdytail, _8$1);
  1277. finlen = finadd(finlen, sum_three(
  1278. scale(len2, _8$1, 2 * bdy, _16$1), _16$1,
  1279. scale(len2, _8$1, bdytail, _16b), _16b,
  1280. scale(len, _16c, bdytail, _32), _32, _32b, _64), _64);
  1281. }
  1282. }
  1283. if (cdxtail !== 0 || cdytail !== 0) {
  1284. if (adxtail !== 0 || adytail !== 0 || bdxtail !== 0 || bdytail !== 0) {
  1285. s1 = adxtail * bdy;
  1286. c = splitter * adxtail;
  1287. ahi = c - (c - adxtail);
  1288. alo = adxtail - ahi;
  1289. c = splitter * bdy;
  1290. bhi = c - (c - bdy);
  1291. blo = bdy - bhi;
  1292. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1293. t1 = adx * bdytail;
  1294. c = splitter * adx;
  1295. ahi = c - (c - adx);
  1296. alo = adx - ahi;
  1297. c = splitter * bdytail;
  1298. bhi = c - (c - bdytail);
  1299. blo = bdytail - bhi;
  1300. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1301. _i = s0 + t0;
  1302. bvirt = _i - s0;
  1303. u[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  1304. _j = s1 + _i;
  1305. bvirt = _j - s1;
  1306. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1307. _i = _0 + t1;
  1308. bvirt = _i - _0;
  1309. u[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  1310. u3 = _j + _i;
  1311. bvirt = u3 - _j;
  1312. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1313. u[3] = u3;
  1314. n1 = -ady;
  1315. n0 = -adytail;
  1316. s1 = bdxtail * n1;
  1317. c = splitter * bdxtail;
  1318. ahi = c - (c - bdxtail);
  1319. alo = bdxtail - ahi;
  1320. c = splitter * n1;
  1321. bhi = c - (c - n1);
  1322. blo = n1 - bhi;
  1323. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1324. t1 = bdx * n0;
  1325. c = splitter * bdx;
  1326. ahi = c - (c - bdx);
  1327. alo = bdx - ahi;
  1328. c = splitter * n0;
  1329. bhi = c - (c - n0);
  1330. blo = n0 - bhi;
  1331. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1332. _i = s0 + t0;
  1333. bvirt = _i - s0;
  1334. v[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  1335. _j = s1 + _i;
  1336. bvirt = _j - s1;
  1337. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1338. _i = _0 + t1;
  1339. bvirt = _i - _0;
  1340. v[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  1341. u3 = _j + _i;
  1342. bvirt = u3 - _j;
  1343. v[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1344. v[3] = u3;
  1345. abtlen = sum(4, u, 4, v, abt);
  1346. s1 = adxtail * bdytail;
  1347. c = splitter * adxtail;
  1348. ahi = c - (c - adxtail);
  1349. alo = adxtail - ahi;
  1350. c = splitter * bdytail;
  1351. bhi = c - (c - bdytail);
  1352. blo = bdytail - bhi;
  1353. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1354. t1 = bdxtail * adytail;
  1355. c = splitter * bdxtail;
  1356. ahi = c - (c - bdxtail);
  1357. alo = bdxtail - ahi;
  1358. c = splitter * adytail;
  1359. bhi = c - (c - adytail);
  1360. blo = adytail - bhi;
  1361. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1362. _i = s0 - t0;
  1363. bvirt = s0 - _i;
  1364. abtt[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1365. _j = s1 + _i;
  1366. bvirt = _j - s1;
  1367. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1368. _i = _0 - t1;
  1369. bvirt = _0 - _i;
  1370. abtt[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1371. u3 = _j + _i;
  1372. bvirt = u3 - _j;
  1373. abtt[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1374. abtt[3] = u3;
  1375. abttlen = 4;
  1376. } else {
  1377. abt[0] = 0;
  1378. abtlen = 1;
  1379. abtt[0] = 0;
  1380. abttlen = 1;
  1381. }
  1382. if (cdxtail !== 0) {
  1383. const len = scale(abtlen, abt, cdxtail, _16c);
  1384. finlen = finadd(finlen, sum(
  1385. scale(cxtablen, cxtab, cdxtail, _16$1), _16$1,
  1386. scale(len, _16c, 2 * cdx, _32), _32, _48$1), _48$1);
  1387. const len2 = scale(abttlen, abtt, cdxtail, _8$1);
  1388. finlen = finadd(finlen, sum_three(
  1389. scale(len2, _8$1, 2 * cdx, _16$1), _16$1,
  1390. scale(len2, _8$1, cdxtail, _16b), _16b,
  1391. scale(len, _16c, cdxtail, _32), _32, _32b, _64), _64);
  1392. if (adytail !== 0) {
  1393. finlen = finadd(finlen, scale(scale(4, bb, cdxtail, _8$1), _8$1, adytail, _16$1), _16$1);
  1394. }
  1395. if (bdytail !== 0) {
  1396. finlen = finadd(finlen, scale(scale(4, aa, -cdxtail, _8$1), _8$1, bdytail, _16$1), _16$1);
  1397. }
  1398. }
  1399. if (cdytail !== 0) {
  1400. const len = scale(abtlen, abt, cdytail, _16c);
  1401. finlen = finadd(finlen, sum(
  1402. scale(cytablen, cytab, cdytail, _16$1), _16$1,
  1403. scale(len, _16c, 2 * cdy, _32), _32, _48$1), _48$1);
  1404. const len2 = scale(abttlen, abtt, cdytail, _8$1);
  1405. finlen = finadd(finlen, sum_three(
  1406. scale(len2, _8$1, 2 * cdy, _16$1), _16$1,
  1407. scale(len2, _8$1, cdytail, _16b), _16b,
  1408. scale(len, _16c, cdytail, _32), _32, _32b, _64), _64);
  1409. }
  1410. }
  1411. return fin$1[finlen - 1];
  1412. }
  1413. function incircle(ax, ay, bx, by, cx, cy, dx, dy) {
  1414. const adx = ax - dx;
  1415. const bdx = bx - dx;
  1416. const cdx = cx - dx;
  1417. const ady = ay - dy;
  1418. const bdy = by - dy;
  1419. const cdy = cy - dy;
  1420. const bdxcdy = bdx * cdy;
  1421. const cdxbdy = cdx * bdy;
  1422. const alift = adx * adx + ady * ady;
  1423. const cdxady = cdx * ady;
  1424. const adxcdy = adx * cdy;
  1425. const blift = bdx * bdx + bdy * bdy;
  1426. const adxbdy = adx * bdy;
  1427. const bdxady = bdx * ady;
  1428. const clift = cdx * cdx + cdy * cdy;
  1429. const det =
  1430. alift * (bdxcdy - cdxbdy) +
  1431. blift * (cdxady - adxcdy) +
  1432. clift * (adxbdy - bdxady);
  1433. const permanent =
  1434. (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * alift +
  1435. (Math.abs(cdxady) + Math.abs(adxcdy)) * blift +
  1436. (Math.abs(adxbdy) + Math.abs(bdxady)) * clift;
  1437. const errbound = iccerrboundA * permanent;
  1438. if (det > errbound || -det > errbound) {
  1439. return det;
  1440. }
  1441. return incircleadapt(ax, ay, bx, by, cx, cy, dx, dy, permanent);
  1442. }
  1443. function incirclefast(ax, ay, bx, by, cx, cy, dx, dy) {
  1444. const adx = ax - dx;
  1445. const ady = ay - dy;
  1446. const bdx = bx - dx;
  1447. const bdy = by - dy;
  1448. const cdx = cx - dx;
  1449. const cdy = cy - dy;
  1450. const abdet = adx * bdy - bdx * ady;
  1451. const bcdet = bdx * cdy - cdx * bdy;
  1452. const cadet = cdx * ady - adx * cdy;
  1453. const alift = adx * adx + ady * ady;
  1454. const blift = bdx * bdx + bdy * bdy;
  1455. const clift = cdx * cdx + cdy * cdy;
  1456. return alift * bcdet + blift * cadet + clift * abdet;
  1457. }
  1458. const isperrboundA = (16 + 224 * epsilon) * epsilon;
  1459. const isperrboundB = (5 + 72 * epsilon) * epsilon;
  1460. const isperrboundC = (71 + 1408 * epsilon) * epsilon * epsilon;
  1461. const ab = vec(4);
  1462. const bc = vec(4);
  1463. const cd = vec(4);
  1464. const de = vec(4);
  1465. const ea = vec(4);
  1466. const ac = vec(4);
  1467. const bd = vec(4);
  1468. const ce = vec(4);
  1469. const da = vec(4);
  1470. const eb = vec(4);
  1471. const abc = vec(24);
  1472. const bcd = vec(24);
  1473. const cde = vec(24);
  1474. const dea = vec(24);
  1475. const eab = vec(24);
  1476. const abd = vec(24);
  1477. const bce = vec(24);
  1478. const cda = vec(24);
  1479. const deb = vec(24);
  1480. const eac = vec(24);
  1481. const adet = vec(1152);
  1482. const bdet = vec(1152);
  1483. const cdet = vec(1152);
  1484. const ddet = vec(1152);
  1485. const edet = vec(1152);
  1486. const abdet = vec(2304);
  1487. const cddet = vec(2304);
  1488. const cdedet = vec(3456);
  1489. const deter = vec(5760);
  1490. const _8 = vec(8);
  1491. const _8b = vec(8);
  1492. const _8c = vec(8);
  1493. const _16 = vec(16);
  1494. const _24 = vec(24);
  1495. const _48 = vec(48);
  1496. const _48b = vec(48);
  1497. const _96 = vec(96);
  1498. const _192 = vec(192);
  1499. const _384x = vec(384);
  1500. const _384y = vec(384);
  1501. const _384z = vec(384);
  1502. const _768 = vec(768);
  1503. function sum_three_scale(a, b, c, az, bz, cz, out) {
  1504. return sum_three(
  1505. scale(4, a, az, _8), _8,
  1506. scale(4, b, bz, _8b), _8b,
  1507. scale(4, c, cz, _8c), _8c, _16, out);
  1508. }
  1509. function liftexact(alen, a, blen, b, clen, c, dlen, d, x, y, z, out) {
  1510. const len = sum(
  1511. sum(alen, a, blen, b, _48), _48,
  1512. negate(sum(clen, c, dlen, d, _48b), _48b), _48b, _96);
  1513. return sum_three(
  1514. scale(scale(len, _96, x, _192), _192, x, _384x), _384x,
  1515. scale(scale(len, _96, y, _192), _192, y, _384y), _384y,
  1516. scale(scale(len, _96, z, _192), _192, z, _384z), _384z, _768, out);
  1517. }
  1518. function insphereexact(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez) {
  1519. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  1520. s1 = ax * by;
  1521. c = splitter * ax;
  1522. ahi = c - (c - ax);
  1523. alo = ax - ahi;
  1524. c = splitter * by;
  1525. bhi = c - (c - by);
  1526. blo = by - bhi;
  1527. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1528. t1 = bx * ay;
  1529. c = splitter * bx;
  1530. ahi = c - (c - bx);
  1531. alo = bx - ahi;
  1532. c = splitter * ay;
  1533. bhi = c - (c - ay);
  1534. blo = ay - bhi;
  1535. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1536. _i = s0 - t0;
  1537. bvirt = s0 - _i;
  1538. ab[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1539. _j = s1 + _i;
  1540. bvirt = _j - s1;
  1541. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1542. _i = _0 - t1;
  1543. bvirt = _0 - _i;
  1544. ab[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1545. u3 = _j + _i;
  1546. bvirt = u3 - _j;
  1547. ab[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1548. ab[3] = u3;
  1549. s1 = bx * cy;
  1550. c = splitter * bx;
  1551. ahi = c - (c - bx);
  1552. alo = bx - ahi;
  1553. c = splitter * cy;
  1554. bhi = c - (c - cy);
  1555. blo = cy - bhi;
  1556. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1557. t1 = cx * by;
  1558. c = splitter * cx;
  1559. ahi = c - (c - cx);
  1560. alo = cx - ahi;
  1561. c = splitter * by;
  1562. bhi = c - (c - by);
  1563. blo = by - bhi;
  1564. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1565. _i = s0 - t0;
  1566. bvirt = s0 - _i;
  1567. bc[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1568. _j = s1 + _i;
  1569. bvirt = _j - s1;
  1570. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1571. _i = _0 - t1;
  1572. bvirt = _0 - _i;
  1573. bc[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1574. u3 = _j + _i;
  1575. bvirt = u3 - _j;
  1576. bc[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1577. bc[3] = u3;
  1578. s1 = cx * dy;
  1579. c = splitter * cx;
  1580. ahi = c - (c - cx);
  1581. alo = cx - ahi;
  1582. c = splitter * dy;
  1583. bhi = c - (c - dy);
  1584. blo = dy - bhi;
  1585. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1586. t1 = dx * cy;
  1587. c = splitter * dx;
  1588. ahi = c - (c - dx);
  1589. alo = dx - ahi;
  1590. c = splitter * cy;
  1591. bhi = c - (c - cy);
  1592. blo = cy - bhi;
  1593. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1594. _i = s0 - t0;
  1595. bvirt = s0 - _i;
  1596. cd[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1597. _j = s1 + _i;
  1598. bvirt = _j - s1;
  1599. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1600. _i = _0 - t1;
  1601. bvirt = _0 - _i;
  1602. cd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1603. u3 = _j + _i;
  1604. bvirt = u3 - _j;
  1605. cd[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1606. cd[3] = u3;
  1607. s1 = dx * ey;
  1608. c = splitter * dx;
  1609. ahi = c - (c - dx);
  1610. alo = dx - ahi;
  1611. c = splitter * ey;
  1612. bhi = c - (c - ey);
  1613. blo = ey - bhi;
  1614. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1615. t1 = ex * dy;
  1616. c = splitter * ex;
  1617. ahi = c - (c - ex);
  1618. alo = ex - ahi;
  1619. c = splitter * dy;
  1620. bhi = c - (c - dy);
  1621. blo = dy - bhi;
  1622. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1623. _i = s0 - t0;
  1624. bvirt = s0 - _i;
  1625. de[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1626. _j = s1 + _i;
  1627. bvirt = _j - s1;
  1628. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1629. _i = _0 - t1;
  1630. bvirt = _0 - _i;
  1631. de[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1632. u3 = _j + _i;
  1633. bvirt = u3 - _j;
  1634. de[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1635. de[3] = u3;
  1636. s1 = ex * ay;
  1637. c = splitter * ex;
  1638. ahi = c - (c - ex);
  1639. alo = ex - ahi;
  1640. c = splitter * ay;
  1641. bhi = c - (c - ay);
  1642. blo = ay - bhi;
  1643. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1644. t1 = ax * ey;
  1645. c = splitter * ax;
  1646. ahi = c - (c - ax);
  1647. alo = ax - ahi;
  1648. c = splitter * ey;
  1649. bhi = c - (c - ey);
  1650. blo = ey - bhi;
  1651. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1652. _i = s0 - t0;
  1653. bvirt = s0 - _i;
  1654. ea[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1655. _j = s1 + _i;
  1656. bvirt = _j - s1;
  1657. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1658. _i = _0 - t1;
  1659. bvirt = _0 - _i;
  1660. ea[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1661. u3 = _j + _i;
  1662. bvirt = u3 - _j;
  1663. ea[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1664. ea[3] = u3;
  1665. s1 = ax * cy;
  1666. c = splitter * ax;
  1667. ahi = c - (c - ax);
  1668. alo = ax - ahi;
  1669. c = splitter * cy;
  1670. bhi = c - (c - cy);
  1671. blo = cy - bhi;
  1672. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1673. t1 = cx * ay;
  1674. c = splitter * cx;
  1675. ahi = c - (c - cx);
  1676. alo = cx - ahi;
  1677. c = splitter * ay;
  1678. bhi = c - (c - ay);
  1679. blo = ay - bhi;
  1680. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1681. _i = s0 - t0;
  1682. bvirt = s0 - _i;
  1683. ac[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1684. _j = s1 + _i;
  1685. bvirt = _j - s1;
  1686. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1687. _i = _0 - t1;
  1688. bvirt = _0 - _i;
  1689. ac[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1690. u3 = _j + _i;
  1691. bvirt = u3 - _j;
  1692. ac[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1693. ac[3] = u3;
  1694. s1 = bx * dy;
  1695. c = splitter * bx;
  1696. ahi = c - (c - bx);
  1697. alo = bx - ahi;
  1698. c = splitter * dy;
  1699. bhi = c - (c - dy);
  1700. blo = dy - bhi;
  1701. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1702. t1 = dx * by;
  1703. c = splitter * dx;
  1704. ahi = c - (c - dx);
  1705. alo = dx - ahi;
  1706. c = splitter * by;
  1707. bhi = c - (c - by);
  1708. blo = by - bhi;
  1709. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1710. _i = s0 - t0;
  1711. bvirt = s0 - _i;
  1712. bd[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1713. _j = s1 + _i;
  1714. bvirt = _j - s1;
  1715. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1716. _i = _0 - t1;
  1717. bvirt = _0 - _i;
  1718. bd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1719. u3 = _j + _i;
  1720. bvirt = u3 - _j;
  1721. bd[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1722. bd[3] = u3;
  1723. s1 = cx * ey;
  1724. c = splitter * cx;
  1725. ahi = c - (c - cx);
  1726. alo = cx - ahi;
  1727. c = splitter * ey;
  1728. bhi = c - (c - ey);
  1729. blo = ey - bhi;
  1730. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1731. t1 = ex * cy;
  1732. c = splitter * ex;
  1733. ahi = c - (c - ex);
  1734. alo = ex - ahi;
  1735. c = splitter * cy;
  1736. bhi = c - (c - cy);
  1737. blo = cy - bhi;
  1738. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1739. _i = s0 - t0;
  1740. bvirt = s0 - _i;
  1741. ce[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1742. _j = s1 + _i;
  1743. bvirt = _j - s1;
  1744. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1745. _i = _0 - t1;
  1746. bvirt = _0 - _i;
  1747. ce[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1748. u3 = _j + _i;
  1749. bvirt = u3 - _j;
  1750. ce[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1751. ce[3] = u3;
  1752. s1 = dx * ay;
  1753. c = splitter * dx;
  1754. ahi = c - (c - dx);
  1755. alo = dx - ahi;
  1756. c = splitter * ay;
  1757. bhi = c - (c - ay);
  1758. blo = ay - bhi;
  1759. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1760. t1 = ax * dy;
  1761. c = splitter * ax;
  1762. ahi = c - (c - ax);
  1763. alo = ax - ahi;
  1764. c = splitter * dy;
  1765. bhi = c - (c - dy);
  1766. blo = dy - bhi;
  1767. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1768. _i = s0 - t0;
  1769. bvirt = s0 - _i;
  1770. da[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1771. _j = s1 + _i;
  1772. bvirt = _j - s1;
  1773. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1774. _i = _0 - t1;
  1775. bvirt = _0 - _i;
  1776. da[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1777. u3 = _j + _i;
  1778. bvirt = u3 - _j;
  1779. da[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1780. da[3] = u3;
  1781. s1 = ex * by;
  1782. c = splitter * ex;
  1783. ahi = c - (c - ex);
  1784. alo = ex - ahi;
  1785. c = splitter * by;
  1786. bhi = c - (c - by);
  1787. blo = by - bhi;
  1788. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1789. t1 = bx * ey;
  1790. c = splitter * bx;
  1791. ahi = c - (c - bx);
  1792. alo = bx - ahi;
  1793. c = splitter * ey;
  1794. bhi = c - (c - ey);
  1795. blo = ey - bhi;
  1796. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1797. _i = s0 - t0;
  1798. bvirt = s0 - _i;
  1799. eb[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1800. _j = s1 + _i;
  1801. bvirt = _j - s1;
  1802. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1803. _i = _0 - t1;
  1804. bvirt = _0 - _i;
  1805. eb[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1806. u3 = _j + _i;
  1807. bvirt = u3 - _j;
  1808. eb[2] = _j - (u3 - bvirt) + (_i - bvirt);
  1809. eb[3] = u3;
  1810. const abclen = sum_three_scale(ab, bc, ac, cz, az, -bz, abc);
  1811. const bcdlen = sum_three_scale(bc, cd, bd, dz, bz, -cz, bcd);
  1812. const cdelen = sum_three_scale(cd, de, ce, ez, cz, -dz, cde);
  1813. const dealen = sum_three_scale(de, ea, da, az, dz, -ez, dea);
  1814. const eablen = sum_three_scale(ea, ab, eb, bz, ez, -az, eab);
  1815. const abdlen = sum_three_scale(ab, bd, da, dz, az, bz, abd);
  1816. const bcelen = sum_three_scale(bc, ce, eb, ez, bz, cz, bce);
  1817. const cdalen = sum_three_scale(cd, da, ac, az, cz, dz, cda);
  1818. const deblen = sum_three_scale(de, eb, bd, bz, dz, ez, deb);
  1819. const eaclen = sum_three_scale(ea, ac, ce, cz, ez, az, eac);
  1820. const deterlen = sum_three(
  1821. liftexact(cdelen, cde, bcelen, bce, deblen, deb, bcdlen, bcd, ax, ay, az, adet), adet,
  1822. liftexact(dealen, dea, cdalen, cda, eaclen, eac, cdelen, cde, bx, by, bz, bdet), bdet,
  1823. sum_three(
  1824. liftexact(eablen, eab, deblen, deb, abdlen, abd, dealen, dea, cx, cy, cz, cdet), cdet,
  1825. liftexact(abclen, abc, eaclen, eac, bcelen, bce, eablen, eab, dx, dy, dz, ddet), ddet,
  1826. liftexact(bcdlen, bcd, abdlen, abd, cdalen, cda, abclen, abc, ex, ey, ez, edet), edet, cddet, cdedet), cdedet, abdet, deter);
  1827. return deter[deterlen - 1];
  1828. }
  1829. const xdet = vec(96);
  1830. const ydet = vec(96);
  1831. const zdet = vec(96);
  1832. const fin = vec(1152);
  1833. function liftadapt(a, b, c, az, bz, cz, x, y, z, out) {
  1834. const len = sum_three_scale(a, b, c, az, bz, cz, _24);
  1835. return sum_three(
  1836. scale(scale(len, _24, x, _48), _48, x, xdet), xdet,
  1837. scale(scale(len, _24, y, _48), _48, y, ydet), ydet,
  1838. scale(scale(len, _24, z, _48), _48, z, zdet), zdet, _192, out);
  1839. }
  1840. function insphereadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez, permanent) {
  1841. let ab3, bc3, cd3, da3, ac3, bd3;
  1842. let aextail, bextail, cextail, dextail;
  1843. let aeytail, beytail, ceytail, deytail;
  1844. let aeztail, beztail, ceztail, deztail;
  1845. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0;
  1846. const aex = ax - ex;
  1847. const bex = bx - ex;
  1848. const cex = cx - ex;
  1849. const dex = dx - ex;
  1850. const aey = ay - ey;
  1851. const bey = by - ey;
  1852. const cey = cy - ey;
  1853. const dey = dy - ey;
  1854. const aez = az - ez;
  1855. const bez = bz - ez;
  1856. const cez = cz - ez;
  1857. const dez = dz - ez;
  1858. s1 = aex * bey;
  1859. c = splitter * aex;
  1860. ahi = c - (c - aex);
  1861. alo = aex - ahi;
  1862. c = splitter * bey;
  1863. bhi = c - (c - bey);
  1864. blo = bey - bhi;
  1865. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1866. t1 = bex * aey;
  1867. c = splitter * bex;
  1868. ahi = c - (c - bex);
  1869. alo = bex - ahi;
  1870. c = splitter * aey;
  1871. bhi = c - (c - aey);
  1872. blo = aey - bhi;
  1873. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1874. _i = s0 - t0;
  1875. bvirt = s0 - _i;
  1876. ab[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1877. _j = s1 + _i;
  1878. bvirt = _j - s1;
  1879. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1880. _i = _0 - t1;
  1881. bvirt = _0 - _i;
  1882. ab[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1883. ab3 = _j + _i;
  1884. bvirt = ab3 - _j;
  1885. ab[2] = _j - (ab3 - bvirt) + (_i - bvirt);
  1886. ab[3] = ab3;
  1887. s1 = bex * cey;
  1888. c = splitter * bex;
  1889. ahi = c - (c - bex);
  1890. alo = bex - ahi;
  1891. c = splitter * cey;
  1892. bhi = c - (c - cey);
  1893. blo = cey - bhi;
  1894. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1895. t1 = cex * bey;
  1896. c = splitter * cex;
  1897. ahi = c - (c - cex);
  1898. alo = cex - ahi;
  1899. c = splitter * bey;
  1900. bhi = c - (c - bey);
  1901. blo = bey - bhi;
  1902. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1903. _i = s0 - t0;
  1904. bvirt = s0 - _i;
  1905. bc[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1906. _j = s1 + _i;
  1907. bvirt = _j - s1;
  1908. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1909. _i = _0 - t1;
  1910. bvirt = _0 - _i;
  1911. bc[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1912. bc3 = _j + _i;
  1913. bvirt = bc3 - _j;
  1914. bc[2] = _j - (bc3 - bvirt) + (_i - bvirt);
  1915. bc[3] = bc3;
  1916. s1 = cex * dey;
  1917. c = splitter * cex;
  1918. ahi = c - (c - cex);
  1919. alo = cex - ahi;
  1920. c = splitter * dey;
  1921. bhi = c - (c - dey);
  1922. blo = dey - bhi;
  1923. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1924. t1 = dex * cey;
  1925. c = splitter * dex;
  1926. ahi = c - (c - dex);
  1927. alo = dex - ahi;
  1928. c = splitter * cey;
  1929. bhi = c - (c - cey);
  1930. blo = cey - bhi;
  1931. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1932. _i = s0 - t0;
  1933. bvirt = s0 - _i;
  1934. cd[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1935. _j = s1 + _i;
  1936. bvirt = _j - s1;
  1937. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1938. _i = _0 - t1;
  1939. bvirt = _0 - _i;
  1940. cd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1941. cd3 = _j + _i;
  1942. bvirt = cd3 - _j;
  1943. cd[2] = _j - (cd3 - bvirt) + (_i - bvirt);
  1944. cd[3] = cd3;
  1945. s1 = dex * aey;
  1946. c = splitter * dex;
  1947. ahi = c - (c - dex);
  1948. alo = dex - ahi;
  1949. c = splitter * aey;
  1950. bhi = c - (c - aey);
  1951. blo = aey - bhi;
  1952. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1953. t1 = aex * dey;
  1954. c = splitter * aex;
  1955. ahi = c - (c - aex);
  1956. alo = aex - ahi;
  1957. c = splitter * dey;
  1958. bhi = c - (c - dey);
  1959. blo = dey - bhi;
  1960. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1961. _i = s0 - t0;
  1962. bvirt = s0 - _i;
  1963. da[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1964. _j = s1 + _i;
  1965. bvirt = _j - s1;
  1966. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1967. _i = _0 - t1;
  1968. bvirt = _0 - _i;
  1969. da[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1970. da3 = _j + _i;
  1971. bvirt = da3 - _j;
  1972. da[2] = _j - (da3 - bvirt) + (_i - bvirt);
  1973. da[3] = da3;
  1974. s1 = aex * cey;
  1975. c = splitter * aex;
  1976. ahi = c - (c - aex);
  1977. alo = aex - ahi;
  1978. c = splitter * cey;
  1979. bhi = c - (c - cey);
  1980. blo = cey - bhi;
  1981. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  1982. t1 = cex * aey;
  1983. c = splitter * cex;
  1984. ahi = c - (c - cex);
  1985. alo = cex - ahi;
  1986. c = splitter * aey;
  1987. bhi = c - (c - aey);
  1988. blo = aey - bhi;
  1989. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  1990. _i = s0 - t0;
  1991. bvirt = s0 - _i;
  1992. ac[0] = s0 - (_i + bvirt) + (bvirt - t0);
  1993. _j = s1 + _i;
  1994. bvirt = _j - s1;
  1995. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  1996. _i = _0 - t1;
  1997. bvirt = _0 - _i;
  1998. ac[1] = _0 - (_i + bvirt) + (bvirt - t1);
  1999. ac3 = _j + _i;
  2000. bvirt = ac3 - _j;
  2001. ac[2] = _j - (ac3 - bvirt) + (_i - bvirt);
  2002. ac[3] = ac3;
  2003. s1 = bex * dey;
  2004. c = splitter * bex;
  2005. ahi = c - (c - bex);
  2006. alo = bex - ahi;
  2007. c = splitter * dey;
  2008. bhi = c - (c - dey);
  2009. blo = dey - bhi;
  2010. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  2011. t1 = dex * bey;
  2012. c = splitter * dex;
  2013. ahi = c - (c - dex);
  2014. alo = dex - ahi;
  2015. c = splitter * bey;
  2016. bhi = c - (c - bey);
  2017. blo = bey - bhi;
  2018. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  2019. _i = s0 - t0;
  2020. bvirt = s0 - _i;
  2021. bd[0] = s0 - (_i + bvirt) + (bvirt - t0);
  2022. _j = s1 + _i;
  2023. bvirt = _j - s1;
  2024. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  2025. _i = _0 - t1;
  2026. bvirt = _0 - _i;
  2027. bd[1] = _0 - (_i + bvirt) + (bvirt - t1);
  2028. bd3 = _j + _i;
  2029. bvirt = bd3 - _j;
  2030. bd[2] = _j - (bd3 - bvirt) + (_i - bvirt);
  2031. bd[3] = bd3;
  2032. const finlen = sum(
  2033. sum(
  2034. negate(liftadapt(bc, cd, bd, dez, bez, -cez, aex, aey, aez, adet), adet), adet,
  2035. liftadapt(cd, da, ac, aez, cez, dez, bex, bey, bez, bdet), bdet, abdet), abdet,
  2036. sum(
  2037. negate(liftadapt(da, ab, bd, bez, dez, aez, cex, cey, cez, cdet), cdet), cdet,
  2038. liftadapt(ab, bc, ac, cez, aez, -bez, dex, dey, dez, ddet), ddet, cddet), cddet, fin);
  2039. let det = estimate(finlen, fin);
  2040. let errbound = isperrboundB * permanent;
  2041. if (det >= errbound || -det >= errbound) {
  2042. return det;
  2043. }
  2044. bvirt = ax - aex;
  2045. aextail = ax - (aex + bvirt) + (bvirt - ex);
  2046. bvirt = ay - aey;
  2047. aeytail = ay - (aey + bvirt) + (bvirt - ey);
  2048. bvirt = az - aez;
  2049. aeztail = az - (aez + bvirt) + (bvirt - ez);
  2050. bvirt = bx - bex;
  2051. bextail = bx - (bex + bvirt) + (bvirt - ex);
  2052. bvirt = by - bey;
  2053. beytail = by - (bey + bvirt) + (bvirt - ey);
  2054. bvirt = bz - bez;
  2055. beztail = bz - (bez + bvirt) + (bvirt - ez);
  2056. bvirt = cx - cex;
  2057. cextail = cx - (cex + bvirt) + (bvirt - ex);
  2058. bvirt = cy - cey;
  2059. ceytail = cy - (cey + bvirt) + (bvirt - ey);
  2060. bvirt = cz - cez;
  2061. ceztail = cz - (cez + bvirt) + (bvirt - ez);
  2062. bvirt = dx - dex;
  2063. dextail = dx - (dex + bvirt) + (bvirt - ex);
  2064. bvirt = dy - dey;
  2065. deytail = dy - (dey + bvirt) + (bvirt - ey);
  2066. bvirt = dz - dez;
  2067. deztail = dz - (dez + bvirt) + (bvirt - ez);
  2068. if (aextail === 0 && aeytail === 0 && aeztail === 0 &&
  2069. bextail === 0 && beytail === 0 && beztail === 0 &&
  2070. cextail === 0 && ceytail === 0 && ceztail === 0 &&
  2071. dextail === 0 && deytail === 0 && deztail === 0) {
  2072. return det;
  2073. }
  2074. errbound = isperrboundC * permanent + resulterrbound * Math.abs(det);
  2075. const abeps = (aex * beytail + bey * aextail) - (aey * bextail + bex * aeytail);
  2076. const bceps = (bex * ceytail + cey * bextail) - (bey * cextail + cex * beytail);
  2077. const cdeps = (cex * deytail + dey * cextail) - (cey * dextail + dex * ceytail);
  2078. const daeps = (dex * aeytail + aey * dextail) - (dey * aextail + aex * deytail);
  2079. const aceps = (aex * ceytail + cey * aextail) - (aey * cextail + cex * aeytail);
  2080. const bdeps = (bex * deytail + dey * bextail) - (bey * dextail + dex * beytail);
  2081. det +=
  2082. (((bex * bex + bey * bey + bez * bez) * ((cez * daeps + dez * aceps + aez * cdeps) +
  2083. (ceztail * da3 + deztail * ac3 + aeztail * cd3)) + (dex * dex + dey * dey + dez * dez) *
  2084. ((aez * bceps - bez * aceps + cez * abeps) + (aeztail * bc3 - beztail * ac3 + ceztail * ab3))) -
  2085. ((aex * aex + aey * aey + aez * aez) * ((bez * cdeps - cez * bdeps + dez * bceps) +
  2086. (beztail * cd3 - ceztail * bd3 + deztail * bc3)) + (cex * cex + cey * cey + cez * cez) *
  2087. ((dez * abeps + aez * bdeps + bez * daeps) + (deztail * ab3 + aeztail * bd3 + beztail * da3)))) +
  2088. 2 * (((bex * bextail + bey * beytail + bez * beztail) * (cez * da3 + dez * ac3 + aez * cd3) +
  2089. (dex * dextail + dey * deytail + dez * deztail) * (aez * bc3 - bez * ac3 + cez * ab3)) -
  2090. ((aex * aextail + aey * aeytail + aez * aeztail) * (bez * cd3 - cez * bd3 + dez * bc3) +
  2091. (cex * cextail + cey * ceytail + cez * ceztail) * (dez * ab3 + aez * bd3 + bez * da3)));
  2092. if (det >= errbound || -det >= errbound) {
  2093. return det;
  2094. }
  2095. return insphereexact(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez);
  2096. }
  2097. function insphere(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez) {
  2098. const aex = ax - ex;
  2099. const bex = bx - ex;
  2100. const cex = cx - ex;
  2101. const dex = dx - ex;
  2102. const aey = ay - ey;
  2103. const bey = by - ey;
  2104. const cey = cy - ey;
  2105. const dey = dy - ey;
  2106. const aez = az - ez;
  2107. const bez = bz - ez;
  2108. const cez = cz - ez;
  2109. const dez = dz - ez;
  2110. const aexbey = aex * bey;
  2111. const bexaey = bex * aey;
  2112. const ab = aexbey - bexaey;
  2113. const bexcey = bex * cey;
  2114. const cexbey = cex * bey;
  2115. const bc = bexcey - cexbey;
  2116. const cexdey = cex * dey;
  2117. const dexcey = dex * cey;
  2118. const cd = cexdey - dexcey;
  2119. const dexaey = dex * aey;
  2120. const aexdey = aex * dey;
  2121. const da = dexaey - aexdey;
  2122. const aexcey = aex * cey;
  2123. const cexaey = cex * aey;
  2124. const ac = aexcey - cexaey;
  2125. const bexdey = bex * dey;
  2126. const dexbey = dex * bey;
  2127. const bd = bexdey - dexbey;
  2128. const alift = aex * aex + aey * aey + aez * aez;
  2129. const blift = bex * bex + bey * bey + bez * bez;
  2130. const clift = cex * cex + cey * cey + cez * cez;
  2131. const dlift = dex * dex + dey * dey + dez * dez;
  2132. const det =
  2133. (clift * (dez * ab + aez * bd + bez * da) - dlift * (aez * bc - bez * ac + cez * ab)) +
  2134. (alift * (bez * cd - cez * bd + dez * bc) - blift * (cez * da + dez * ac + aez * cd));
  2135. const aezplus = Math.abs(aez);
  2136. const bezplus = Math.abs(bez);
  2137. const cezplus = Math.abs(cez);
  2138. const dezplus = Math.abs(dez);
  2139. const aexbeyplus = Math.abs(aexbey) + Math.abs(bexaey);
  2140. const bexceyplus = Math.abs(bexcey) + Math.abs(cexbey);
  2141. const cexdeyplus = Math.abs(cexdey) + Math.abs(dexcey);
  2142. const dexaeyplus = Math.abs(dexaey) + Math.abs(aexdey);
  2143. const aexceyplus = Math.abs(aexcey) + Math.abs(cexaey);
  2144. const bexdeyplus = Math.abs(bexdey) + Math.abs(dexbey);
  2145. const permanent =
  2146. (cexdeyplus * bezplus + bexdeyplus * cezplus + bexceyplus * dezplus) * alift +
  2147. (dexaeyplus * cezplus + aexceyplus * dezplus + cexdeyplus * aezplus) * blift +
  2148. (aexbeyplus * dezplus + bexdeyplus * aezplus + dexaeyplus * bezplus) * clift +
  2149. (bexceyplus * aezplus + aexceyplus * bezplus + aexbeyplus * cezplus) * dlift;
  2150. const errbound = isperrboundA * permanent;
  2151. if (det > errbound || -det > errbound) {
  2152. return det;
  2153. }
  2154. return -insphereadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez, permanent);
  2155. }
  2156. function inspherefast(pax, pay, paz, pbx, pby, pbz, pcx, pcy, pcz, pdx, pdy, pdz, pex, pey, pez) {
  2157. const aex = pax - pex;
  2158. const bex = pbx - pex;
  2159. const cex = pcx - pex;
  2160. const dex = pdx - pex;
  2161. const aey = pay - pey;
  2162. const bey = pby - pey;
  2163. const cey = pcy - pey;
  2164. const dey = pdy - pey;
  2165. const aez = paz - pez;
  2166. const bez = pbz - pez;
  2167. const cez = pcz - pez;
  2168. const dez = pdz - pez;
  2169. const ab = aex * bey - bex * aey;
  2170. const bc = bex * cey - cex * bey;
  2171. const cd = cex * dey - dex * cey;
  2172. const da = dex * aey - aex * dey;
  2173. const ac = aex * cey - cex * aey;
  2174. const bd = bex * dey - dex * bey;
  2175. const abc = aez * bc - bez * ac + cez * ab;
  2176. const bcd = bez * cd - cez * bd + dez * bc;
  2177. const cda = cez * da + dez * ac + aez * cd;
  2178. const dab = dez * ab + aez * bd + bez * da;
  2179. const alift = aex * aex + aey * aey + aez * aez;
  2180. const blift = bex * bex + bey * bey + bez * bez;
  2181. const clift = cex * cex + cey * cey + cez * cez;
  2182. const dlift = dex * dex + dey * dey + dez * dez;
  2183. return (clift * dab - dlift * abc) + (alift * bcd - blift * cda);
  2184. }
  2185. exports.incircle = incircle;
  2186. exports.incirclefast = incirclefast;
  2187. exports.insphere = insphere;
  2188. exports.inspherefast = inspherefast;
  2189. exports.orient2d = orient2d;
  2190. exports.orient2dfast = orient2dfast;
  2191. exports.orient3d = orient3d;
  2192. exports.orient3dfast = orient3dfast;
  2193. }));