123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328 |
- (function (global, factory) {
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.predicates = {}));
- })(this, (function (exports) { 'use strict';
-
- const epsilon = 1.1102230246251565e-16;
- const splitter = 134217729;
- const resulterrbound = (3 + 8 * epsilon) * epsilon;
-
- // fast_expansion_sum_zeroelim routine from oritinal code
- function sum(elen, e, flen, f, h) {
- let Q, Qnew, hh, bvirt;
- let enow = e[0];
- let fnow = f[0];
- let eindex = 0;
- let findex = 0;
- if ((fnow > enow) === (fnow > -enow)) {
- Q = enow;
- enow = e[++eindex];
- } else {
- Q = fnow;
- fnow = f[++findex];
- }
- let hindex = 0;
- if (eindex < elen && findex < flen) {
- if ((fnow > enow) === (fnow > -enow)) {
- Qnew = enow + Q;
- hh = Q - (Qnew - enow);
- enow = e[++eindex];
- } else {
- Qnew = fnow + Q;
- hh = Q - (Qnew - fnow);
- fnow = f[++findex];
- }
- Q = Qnew;
- if (hh !== 0) {
- h[hindex++] = hh;
- }
- while (eindex < elen && findex < flen) {
- if ((fnow > enow) === (fnow > -enow)) {
- Qnew = Q + enow;
- bvirt = Qnew - Q;
- hh = Q - (Qnew - bvirt) + (enow - bvirt);
- enow = e[++eindex];
- } else {
- Qnew = Q + fnow;
- bvirt = Qnew - Q;
- hh = Q - (Qnew - bvirt) + (fnow - bvirt);
- fnow = f[++findex];
- }
- Q = Qnew;
- if (hh !== 0) {
- h[hindex++] = hh;
- }
- }
- }
- while (eindex < elen) {
- Qnew = Q + enow;
- bvirt = Qnew - Q;
- hh = Q - (Qnew - bvirt) + (enow - bvirt);
- enow = e[++eindex];
- Q = Qnew;
- if (hh !== 0) {
- h[hindex++] = hh;
- }
- }
- while (findex < flen) {
- Qnew = Q + fnow;
- bvirt = Qnew - Q;
- hh = Q - (Qnew - bvirt) + (fnow - bvirt);
- fnow = f[++findex];
- Q = Qnew;
- if (hh !== 0) {
- h[hindex++] = hh;
- }
- }
- if (Q !== 0 || hindex === 0) {
- h[hindex++] = Q;
- }
- return hindex;
- }
-
- function sum_three(alen, a, blen, b, clen, c, tmp, out) {
- return sum(sum(alen, a, blen, b, tmp), tmp, clen, c, out);
- }
-
- // scale_expansion_zeroelim routine from oritinal code
- function scale(elen, e, b, h) {
- let Q, sum, hh, product1, product0;
- let bvirt, c, ahi, alo, bhi, blo;
-
- c = splitter * b;
- bhi = c - (c - b);
- blo = b - bhi;
- let enow = e[0];
- Q = enow * b;
- c = splitter * enow;
- ahi = c - (c - enow);
- alo = enow - ahi;
- hh = alo * blo - (Q - ahi * bhi - alo * bhi - ahi * blo);
- let hindex = 0;
- if (hh !== 0) {
- h[hindex++] = hh;
- }
- for (let i = 1; i < elen; i++) {
- enow = e[i];
- product1 = enow * b;
- c = splitter * enow;
- ahi = c - (c - enow);
- alo = enow - ahi;
- product0 = alo * blo - (product1 - ahi * bhi - alo * bhi - ahi * blo);
- sum = Q + product0;
- bvirt = sum - Q;
- hh = Q - (sum - bvirt) + (product0 - bvirt);
- if (hh !== 0) {
- h[hindex++] = hh;
- }
- Q = product1 + sum;
- hh = sum - (Q - product1);
- if (hh !== 0) {
- h[hindex++] = hh;
- }
- }
- if (Q !== 0 || hindex === 0) {
- h[hindex++] = Q;
- }
- return hindex;
- }
-
- function negate(elen, e) {
- for (let i = 0; i < elen; i++) e[i] = -e[i];
- return elen;
- }
-
- function estimate(elen, e) {
- let Q = e[0];
- for (let i = 1; i < elen; i++) Q += e[i];
- return Q;
- }
-
- function vec(n) {
- return new Float64Array(n);
- }
-
- const ccwerrboundA = (3 + 16 * epsilon) * epsilon;
- const ccwerrboundB = (2 + 12 * epsilon) * epsilon;
- const ccwerrboundC = (9 + 64 * epsilon) * epsilon * epsilon;
-
- const B = vec(4);
- const C1 = vec(8);
- const C2 = vec(12);
- const D = vec(16);
- const u$2 = vec(4);
-
- function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
- let acxtail, acytail, bcxtail, bcytail;
- let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
-
- const acx = ax - cx;
- const bcx = bx - cx;
- const acy = ay - cy;
- const bcy = by - cy;
-
- s1 = acx * bcy;
- c = splitter * acx;
- ahi = c - (c - acx);
- alo = acx - ahi;
- c = splitter * bcy;
- bhi = c - (c - bcy);
- blo = bcy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = acy * bcx;
- c = splitter * acy;
- ahi = c - (c - acy);
- alo = acy - ahi;
- c = splitter * bcx;
- bhi = c - (c - bcx);
- blo = bcx - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- B[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- B[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- B[2] = _j - (u3 - bvirt) + (_i - bvirt);
- B[3] = u3;
-
- let det = estimate(4, B);
- let errbound = ccwerrboundB * detsum;
- if (det >= errbound || -det >= errbound) {
- return det;
- }
-
- bvirt = ax - acx;
- acxtail = ax - (acx + bvirt) + (bvirt - cx);
- bvirt = bx - bcx;
- bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
- bvirt = ay - acy;
- acytail = ay - (acy + bvirt) + (bvirt - cy);
- bvirt = by - bcy;
- bcytail = by - (bcy + bvirt) + (bvirt - cy);
-
- if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
- return det;
- }
-
- errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
- det += (acx * bcytail + bcy * acxtail) - (acy * bcxtail + bcx * acytail);
- if (det >= errbound || -det >= errbound) return det;
-
- s1 = acxtail * bcy;
- c = splitter * acxtail;
- ahi = c - (c - acxtail);
- alo = acxtail - ahi;
- c = splitter * bcy;
- bhi = c - (c - bcy);
- blo = bcy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = acytail * bcx;
- c = splitter * acytail;
- ahi = c - (c - acytail);
- alo = acytail - ahi;
- c = splitter * bcx;
- bhi = c - (c - bcx);
- blo = bcx - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- u$2[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- u$2[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- u$2[2] = _j - (u3 - bvirt) + (_i - bvirt);
- u$2[3] = u3;
- const C1len = sum(4, B, 4, u$2, C1);
-
- s1 = acx * bcytail;
- c = splitter * acx;
- ahi = c - (c - acx);
- alo = acx - ahi;
- c = splitter * bcytail;
- bhi = c - (c - bcytail);
- blo = bcytail - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = acy * bcxtail;
- c = splitter * acy;
- ahi = c - (c - acy);
- alo = acy - ahi;
- c = splitter * bcxtail;
- bhi = c - (c - bcxtail);
- blo = bcxtail - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- u$2[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- u$2[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- u$2[2] = _j - (u3 - bvirt) + (_i - bvirt);
- u$2[3] = u3;
- const C2len = sum(C1len, C1, 4, u$2, C2);
-
- s1 = acxtail * bcytail;
- c = splitter * acxtail;
- ahi = c - (c - acxtail);
- alo = acxtail - ahi;
- c = splitter * bcytail;
- bhi = c - (c - bcytail);
- blo = bcytail - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = acytail * bcxtail;
- c = splitter * acytail;
- ahi = c - (c - acytail);
- alo = acytail - ahi;
- c = splitter * bcxtail;
- bhi = c - (c - bcxtail);
- blo = bcxtail - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- u$2[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- u$2[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- u$2[2] = _j - (u3 - bvirt) + (_i - bvirt);
- u$2[3] = u3;
- const Dlen = sum(C2len, C2, 4, u$2, D);
-
- return D[Dlen - 1];
- }
-
- function orient2d(ax, ay, bx, by, cx, cy) {
- const detleft = (ay - cy) * (bx - cx);
- const detright = (ax - cx) * (by - cy);
- const det = detleft - detright;
-
- const detsum = Math.abs(detleft + detright);
- if (Math.abs(det) >= ccwerrboundA * detsum) return det;
-
- return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
- }
-
- function orient2dfast(ax, ay, bx, by, cx, cy) {
- return (ay - cy) * (bx - cx) - (ax - cx) * (by - cy);
- }
-
- const o3derrboundA = (7 + 56 * epsilon) * epsilon;
- const o3derrboundB = (3 + 28 * epsilon) * epsilon;
- const o3derrboundC = (26 + 288 * epsilon) * epsilon * epsilon;
-
- const bc$2 = vec(4);
- const ca$1 = vec(4);
- const ab$2 = vec(4);
- const at_b = vec(4);
- const at_c = vec(4);
- const bt_c = vec(4);
- const bt_a = vec(4);
- const ct_a = vec(4);
- const ct_b = vec(4);
- const bct$1 = vec(8);
- const cat$1 = vec(8);
- const abt$1 = vec(8);
- const u$1 = vec(4);
-
- const _8$2 = vec(8);
- const _8b$1 = vec(8);
- const _16$2 = vec(8);
- const _12 = vec(12);
-
- let fin$2 = vec(192);
- let fin2$1 = vec(192);
-
- function finadd$1(finlen, alen, a) {
- finlen = sum(finlen, fin$2, alen, a, fin2$1);
- const tmp = fin$2; fin$2 = fin2$1; fin2$1 = tmp;
- return finlen;
- }
-
- function tailinit(xtail, ytail, ax, ay, bx, by, a, b) {
- let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3, negate;
- if (xtail === 0) {
- if (ytail === 0) {
- a[0] = 0;
- b[0] = 0;
- return 1;
- } else {
- negate = -ytail;
- s1 = negate * ax;
- c = splitter * negate;
- ahi = c - (c - negate);
- alo = negate - ahi;
- c = splitter * ax;
- bhi = c - (c - ax);
- blo = ax - bhi;
- a[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- a[1] = s1;
- s1 = ytail * bx;
- c = splitter * ytail;
- ahi = c - (c - ytail);
- alo = ytail - ahi;
- c = splitter * bx;
- bhi = c - (c - bx);
- blo = bx - bhi;
- b[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- b[1] = s1;
- return 2;
- }
- } else {
- if (ytail === 0) {
- s1 = xtail * ay;
- c = splitter * xtail;
- ahi = c - (c - xtail);
- alo = xtail - ahi;
- c = splitter * ay;
- bhi = c - (c - ay);
- blo = ay - bhi;
- a[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- a[1] = s1;
- negate = -xtail;
- s1 = negate * by;
- c = splitter * negate;
- ahi = c - (c - negate);
- alo = negate - ahi;
- c = splitter * by;
- bhi = c - (c - by);
- blo = by - bhi;
- b[0] = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- b[1] = s1;
- return 2;
- } else {
- s1 = xtail * ay;
- c = splitter * xtail;
- ahi = c - (c - xtail);
- alo = xtail - ahi;
- c = splitter * ay;
- bhi = c - (c - ay);
- blo = ay - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = ytail * ax;
- c = splitter * ytail;
- ahi = c - (c - ytail);
- alo = ytail - ahi;
- c = splitter * ax;
- bhi = c - (c - ax);
- blo = ax - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- a[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- a[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- a[2] = _j - (u3 - bvirt) + (_i - bvirt);
- a[3] = u3;
- s1 = ytail * bx;
- c = splitter * ytail;
- ahi = c - (c - ytail);
- alo = ytail - ahi;
- c = splitter * bx;
- bhi = c - (c - bx);
- blo = bx - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = xtail * by;
- c = splitter * xtail;
- ahi = c - (c - xtail);
- alo = xtail - ahi;
- c = splitter * by;
- bhi = c - (c - by);
- blo = by - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- b[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- b[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- b[2] = _j - (u3 - bvirt) + (_i - bvirt);
- b[3] = u3;
- return 4;
- }
- }
- }
-
- function tailadd(finlen, a, b, k, z) {
- let bvirt, c, ahi, alo, bhi, blo, _i, _j, _k, _0, s1, s0, u3;
- s1 = a * b;
- c = splitter * a;
- ahi = c - (c - a);
- alo = a - ahi;
- c = splitter * b;
- bhi = c - (c - b);
- blo = b - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- c = splitter * k;
- bhi = c - (c - k);
- blo = k - bhi;
- _i = s0 * k;
- c = splitter * s0;
- ahi = c - (c - s0);
- alo = s0 - ahi;
- u$1[0] = alo * blo - (_i - ahi * bhi - alo * bhi - ahi * blo);
- _j = s1 * k;
- c = splitter * s1;
- ahi = c - (c - s1);
- alo = s1 - ahi;
- _0 = alo * blo - (_j - ahi * bhi - alo * bhi - ahi * blo);
- _k = _i + _0;
- bvirt = _k - _i;
- u$1[1] = _i - (_k - bvirt) + (_0 - bvirt);
- u3 = _j + _k;
- u$1[2] = _k - (u3 - _j);
- u$1[3] = u3;
- finlen = finadd$1(finlen, 4, u$1);
- if (z !== 0) {
- c = splitter * z;
- bhi = c - (c - z);
- blo = z - bhi;
- _i = s0 * z;
- c = splitter * s0;
- ahi = c - (c - s0);
- alo = s0 - ahi;
- u$1[0] = alo * blo - (_i - ahi * bhi - alo * bhi - ahi * blo);
- _j = s1 * z;
- c = splitter * s1;
- ahi = c - (c - s1);
- alo = s1 - ahi;
- _0 = alo * blo - (_j - ahi * bhi - alo * bhi - ahi * blo);
- _k = _i + _0;
- bvirt = _k - _i;
- u$1[1] = _i - (_k - bvirt) + (_0 - bvirt);
- u3 = _j + _k;
- u$1[2] = _k - (u3 - _j);
- u$1[3] = u3;
- finlen = finadd$1(finlen, 4, u$1);
- }
- return finlen;
- }
-
- function orient3dadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, permanent) {
- let finlen;
- let adxtail, bdxtail, cdxtail;
- let adytail, bdytail, cdytail;
- let adztail, bdztail, cdztail;
- let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
-
- const adx = ax - dx;
- const bdx = bx - dx;
- const cdx = cx - dx;
- const ady = ay - dy;
- const bdy = by - dy;
- const cdy = cy - dy;
- const adz = az - dz;
- const bdz = bz - dz;
- const cdz = cz - dz;
-
- s1 = bdx * cdy;
- c = splitter * bdx;
- ahi = c - (c - bdx);
- alo = bdx - ahi;
- c = splitter * cdy;
- bhi = c - (c - cdy);
- blo = cdy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = cdx * bdy;
- c = splitter * cdx;
- ahi = c - (c - cdx);
- alo = cdx - ahi;
- c = splitter * bdy;
- bhi = c - (c - bdy);
- blo = bdy - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- bc$2[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- bc$2[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- bc$2[2] = _j - (u3 - bvirt) + (_i - bvirt);
- bc$2[3] = u3;
- s1 = cdx * ady;
- c = splitter * cdx;
- ahi = c - (c - cdx);
- alo = cdx - ahi;
- c = splitter * ady;
- bhi = c - (c - ady);
- blo = ady - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = adx * cdy;
- c = splitter * adx;
- ahi = c - (c - adx);
- alo = adx - ahi;
- c = splitter * cdy;
- bhi = c - (c - cdy);
- blo = cdy - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- ca$1[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- ca$1[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- ca$1[2] = _j - (u3 - bvirt) + (_i - bvirt);
- ca$1[3] = u3;
- s1 = adx * bdy;
- c = splitter * adx;
- ahi = c - (c - adx);
- alo = adx - ahi;
- c = splitter * bdy;
- bhi = c - (c - bdy);
- blo = bdy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = bdx * ady;
- c = splitter * bdx;
- ahi = c - (c - bdx);
- alo = bdx - ahi;
- c = splitter * ady;
- bhi = c - (c - ady);
- blo = ady - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- ab$2[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- ab$2[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- ab$2[2] = _j - (u3 - bvirt) + (_i - bvirt);
- ab$2[3] = u3;
-
- finlen = sum(
- sum(
- scale(4, bc$2, adz, _8$2), _8$2,
- scale(4, ca$1, bdz, _8b$1), _8b$1, _16$2), _16$2,
- scale(4, ab$2, cdz, _8$2), _8$2, fin$2);
-
- let det = estimate(finlen, fin$2);
- let errbound = o3derrboundB * permanent;
- if (det >= errbound || -det >= errbound) {
- return det;
- }
-
- bvirt = ax - adx;
- adxtail = ax - (adx + bvirt) + (bvirt - dx);
- bvirt = bx - bdx;
- bdxtail = bx - (bdx + bvirt) + (bvirt - dx);
- bvirt = cx - cdx;
- cdxtail = cx - (cdx + bvirt) + (bvirt - dx);
- bvirt = ay - ady;
- adytail = ay - (ady + bvirt) + (bvirt - dy);
- bvirt = by - bdy;
- bdytail = by - (bdy + bvirt) + (bvirt - dy);
- bvirt = cy - cdy;
- cdytail = cy - (cdy + bvirt) + (bvirt - dy);
- bvirt = az - adz;
- adztail = az - (adz + bvirt) + (bvirt - dz);
- bvirt = bz - bdz;
- bdztail = bz - (bdz + bvirt) + (bvirt - dz);
- bvirt = cz - cdz;
- cdztail = cz - (cdz + bvirt) + (bvirt - dz);
-
- if (adxtail === 0 && bdxtail === 0 && cdxtail === 0 &&
- adytail === 0 && bdytail === 0 && cdytail === 0 &&
- adztail === 0 && bdztail === 0 && cdztail === 0) {
- return det;
- }
-
- errbound = o3derrboundC * permanent + resulterrbound * Math.abs(det);
- det +=
- adz * (bdx * cdytail + cdy * bdxtail - (bdy * cdxtail + cdx * bdytail)) + adztail * (bdx * cdy - bdy * cdx) +
- bdz * (cdx * adytail + ady * cdxtail - (cdy * adxtail + adx * cdytail)) + bdztail * (cdx * ady - cdy * adx) +
- cdz * (adx * bdytail + bdy * adxtail - (ady * bdxtail + bdx * adytail)) + cdztail * (adx * bdy - ady * bdx);
- if (det >= errbound || -det >= errbound) {
- return det;
- }
-
- const at_len = tailinit(adxtail, adytail, bdx, bdy, cdx, cdy, at_b, at_c);
- const bt_len = tailinit(bdxtail, bdytail, cdx, cdy, adx, ady, bt_c, bt_a);
- const ct_len = tailinit(cdxtail, cdytail, adx, ady, bdx, bdy, ct_a, ct_b);
-
- const bctlen = sum(bt_len, bt_c, ct_len, ct_b, bct$1);
- finlen = finadd$1(finlen, scale(bctlen, bct$1, adz, _16$2), _16$2);
-
- const catlen = sum(ct_len, ct_a, at_len, at_c, cat$1);
- finlen = finadd$1(finlen, scale(catlen, cat$1, bdz, _16$2), _16$2);
-
- const abtlen = sum(at_len, at_b, bt_len, bt_a, abt$1);
- finlen = finadd$1(finlen, scale(abtlen, abt$1, cdz, _16$2), _16$2);
-
- if (adztail !== 0) {
- finlen = finadd$1(finlen, scale(4, bc$2, adztail, _12), _12);
- finlen = finadd$1(finlen, scale(bctlen, bct$1, adztail, _16$2), _16$2);
- }
- if (bdztail !== 0) {
- finlen = finadd$1(finlen, scale(4, ca$1, bdztail, _12), _12);
- finlen = finadd$1(finlen, scale(catlen, cat$1, bdztail, _16$2), _16$2);
- }
- if (cdztail !== 0) {
- finlen = finadd$1(finlen, scale(4, ab$2, cdztail, _12), _12);
- finlen = finadd$1(finlen, scale(abtlen, abt$1, cdztail, _16$2), _16$2);
- }
-
- if (adxtail !== 0) {
- if (bdytail !== 0) {
- finlen = tailadd(finlen, adxtail, bdytail, cdz, cdztail);
- }
- if (cdytail !== 0) {
- finlen = tailadd(finlen, -adxtail, cdytail, bdz, bdztail);
- }
- }
- if (bdxtail !== 0) {
- if (cdytail !== 0) {
- finlen = tailadd(finlen, bdxtail, cdytail, adz, adztail);
- }
- if (adytail !== 0) {
- finlen = tailadd(finlen, -bdxtail, adytail, cdz, cdztail);
- }
- }
- if (cdxtail !== 0) {
- if (adytail !== 0) {
- finlen = tailadd(finlen, cdxtail, adytail, bdz, bdztail);
- }
- if (bdytail !== 0) {
- finlen = tailadd(finlen, -cdxtail, bdytail, adz, adztail);
- }
- }
-
- return fin$2[finlen - 1];
- }
-
- function orient3d(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz) {
- const adx = ax - dx;
- const bdx = bx - dx;
- const cdx = cx - dx;
- const ady = ay - dy;
- const bdy = by - dy;
- const cdy = cy - dy;
- const adz = az - dz;
- const bdz = bz - dz;
- const cdz = cz - dz;
-
- const bdxcdy = bdx * cdy;
- const cdxbdy = cdx * bdy;
-
- const cdxady = cdx * ady;
- const adxcdy = adx * cdy;
-
- const adxbdy = adx * bdy;
- const bdxady = bdx * ady;
-
- const det =
- adz * (bdxcdy - cdxbdy) +
- bdz * (cdxady - adxcdy) +
- cdz * (adxbdy - bdxady);
-
- const permanent =
- (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * Math.abs(adz) +
- (Math.abs(cdxady) + Math.abs(adxcdy)) * Math.abs(bdz) +
- (Math.abs(adxbdy) + Math.abs(bdxady)) * Math.abs(cdz);
-
- const errbound = o3derrboundA * permanent;
- if (det > errbound || -det > errbound) {
- return det;
- }
-
- return orient3dadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, permanent);
- }
-
- function orient3dfast(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz) {
- const adx = ax - dx;
- const bdx = bx - dx;
- const cdx = cx - dx;
- const ady = ay - dy;
- const bdy = by - dy;
- const cdy = cy - dy;
- const adz = az - dz;
- const bdz = bz - dz;
- const cdz = cz - dz;
-
- return adx * (bdy * cdz - bdz * cdy) +
- bdx * (cdy * adz - cdz * ady) +
- cdx * (ady * bdz - adz * bdy);
- }
-
- const iccerrboundA = (10 + 96 * epsilon) * epsilon;
- const iccerrboundB = (4 + 48 * epsilon) * epsilon;
- const iccerrboundC = (44 + 576 * epsilon) * epsilon * epsilon;
-
- const bc$1 = vec(4);
- const ca = vec(4);
- const ab$1 = vec(4);
- const aa = vec(4);
- const bb = vec(4);
- const cc = vec(4);
- const u = vec(4);
- const v = vec(4);
- const axtbc = vec(8);
- const aytbc = vec(8);
- const bxtca = vec(8);
- const bytca = vec(8);
- const cxtab = vec(8);
- const cytab = vec(8);
- const abt = vec(8);
- const bct = vec(8);
- const cat = vec(8);
- const abtt = vec(4);
- const bctt = vec(4);
- const catt = vec(4);
-
- const _8$1 = vec(8);
- const _16$1 = vec(16);
- const _16b = vec(16);
- const _16c = vec(16);
- const _32 = vec(32);
- const _32b = vec(32);
- const _48$1 = vec(48);
- const _64 = vec(64);
-
- let fin$1 = vec(1152);
- let fin2 = vec(1152);
-
- function finadd(finlen, a, alen) {
- finlen = sum(finlen, fin$1, a, alen, fin2);
- const tmp = fin$1; fin$1 = fin2; fin2 = tmp;
- return finlen;
- }
-
- function incircleadapt(ax, ay, bx, by, cx, cy, dx, dy, permanent) {
- let finlen;
- let adxtail, bdxtail, cdxtail, adytail, bdytail, cdytail;
- let axtbclen, aytbclen, bxtcalen, bytcalen, cxtablen, cytablen;
- let abtlen, bctlen, catlen;
- let abttlen, bcttlen, cattlen;
- let n1, n0;
-
- let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
-
- const adx = ax - dx;
- const bdx = bx - dx;
- const cdx = cx - dx;
- const ady = ay - dy;
- const bdy = by - dy;
- const cdy = cy - dy;
-
- s1 = bdx * cdy;
- c = splitter * bdx;
- ahi = c - (c - bdx);
- alo = bdx - ahi;
- c = splitter * cdy;
- bhi = c - (c - cdy);
- blo = cdy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = cdx * bdy;
- c = splitter * cdx;
- ahi = c - (c - cdx);
- alo = cdx - ahi;
- c = splitter * bdy;
- bhi = c - (c - bdy);
- blo = bdy - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- bc$1[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- bc$1[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- bc$1[2] = _j - (u3 - bvirt) + (_i - bvirt);
- bc$1[3] = u3;
- s1 = cdx * ady;
- c = splitter * cdx;
- ahi = c - (c - cdx);
- alo = cdx - ahi;
- c = splitter * ady;
- bhi = c - (c - ady);
- blo = ady - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = adx * cdy;
- c = splitter * adx;
- ahi = c - (c - adx);
- alo = adx - ahi;
- c = splitter * cdy;
- bhi = c - (c - cdy);
- blo = cdy - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- ca[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- ca[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- ca[2] = _j - (u3 - bvirt) + (_i - bvirt);
- ca[3] = u3;
- s1 = adx * bdy;
- c = splitter * adx;
- ahi = c - (c - adx);
- alo = adx - ahi;
- c = splitter * bdy;
- bhi = c - (c - bdy);
- blo = bdy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = bdx * ady;
- c = splitter * bdx;
- ahi = c - (c - bdx);
- alo = bdx - ahi;
- c = splitter * ady;
- bhi = c - (c - ady);
- blo = ady - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- ab$1[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- ab$1[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- ab$1[2] = _j - (u3 - bvirt) + (_i - bvirt);
- ab$1[3] = u3;
-
- finlen = sum(
- sum(
- sum(
- scale(scale(4, bc$1, adx, _8$1), _8$1, adx, _16$1), _16$1,
- scale(scale(4, bc$1, ady, _8$1), _8$1, ady, _16b), _16b, _32), _32,
- sum(
- scale(scale(4, ca, bdx, _8$1), _8$1, bdx, _16$1), _16$1,
- scale(scale(4, ca, bdy, _8$1), _8$1, bdy, _16b), _16b, _32b), _32b, _64), _64,
- sum(
- scale(scale(4, ab$1, cdx, _8$1), _8$1, cdx, _16$1), _16$1,
- scale(scale(4, ab$1, cdy, _8$1), _8$1, cdy, _16b), _16b, _32), _32, fin$1);
-
- let det = estimate(finlen, fin$1);
- let errbound = iccerrboundB * permanent;
- if (det >= errbound || -det >= errbound) {
- return det;
- }
-
- bvirt = ax - adx;
- adxtail = ax - (adx + bvirt) + (bvirt - dx);
- bvirt = ay - ady;
- adytail = ay - (ady + bvirt) + (bvirt - dy);
- bvirt = bx - bdx;
- bdxtail = bx - (bdx + bvirt) + (bvirt - dx);
- bvirt = by - bdy;
- bdytail = by - (bdy + bvirt) + (bvirt - dy);
- bvirt = cx - cdx;
- cdxtail = cx - (cdx + bvirt) + (bvirt - dx);
- bvirt = cy - cdy;
- cdytail = cy - (cdy + bvirt) + (bvirt - dy);
- if (adxtail === 0 && bdxtail === 0 && cdxtail === 0 && adytail === 0 && bdytail === 0 && cdytail === 0) {
- return det;
- }
-
- errbound = iccerrboundC * permanent + resulterrbound * Math.abs(det);
- det += ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) +
- 2 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx)) +
- ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) +
- 2 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx)) +
- ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) +
- 2 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx));
-
- if (det >= errbound || -det >= errbound) {
- return det;
- }
-
- if (bdxtail !== 0 || bdytail !== 0 || cdxtail !== 0 || cdytail !== 0) {
- s1 = adx * adx;
- c = splitter * adx;
- ahi = c - (c - adx);
- alo = adx - ahi;
- s0 = alo * alo - (s1 - ahi * ahi - (ahi + ahi) * alo);
- t1 = ady * ady;
- c = splitter * ady;
- ahi = c - (c - ady);
- alo = ady - ahi;
- t0 = alo * alo - (t1 - ahi * ahi - (ahi + ahi) * alo);
- _i = s0 + t0;
- bvirt = _i - s0;
- aa[0] = s0 - (_i - bvirt) + (t0 - bvirt);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 + t1;
- bvirt = _i - _0;
- aa[1] = _0 - (_i - bvirt) + (t1 - bvirt);
- u3 = _j + _i;
- bvirt = u3 - _j;
- aa[2] = _j - (u3 - bvirt) + (_i - bvirt);
- aa[3] = u3;
- }
- if (cdxtail !== 0 || cdytail !== 0 || adxtail !== 0 || adytail !== 0) {
- s1 = bdx * bdx;
- c = splitter * bdx;
- ahi = c - (c - bdx);
- alo = bdx - ahi;
- s0 = alo * alo - (s1 - ahi * ahi - (ahi + ahi) * alo);
- t1 = bdy * bdy;
- c = splitter * bdy;
- ahi = c - (c - bdy);
- alo = bdy - ahi;
- t0 = alo * alo - (t1 - ahi * ahi - (ahi + ahi) * alo);
- _i = s0 + t0;
- bvirt = _i - s0;
- bb[0] = s0 - (_i - bvirt) + (t0 - bvirt);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 + t1;
- bvirt = _i - _0;
- bb[1] = _0 - (_i - bvirt) + (t1 - bvirt);
- u3 = _j + _i;
- bvirt = u3 - _j;
- bb[2] = _j - (u3 - bvirt) + (_i - bvirt);
- bb[3] = u3;
- }
- if (adxtail !== 0 || adytail !== 0 || bdxtail !== 0 || bdytail !== 0) {
- s1 = cdx * cdx;
- c = splitter * cdx;
- ahi = c - (c - cdx);
- alo = cdx - ahi;
- s0 = alo * alo - (s1 - ahi * ahi - (ahi + ahi) * alo);
- t1 = cdy * cdy;
- c = splitter * cdy;
- ahi = c - (c - cdy);
- alo = cdy - ahi;
- t0 = alo * alo - (t1 - ahi * ahi - (ahi + ahi) * alo);
- _i = s0 + t0;
- bvirt = _i - s0;
- cc[0] = s0 - (_i - bvirt) + (t0 - bvirt);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 + t1;
- bvirt = _i - _0;
- cc[1] = _0 - (_i - bvirt) + (t1 - bvirt);
- u3 = _j + _i;
- bvirt = u3 - _j;
- cc[2] = _j - (u3 - bvirt) + (_i - bvirt);
- cc[3] = u3;
- }
-
- if (adxtail !== 0) {
- axtbclen = scale(4, bc$1, adxtail, axtbc);
- finlen = finadd(finlen, sum_three(
- scale(axtbclen, axtbc, 2 * adx, _16$1), _16$1,
- scale(scale(4, cc, adxtail, _8$1), _8$1, bdy, _16b), _16b,
- scale(scale(4, bb, adxtail, _8$1), _8$1, -cdy, _16c), _16c, _32, _48$1), _48$1);
- }
- if (adytail !== 0) {
- aytbclen = scale(4, bc$1, adytail, aytbc);
- finlen = finadd(finlen, sum_three(
- scale(aytbclen, aytbc, 2 * ady, _16$1), _16$1,
- scale(scale(4, bb, adytail, _8$1), _8$1, cdx, _16b), _16b,
- scale(scale(4, cc, adytail, _8$1), _8$1, -bdx, _16c), _16c, _32, _48$1), _48$1);
- }
- if (bdxtail !== 0) {
- bxtcalen = scale(4, ca, bdxtail, bxtca);
- finlen = finadd(finlen, sum_three(
- scale(bxtcalen, bxtca, 2 * bdx, _16$1), _16$1,
- scale(scale(4, aa, bdxtail, _8$1), _8$1, cdy, _16b), _16b,
- scale(scale(4, cc, bdxtail, _8$1), _8$1, -ady, _16c), _16c, _32, _48$1), _48$1);
- }
- if (bdytail !== 0) {
- bytcalen = scale(4, ca, bdytail, bytca);
- finlen = finadd(finlen, sum_three(
- scale(bytcalen, bytca, 2 * bdy, _16$1), _16$1,
- scale(scale(4, cc, bdytail, _8$1), _8$1, adx, _16b), _16b,
- scale(scale(4, aa, bdytail, _8$1), _8$1, -cdx, _16c), _16c, _32, _48$1), _48$1);
- }
- if (cdxtail !== 0) {
- cxtablen = scale(4, ab$1, cdxtail, cxtab);
- finlen = finadd(finlen, sum_three(
- scale(cxtablen, cxtab, 2 * cdx, _16$1), _16$1,
- scale(scale(4, bb, cdxtail, _8$1), _8$1, ady, _16b), _16b,
- scale(scale(4, aa, cdxtail, _8$1), _8$1, -bdy, _16c), _16c, _32, _48$1), _48$1);
- }
- if (cdytail !== 0) {
- cytablen = scale(4, ab$1, cdytail, cytab);
- finlen = finadd(finlen, sum_three(
- scale(cytablen, cytab, 2 * cdy, _16$1), _16$1,
- scale(scale(4, aa, cdytail, _8$1), _8$1, bdx, _16b), _16b,
- scale(scale(4, bb, cdytail, _8$1), _8$1, -adx, _16c), _16c, _32, _48$1), _48$1);
- }
-
- if (adxtail !== 0 || adytail !== 0) {
- if (bdxtail !== 0 || bdytail !== 0 || cdxtail !== 0 || cdytail !== 0) {
- s1 = bdxtail * cdy;
- c = splitter * bdxtail;
- ahi = c - (c - bdxtail);
- alo = bdxtail - ahi;
- c = splitter * cdy;
- bhi = c - (c - cdy);
- blo = cdy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = bdx * cdytail;
- c = splitter * bdx;
- ahi = c - (c - bdx);
- alo = bdx - ahi;
- c = splitter * cdytail;
- bhi = c - (c - cdytail);
- blo = cdytail - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 + t0;
- bvirt = _i - s0;
- u[0] = s0 - (_i - bvirt) + (t0 - bvirt);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 + t1;
- bvirt = _i - _0;
- u[1] = _0 - (_i - bvirt) + (t1 - bvirt);
- u3 = _j + _i;
- bvirt = u3 - _j;
- u[2] = _j - (u3 - bvirt) + (_i - bvirt);
- u[3] = u3;
- s1 = cdxtail * -bdy;
- c = splitter * cdxtail;
- ahi = c - (c - cdxtail);
- alo = cdxtail - ahi;
- c = splitter * -bdy;
- bhi = c - (c - -bdy);
- blo = -bdy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = cdx * -bdytail;
- c = splitter * cdx;
- ahi = c - (c - cdx);
- alo = cdx - ahi;
- c = splitter * -bdytail;
- bhi = c - (c - -bdytail);
- blo = -bdytail - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 + t0;
- bvirt = _i - s0;
- v[0] = s0 - (_i - bvirt) + (t0 - bvirt);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 + t1;
- bvirt = _i - _0;
- v[1] = _0 - (_i - bvirt) + (t1 - bvirt);
- u3 = _j + _i;
- bvirt = u3 - _j;
- v[2] = _j - (u3 - bvirt) + (_i - bvirt);
- v[3] = u3;
- bctlen = sum(4, u, 4, v, bct);
- s1 = bdxtail * cdytail;
- c = splitter * bdxtail;
- ahi = c - (c - bdxtail);
- alo = bdxtail - ahi;
- c = splitter * cdytail;
- bhi = c - (c - cdytail);
- blo = cdytail - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = cdxtail * bdytail;
- c = splitter * cdxtail;
- ahi = c - (c - cdxtail);
- alo = cdxtail - ahi;
- c = splitter * bdytail;
- bhi = c - (c - bdytail);
- blo = bdytail - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- bctt[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- bctt[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- bctt[2] = _j - (u3 - bvirt) + (_i - bvirt);
- bctt[3] = u3;
- bcttlen = 4;
- } else {
- bct[0] = 0;
- bctlen = 1;
- bctt[0] = 0;
- bcttlen = 1;
- }
- if (adxtail !== 0) {
- const len = scale(bctlen, bct, adxtail, _16c);
- finlen = finadd(finlen, sum(
- scale(axtbclen, axtbc, adxtail, _16$1), _16$1,
- scale(len, _16c, 2 * adx, _32), _32, _48$1), _48$1);
-
- const len2 = scale(bcttlen, bctt, adxtail, _8$1);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8$1, 2 * adx, _16$1), _16$1,
- scale(len2, _8$1, adxtail, _16b), _16b,
- scale(len, _16c, adxtail, _32), _32, _32b, _64), _64);
-
- if (bdytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, cc, adxtail, _8$1), _8$1, bdytail, _16$1), _16$1);
- }
- if (cdytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, bb, -adxtail, _8$1), _8$1, cdytail, _16$1), _16$1);
- }
- }
- if (adytail !== 0) {
- const len = scale(bctlen, bct, adytail, _16c);
- finlen = finadd(finlen, sum(
- scale(aytbclen, aytbc, adytail, _16$1), _16$1,
- scale(len, _16c, 2 * ady, _32), _32, _48$1), _48$1);
-
- const len2 = scale(bcttlen, bctt, adytail, _8$1);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8$1, 2 * ady, _16$1), _16$1,
- scale(len2, _8$1, adytail, _16b), _16b,
- scale(len, _16c, adytail, _32), _32, _32b, _64), _64);
- }
- }
- if (bdxtail !== 0 || bdytail !== 0) {
- if (cdxtail !== 0 || cdytail !== 0 || adxtail !== 0 || adytail !== 0) {
- s1 = cdxtail * ady;
- c = splitter * cdxtail;
- ahi = c - (c - cdxtail);
- alo = cdxtail - ahi;
- c = splitter * ady;
- bhi = c - (c - ady);
- blo = ady - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = cdx * adytail;
- c = splitter * cdx;
- ahi = c - (c - cdx);
- alo = cdx - ahi;
- c = splitter * adytail;
- bhi = c - (c - adytail);
- blo = adytail - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 + t0;
- bvirt = _i - s0;
- u[0] = s0 - (_i - bvirt) + (t0 - bvirt);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 + t1;
- bvirt = _i - _0;
- u[1] = _0 - (_i - bvirt) + (t1 - bvirt);
- u3 = _j + _i;
- bvirt = u3 - _j;
- u[2] = _j - (u3 - bvirt) + (_i - bvirt);
- u[3] = u3;
- n1 = -cdy;
- n0 = -cdytail;
- s1 = adxtail * n1;
- c = splitter * adxtail;
- ahi = c - (c - adxtail);
- alo = adxtail - ahi;
- c = splitter * n1;
- bhi = c - (c - n1);
- blo = n1 - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = adx * n0;
- c = splitter * adx;
- ahi = c - (c - adx);
- alo = adx - ahi;
- c = splitter * n0;
- bhi = c - (c - n0);
- blo = n0 - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 + t0;
- bvirt = _i - s0;
- v[0] = s0 - (_i - bvirt) + (t0 - bvirt);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 + t1;
- bvirt = _i - _0;
- v[1] = _0 - (_i - bvirt) + (t1 - bvirt);
- u3 = _j + _i;
- bvirt = u3 - _j;
- v[2] = _j - (u3 - bvirt) + (_i - bvirt);
- v[3] = u3;
- catlen = sum(4, u, 4, v, cat);
- s1 = cdxtail * adytail;
- c = splitter * cdxtail;
- ahi = c - (c - cdxtail);
- alo = cdxtail - ahi;
- c = splitter * adytail;
- bhi = c - (c - adytail);
- blo = adytail - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = adxtail * cdytail;
- c = splitter * adxtail;
- ahi = c - (c - adxtail);
- alo = adxtail - ahi;
- c = splitter * cdytail;
- bhi = c - (c - cdytail);
- blo = cdytail - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- catt[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- catt[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- catt[2] = _j - (u3 - bvirt) + (_i - bvirt);
- catt[3] = u3;
- cattlen = 4;
- } else {
- cat[0] = 0;
- catlen = 1;
- catt[0] = 0;
- cattlen = 1;
- }
- if (bdxtail !== 0) {
- const len = scale(catlen, cat, bdxtail, _16c);
- finlen = finadd(finlen, sum(
- scale(bxtcalen, bxtca, bdxtail, _16$1), _16$1,
- scale(len, _16c, 2 * bdx, _32), _32, _48$1), _48$1);
-
- const len2 = scale(cattlen, catt, bdxtail, _8$1);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8$1, 2 * bdx, _16$1), _16$1,
- scale(len2, _8$1, bdxtail, _16b), _16b,
- scale(len, _16c, bdxtail, _32), _32, _32b, _64), _64);
-
- if (cdytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, aa, bdxtail, _8$1), _8$1, cdytail, _16$1), _16$1);
- }
- if (adytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, cc, -bdxtail, _8$1), _8$1, adytail, _16$1), _16$1);
- }
- }
- if (bdytail !== 0) {
- const len = scale(catlen, cat, bdytail, _16c);
- finlen = finadd(finlen, sum(
- scale(bytcalen, bytca, bdytail, _16$1), _16$1,
- scale(len, _16c, 2 * bdy, _32), _32, _48$1), _48$1);
-
- const len2 = scale(cattlen, catt, bdytail, _8$1);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8$1, 2 * bdy, _16$1), _16$1,
- scale(len2, _8$1, bdytail, _16b), _16b,
- scale(len, _16c, bdytail, _32), _32, _32b, _64), _64);
- }
- }
- if (cdxtail !== 0 || cdytail !== 0) {
- if (adxtail !== 0 || adytail !== 0 || bdxtail !== 0 || bdytail !== 0) {
- s1 = adxtail * bdy;
- c = splitter * adxtail;
- ahi = c - (c - adxtail);
- alo = adxtail - ahi;
- c = splitter * bdy;
- bhi = c - (c - bdy);
- blo = bdy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = adx * bdytail;
- c = splitter * adx;
- ahi = c - (c - adx);
- alo = adx - ahi;
- c = splitter * bdytail;
- bhi = c - (c - bdytail);
- blo = bdytail - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 + t0;
- bvirt = _i - s0;
- u[0] = s0 - (_i - bvirt) + (t0 - bvirt);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 + t1;
- bvirt = _i - _0;
- u[1] = _0 - (_i - bvirt) + (t1 - bvirt);
- u3 = _j + _i;
- bvirt = u3 - _j;
- u[2] = _j - (u3 - bvirt) + (_i - bvirt);
- u[3] = u3;
- n1 = -ady;
- n0 = -adytail;
- s1 = bdxtail * n1;
- c = splitter * bdxtail;
- ahi = c - (c - bdxtail);
- alo = bdxtail - ahi;
- c = splitter * n1;
- bhi = c - (c - n1);
- blo = n1 - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = bdx * n0;
- c = splitter * bdx;
- ahi = c - (c - bdx);
- alo = bdx - ahi;
- c = splitter * n0;
- bhi = c - (c - n0);
- blo = n0 - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 + t0;
- bvirt = _i - s0;
- v[0] = s0 - (_i - bvirt) + (t0 - bvirt);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 + t1;
- bvirt = _i - _0;
- v[1] = _0 - (_i - bvirt) + (t1 - bvirt);
- u3 = _j + _i;
- bvirt = u3 - _j;
- v[2] = _j - (u3 - bvirt) + (_i - bvirt);
- v[3] = u3;
- abtlen = sum(4, u, 4, v, abt);
- s1 = adxtail * bdytail;
- c = splitter * adxtail;
- ahi = c - (c - adxtail);
- alo = adxtail - ahi;
- c = splitter * bdytail;
- bhi = c - (c - bdytail);
- blo = bdytail - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = bdxtail * adytail;
- c = splitter * bdxtail;
- ahi = c - (c - bdxtail);
- alo = bdxtail - ahi;
- c = splitter * adytail;
- bhi = c - (c - adytail);
- blo = adytail - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- abtt[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- abtt[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- abtt[2] = _j - (u3 - bvirt) + (_i - bvirt);
- abtt[3] = u3;
- abttlen = 4;
- } else {
- abt[0] = 0;
- abtlen = 1;
- abtt[0] = 0;
- abttlen = 1;
- }
- if (cdxtail !== 0) {
- const len = scale(abtlen, abt, cdxtail, _16c);
- finlen = finadd(finlen, sum(
- scale(cxtablen, cxtab, cdxtail, _16$1), _16$1,
- scale(len, _16c, 2 * cdx, _32), _32, _48$1), _48$1);
-
- const len2 = scale(abttlen, abtt, cdxtail, _8$1);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8$1, 2 * cdx, _16$1), _16$1,
- scale(len2, _8$1, cdxtail, _16b), _16b,
- scale(len, _16c, cdxtail, _32), _32, _32b, _64), _64);
-
- if (adytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, bb, cdxtail, _8$1), _8$1, adytail, _16$1), _16$1);
- }
- if (bdytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, aa, -cdxtail, _8$1), _8$1, bdytail, _16$1), _16$1);
- }
- }
- if (cdytail !== 0) {
- const len = scale(abtlen, abt, cdytail, _16c);
- finlen = finadd(finlen, sum(
- scale(cytablen, cytab, cdytail, _16$1), _16$1,
- scale(len, _16c, 2 * cdy, _32), _32, _48$1), _48$1);
-
- const len2 = scale(abttlen, abtt, cdytail, _8$1);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8$1, 2 * cdy, _16$1), _16$1,
- scale(len2, _8$1, cdytail, _16b), _16b,
- scale(len, _16c, cdytail, _32), _32, _32b, _64), _64);
- }
- }
-
- return fin$1[finlen - 1];
- }
-
- function incircle(ax, ay, bx, by, cx, cy, dx, dy) {
- const adx = ax - dx;
- const bdx = bx - dx;
- const cdx = cx - dx;
- const ady = ay - dy;
- const bdy = by - dy;
- const cdy = cy - dy;
-
- const bdxcdy = bdx * cdy;
- const cdxbdy = cdx * bdy;
- const alift = adx * adx + ady * ady;
-
- const cdxady = cdx * ady;
- const adxcdy = adx * cdy;
- const blift = bdx * bdx + bdy * bdy;
-
- const adxbdy = adx * bdy;
- const bdxady = bdx * ady;
- const clift = cdx * cdx + cdy * cdy;
-
- const det =
- alift * (bdxcdy - cdxbdy) +
- blift * (cdxady - adxcdy) +
- clift * (adxbdy - bdxady);
-
- const permanent =
- (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * alift +
- (Math.abs(cdxady) + Math.abs(adxcdy)) * blift +
- (Math.abs(adxbdy) + Math.abs(bdxady)) * clift;
-
- const errbound = iccerrboundA * permanent;
-
- if (det > errbound || -det > errbound) {
- return det;
- }
- return incircleadapt(ax, ay, bx, by, cx, cy, dx, dy, permanent);
- }
-
- function incirclefast(ax, ay, bx, by, cx, cy, dx, dy) {
- const adx = ax - dx;
- const ady = ay - dy;
- const bdx = bx - dx;
- const bdy = by - dy;
- const cdx = cx - dx;
- const cdy = cy - dy;
-
- const abdet = adx * bdy - bdx * ady;
- const bcdet = bdx * cdy - cdx * bdy;
- const cadet = cdx * ady - adx * cdy;
- const alift = adx * adx + ady * ady;
- const blift = bdx * bdx + bdy * bdy;
- const clift = cdx * cdx + cdy * cdy;
-
- return alift * bcdet + blift * cadet + clift * abdet;
- }
-
- const isperrboundA = (16 + 224 * epsilon) * epsilon;
- const isperrboundB = (5 + 72 * epsilon) * epsilon;
- const isperrboundC = (71 + 1408 * epsilon) * epsilon * epsilon;
-
- const ab = vec(4);
- const bc = vec(4);
- const cd = vec(4);
- const de = vec(4);
- const ea = vec(4);
- const ac = vec(4);
- const bd = vec(4);
- const ce = vec(4);
- const da = vec(4);
- const eb = vec(4);
-
- const abc = vec(24);
- const bcd = vec(24);
- const cde = vec(24);
- const dea = vec(24);
- const eab = vec(24);
- const abd = vec(24);
- const bce = vec(24);
- const cda = vec(24);
- const deb = vec(24);
- const eac = vec(24);
-
- const adet = vec(1152);
- const bdet = vec(1152);
- const cdet = vec(1152);
- const ddet = vec(1152);
- const edet = vec(1152);
- const abdet = vec(2304);
- const cddet = vec(2304);
- const cdedet = vec(3456);
- const deter = vec(5760);
-
- const _8 = vec(8);
- const _8b = vec(8);
- const _8c = vec(8);
- const _16 = vec(16);
- const _24 = vec(24);
- const _48 = vec(48);
- const _48b = vec(48);
- const _96 = vec(96);
- const _192 = vec(192);
- const _384x = vec(384);
- const _384y = vec(384);
- const _384z = vec(384);
- const _768 = vec(768);
-
- function sum_three_scale(a, b, c, az, bz, cz, out) {
- return sum_three(
- scale(4, a, az, _8), _8,
- scale(4, b, bz, _8b), _8b,
- scale(4, c, cz, _8c), _8c, _16, out);
- }
-
- function liftexact(alen, a, blen, b, clen, c, dlen, d, x, y, z, out) {
- const len = sum(
- sum(alen, a, blen, b, _48), _48,
- negate(sum(clen, c, dlen, d, _48b), _48b), _48b, _96);
-
- return sum_three(
- scale(scale(len, _96, x, _192), _192, x, _384x), _384x,
- scale(scale(len, _96, y, _192), _192, y, _384y), _384y,
- scale(scale(len, _96, z, _192), _192, z, _384z), _384z, _768, out);
- }
-
- function insphereexact(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez) {
- let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
-
- s1 = ax * by;
- c = splitter * ax;
- ahi = c - (c - ax);
- alo = ax - ahi;
- c = splitter * by;
- bhi = c - (c - by);
- blo = by - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = bx * ay;
- c = splitter * bx;
- ahi = c - (c - bx);
- alo = bx - ahi;
- c = splitter * ay;
- bhi = c - (c - ay);
- blo = ay - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- ab[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- ab[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- ab[2] = _j - (u3 - bvirt) + (_i - bvirt);
- ab[3] = u3;
- s1 = bx * cy;
- c = splitter * bx;
- ahi = c - (c - bx);
- alo = bx - ahi;
- c = splitter * cy;
- bhi = c - (c - cy);
- blo = cy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = cx * by;
- c = splitter * cx;
- ahi = c - (c - cx);
- alo = cx - ahi;
- c = splitter * by;
- bhi = c - (c - by);
- blo = by - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- bc[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- bc[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- bc[2] = _j - (u3 - bvirt) + (_i - bvirt);
- bc[3] = u3;
- s1 = cx * dy;
- c = splitter * cx;
- ahi = c - (c - cx);
- alo = cx - ahi;
- c = splitter * dy;
- bhi = c - (c - dy);
- blo = dy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = dx * cy;
- c = splitter * dx;
- ahi = c - (c - dx);
- alo = dx - ahi;
- c = splitter * cy;
- bhi = c - (c - cy);
- blo = cy - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- cd[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- cd[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- cd[2] = _j - (u3 - bvirt) + (_i - bvirt);
- cd[3] = u3;
- s1 = dx * ey;
- c = splitter * dx;
- ahi = c - (c - dx);
- alo = dx - ahi;
- c = splitter * ey;
- bhi = c - (c - ey);
- blo = ey - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = ex * dy;
- c = splitter * ex;
- ahi = c - (c - ex);
- alo = ex - ahi;
- c = splitter * dy;
- bhi = c - (c - dy);
- blo = dy - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- de[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- de[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- de[2] = _j - (u3 - bvirt) + (_i - bvirt);
- de[3] = u3;
- s1 = ex * ay;
- c = splitter * ex;
- ahi = c - (c - ex);
- alo = ex - ahi;
- c = splitter * ay;
- bhi = c - (c - ay);
- blo = ay - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = ax * ey;
- c = splitter * ax;
- ahi = c - (c - ax);
- alo = ax - ahi;
- c = splitter * ey;
- bhi = c - (c - ey);
- blo = ey - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- ea[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- ea[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- ea[2] = _j - (u3 - bvirt) + (_i - bvirt);
- ea[3] = u3;
- s1 = ax * cy;
- c = splitter * ax;
- ahi = c - (c - ax);
- alo = ax - ahi;
- c = splitter * cy;
- bhi = c - (c - cy);
- blo = cy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = cx * ay;
- c = splitter * cx;
- ahi = c - (c - cx);
- alo = cx - ahi;
- c = splitter * ay;
- bhi = c - (c - ay);
- blo = ay - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- ac[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- ac[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- ac[2] = _j - (u3 - bvirt) + (_i - bvirt);
- ac[3] = u3;
- s1 = bx * dy;
- c = splitter * bx;
- ahi = c - (c - bx);
- alo = bx - ahi;
- c = splitter * dy;
- bhi = c - (c - dy);
- blo = dy - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = dx * by;
- c = splitter * dx;
- ahi = c - (c - dx);
- alo = dx - ahi;
- c = splitter * by;
- bhi = c - (c - by);
- blo = by - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- bd[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- bd[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- bd[2] = _j - (u3 - bvirt) + (_i - bvirt);
- bd[3] = u3;
- s1 = cx * ey;
- c = splitter * cx;
- ahi = c - (c - cx);
- alo = cx - ahi;
- c = splitter * ey;
- bhi = c - (c - ey);
- blo = ey - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = ex * cy;
- c = splitter * ex;
- ahi = c - (c - ex);
- alo = ex - ahi;
- c = splitter * cy;
- bhi = c - (c - cy);
- blo = cy - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- ce[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- ce[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- ce[2] = _j - (u3 - bvirt) + (_i - bvirt);
- ce[3] = u3;
- s1 = dx * ay;
- c = splitter * dx;
- ahi = c - (c - dx);
- alo = dx - ahi;
- c = splitter * ay;
- bhi = c - (c - ay);
- blo = ay - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = ax * dy;
- c = splitter * ax;
- ahi = c - (c - ax);
- alo = ax - ahi;
- c = splitter * dy;
- bhi = c - (c - dy);
- blo = dy - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- da[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- da[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- da[2] = _j - (u3 - bvirt) + (_i - bvirt);
- da[3] = u3;
- s1 = ex * by;
- c = splitter * ex;
- ahi = c - (c - ex);
- alo = ex - ahi;
- c = splitter * by;
- bhi = c - (c - by);
- blo = by - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = bx * ey;
- c = splitter * bx;
- ahi = c - (c - bx);
- alo = bx - ahi;
- c = splitter * ey;
- bhi = c - (c - ey);
- blo = ey - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- eb[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- eb[1] = _0 - (_i + bvirt) + (bvirt - t1);
- u3 = _j + _i;
- bvirt = u3 - _j;
- eb[2] = _j - (u3 - bvirt) + (_i - bvirt);
- eb[3] = u3;
-
- const abclen = sum_three_scale(ab, bc, ac, cz, az, -bz, abc);
- const bcdlen = sum_three_scale(bc, cd, bd, dz, bz, -cz, bcd);
- const cdelen = sum_three_scale(cd, de, ce, ez, cz, -dz, cde);
- const dealen = sum_three_scale(de, ea, da, az, dz, -ez, dea);
- const eablen = sum_three_scale(ea, ab, eb, bz, ez, -az, eab);
- const abdlen = sum_three_scale(ab, bd, da, dz, az, bz, abd);
- const bcelen = sum_three_scale(bc, ce, eb, ez, bz, cz, bce);
- const cdalen = sum_three_scale(cd, da, ac, az, cz, dz, cda);
- const deblen = sum_three_scale(de, eb, bd, bz, dz, ez, deb);
- const eaclen = sum_three_scale(ea, ac, ce, cz, ez, az, eac);
-
- const deterlen = sum_three(
- liftexact(cdelen, cde, bcelen, bce, deblen, deb, bcdlen, bcd, ax, ay, az, adet), adet,
- liftexact(dealen, dea, cdalen, cda, eaclen, eac, cdelen, cde, bx, by, bz, bdet), bdet,
- sum_three(
- liftexact(eablen, eab, deblen, deb, abdlen, abd, dealen, dea, cx, cy, cz, cdet), cdet,
- liftexact(abclen, abc, eaclen, eac, bcelen, bce, eablen, eab, dx, dy, dz, ddet), ddet,
- liftexact(bcdlen, bcd, abdlen, abd, cdalen, cda, abclen, abc, ex, ey, ez, edet), edet, cddet, cdedet), cdedet, abdet, deter);
-
- return deter[deterlen - 1];
- }
-
- const xdet = vec(96);
- const ydet = vec(96);
- const zdet = vec(96);
- const fin = vec(1152);
-
- function liftadapt(a, b, c, az, bz, cz, x, y, z, out) {
- const len = sum_three_scale(a, b, c, az, bz, cz, _24);
- return sum_three(
- scale(scale(len, _24, x, _48), _48, x, xdet), xdet,
- scale(scale(len, _24, y, _48), _48, y, ydet), ydet,
- scale(scale(len, _24, z, _48), _48, z, zdet), zdet, _192, out);
- }
-
- function insphereadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez, permanent) {
- let ab3, bc3, cd3, da3, ac3, bd3;
-
- let aextail, bextail, cextail, dextail;
- let aeytail, beytail, ceytail, deytail;
- let aeztail, beztail, ceztail, deztail;
-
- let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0;
-
- const aex = ax - ex;
- const bex = bx - ex;
- const cex = cx - ex;
- const dex = dx - ex;
- const aey = ay - ey;
- const bey = by - ey;
- const cey = cy - ey;
- const dey = dy - ey;
- const aez = az - ez;
- const bez = bz - ez;
- const cez = cz - ez;
- const dez = dz - ez;
-
- s1 = aex * bey;
- c = splitter * aex;
- ahi = c - (c - aex);
- alo = aex - ahi;
- c = splitter * bey;
- bhi = c - (c - bey);
- blo = bey - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = bex * aey;
- c = splitter * bex;
- ahi = c - (c - bex);
- alo = bex - ahi;
- c = splitter * aey;
- bhi = c - (c - aey);
- blo = aey - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- ab[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- ab[1] = _0 - (_i + bvirt) + (bvirt - t1);
- ab3 = _j + _i;
- bvirt = ab3 - _j;
- ab[2] = _j - (ab3 - bvirt) + (_i - bvirt);
- ab[3] = ab3;
- s1 = bex * cey;
- c = splitter * bex;
- ahi = c - (c - bex);
- alo = bex - ahi;
- c = splitter * cey;
- bhi = c - (c - cey);
- blo = cey - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = cex * bey;
- c = splitter * cex;
- ahi = c - (c - cex);
- alo = cex - ahi;
- c = splitter * bey;
- bhi = c - (c - bey);
- blo = bey - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- bc[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- bc[1] = _0 - (_i + bvirt) + (bvirt - t1);
- bc3 = _j + _i;
- bvirt = bc3 - _j;
- bc[2] = _j - (bc3 - bvirt) + (_i - bvirt);
- bc[3] = bc3;
- s1 = cex * dey;
- c = splitter * cex;
- ahi = c - (c - cex);
- alo = cex - ahi;
- c = splitter * dey;
- bhi = c - (c - dey);
- blo = dey - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = dex * cey;
- c = splitter * dex;
- ahi = c - (c - dex);
- alo = dex - ahi;
- c = splitter * cey;
- bhi = c - (c - cey);
- blo = cey - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- cd[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- cd[1] = _0 - (_i + bvirt) + (bvirt - t1);
- cd3 = _j + _i;
- bvirt = cd3 - _j;
- cd[2] = _j - (cd3 - bvirt) + (_i - bvirt);
- cd[3] = cd3;
- s1 = dex * aey;
- c = splitter * dex;
- ahi = c - (c - dex);
- alo = dex - ahi;
- c = splitter * aey;
- bhi = c - (c - aey);
- blo = aey - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = aex * dey;
- c = splitter * aex;
- ahi = c - (c - aex);
- alo = aex - ahi;
- c = splitter * dey;
- bhi = c - (c - dey);
- blo = dey - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- da[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- da[1] = _0 - (_i + bvirt) + (bvirt - t1);
- da3 = _j + _i;
- bvirt = da3 - _j;
- da[2] = _j - (da3 - bvirt) + (_i - bvirt);
- da[3] = da3;
- s1 = aex * cey;
- c = splitter * aex;
- ahi = c - (c - aex);
- alo = aex - ahi;
- c = splitter * cey;
- bhi = c - (c - cey);
- blo = cey - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = cex * aey;
- c = splitter * cex;
- ahi = c - (c - cex);
- alo = cex - ahi;
- c = splitter * aey;
- bhi = c - (c - aey);
- blo = aey - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- ac[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- ac[1] = _0 - (_i + bvirt) + (bvirt - t1);
- ac3 = _j + _i;
- bvirt = ac3 - _j;
- ac[2] = _j - (ac3 - bvirt) + (_i - bvirt);
- ac[3] = ac3;
- s1 = bex * dey;
- c = splitter * bex;
- ahi = c - (c - bex);
- alo = bex - ahi;
- c = splitter * dey;
- bhi = c - (c - dey);
- blo = dey - bhi;
- s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
- t1 = dex * bey;
- c = splitter * dex;
- ahi = c - (c - dex);
- alo = dex - ahi;
- c = splitter * bey;
- bhi = c - (c - bey);
- blo = bey - bhi;
- t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
- _i = s0 - t0;
- bvirt = s0 - _i;
- bd[0] = s0 - (_i + bvirt) + (bvirt - t0);
- _j = s1 + _i;
- bvirt = _j - s1;
- _0 = s1 - (_j - bvirt) + (_i - bvirt);
- _i = _0 - t1;
- bvirt = _0 - _i;
- bd[1] = _0 - (_i + bvirt) + (bvirt - t1);
- bd3 = _j + _i;
- bvirt = bd3 - _j;
- bd[2] = _j - (bd3 - bvirt) + (_i - bvirt);
- bd[3] = bd3;
-
- const finlen = sum(
- sum(
- negate(liftadapt(bc, cd, bd, dez, bez, -cez, aex, aey, aez, adet), adet), adet,
- liftadapt(cd, da, ac, aez, cez, dez, bex, bey, bez, bdet), bdet, abdet), abdet,
- sum(
- negate(liftadapt(da, ab, bd, bez, dez, aez, cex, cey, cez, cdet), cdet), cdet,
- liftadapt(ab, bc, ac, cez, aez, -bez, dex, dey, dez, ddet), ddet, cddet), cddet, fin);
-
- let det = estimate(finlen, fin);
- let errbound = isperrboundB * permanent;
- if (det >= errbound || -det >= errbound) {
- return det;
- }
-
- bvirt = ax - aex;
- aextail = ax - (aex + bvirt) + (bvirt - ex);
- bvirt = ay - aey;
- aeytail = ay - (aey + bvirt) + (bvirt - ey);
- bvirt = az - aez;
- aeztail = az - (aez + bvirt) + (bvirt - ez);
- bvirt = bx - bex;
- bextail = bx - (bex + bvirt) + (bvirt - ex);
- bvirt = by - bey;
- beytail = by - (bey + bvirt) + (bvirt - ey);
- bvirt = bz - bez;
- beztail = bz - (bez + bvirt) + (bvirt - ez);
- bvirt = cx - cex;
- cextail = cx - (cex + bvirt) + (bvirt - ex);
- bvirt = cy - cey;
- ceytail = cy - (cey + bvirt) + (bvirt - ey);
- bvirt = cz - cez;
- ceztail = cz - (cez + bvirt) + (bvirt - ez);
- bvirt = dx - dex;
- dextail = dx - (dex + bvirt) + (bvirt - ex);
- bvirt = dy - dey;
- deytail = dy - (dey + bvirt) + (bvirt - ey);
- bvirt = dz - dez;
- deztail = dz - (dez + bvirt) + (bvirt - ez);
- if (aextail === 0 && aeytail === 0 && aeztail === 0 &&
- bextail === 0 && beytail === 0 && beztail === 0 &&
- cextail === 0 && ceytail === 0 && ceztail === 0 &&
- dextail === 0 && deytail === 0 && deztail === 0) {
- return det;
- }
-
- errbound = isperrboundC * permanent + resulterrbound * Math.abs(det);
-
- const abeps = (aex * beytail + bey * aextail) - (aey * bextail + bex * aeytail);
- const bceps = (bex * ceytail + cey * bextail) - (bey * cextail + cex * beytail);
- const cdeps = (cex * deytail + dey * cextail) - (cey * dextail + dex * ceytail);
- const daeps = (dex * aeytail + aey * dextail) - (dey * aextail + aex * deytail);
- const aceps = (aex * ceytail + cey * aextail) - (aey * cextail + cex * aeytail);
- const bdeps = (bex * deytail + dey * bextail) - (bey * dextail + dex * beytail);
- det +=
- (((bex * bex + bey * bey + bez * bez) * ((cez * daeps + dez * aceps + aez * cdeps) +
- (ceztail * da3 + deztail * ac3 + aeztail * cd3)) + (dex * dex + dey * dey + dez * dez) *
- ((aez * bceps - bez * aceps + cez * abeps) + (aeztail * bc3 - beztail * ac3 + ceztail * ab3))) -
- ((aex * aex + aey * aey + aez * aez) * ((bez * cdeps - cez * bdeps + dez * bceps) +
- (beztail * cd3 - ceztail * bd3 + deztail * bc3)) + (cex * cex + cey * cey + cez * cez) *
- ((dez * abeps + aez * bdeps + bez * daeps) + (deztail * ab3 + aeztail * bd3 + beztail * da3)))) +
- 2 * (((bex * bextail + bey * beytail + bez * beztail) * (cez * da3 + dez * ac3 + aez * cd3) +
- (dex * dextail + dey * deytail + dez * deztail) * (aez * bc3 - bez * ac3 + cez * ab3)) -
- ((aex * aextail + aey * aeytail + aez * aeztail) * (bez * cd3 - cez * bd3 + dez * bc3) +
- (cex * cextail + cey * ceytail + cez * ceztail) * (dez * ab3 + aez * bd3 + bez * da3)));
-
- if (det >= errbound || -det >= errbound) {
- return det;
- }
-
- return insphereexact(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez);
- }
-
- function insphere(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez) {
- const aex = ax - ex;
- const bex = bx - ex;
- const cex = cx - ex;
- const dex = dx - ex;
- const aey = ay - ey;
- const bey = by - ey;
- const cey = cy - ey;
- const dey = dy - ey;
- const aez = az - ez;
- const bez = bz - ez;
- const cez = cz - ez;
- const dez = dz - ez;
-
- const aexbey = aex * bey;
- const bexaey = bex * aey;
- const ab = aexbey - bexaey;
- const bexcey = bex * cey;
- const cexbey = cex * bey;
- const bc = bexcey - cexbey;
- const cexdey = cex * dey;
- const dexcey = dex * cey;
- const cd = cexdey - dexcey;
- const dexaey = dex * aey;
- const aexdey = aex * dey;
- const da = dexaey - aexdey;
- const aexcey = aex * cey;
- const cexaey = cex * aey;
- const ac = aexcey - cexaey;
- const bexdey = bex * dey;
- const dexbey = dex * bey;
- const bd = bexdey - dexbey;
-
- const alift = aex * aex + aey * aey + aez * aez;
- const blift = bex * bex + bey * bey + bez * bez;
- const clift = cex * cex + cey * cey + cez * cez;
- const dlift = dex * dex + dey * dey + dez * dez;
-
- const det =
- (clift * (dez * ab + aez * bd + bez * da) - dlift * (aez * bc - bez * ac + cez * ab)) +
- (alift * (bez * cd - cez * bd + dez * bc) - blift * (cez * da + dez * ac + aez * cd));
-
- const aezplus = Math.abs(aez);
- const bezplus = Math.abs(bez);
- const cezplus = Math.abs(cez);
- const dezplus = Math.abs(dez);
- const aexbeyplus = Math.abs(aexbey) + Math.abs(bexaey);
- const bexceyplus = Math.abs(bexcey) + Math.abs(cexbey);
- const cexdeyplus = Math.abs(cexdey) + Math.abs(dexcey);
- const dexaeyplus = Math.abs(dexaey) + Math.abs(aexdey);
- const aexceyplus = Math.abs(aexcey) + Math.abs(cexaey);
- const bexdeyplus = Math.abs(bexdey) + Math.abs(dexbey);
- const permanent =
- (cexdeyplus * bezplus + bexdeyplus * cezplus + bexceyplus * dezplus) * alift +
- (dexaeyplus * cezplus + aexceyplus * dezplus + cexdeyplus * aezplus) * blift +
- (aexbeyplus * dezplus + bexdeyplus * aezplus + dexaeyplus * bezplus) * clift +
- (bexceyplus * aezplus + aexceyplus * bezplus + aexbeyplus * cezplus) * dlift;
-
- const errbound = isperrboundA * permanent;
- if (det > errbound || -det > errbound) {
- return det;
- }
- return -insphereadapt(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz, ex, ey, ez, permanent);
- }
-
- function inspherefast(pax, pay, paz, pbx, pby, pbz, pcx, pcy, pcz, pdx, pdy, pdz, pex, pey, pez) {
- const aex = pax - pex;
- const bex = pbx - pex;
- const cex = pcx - pex;
- const dex = pdx - pex;
- const aey = pay - pey;
- const bey = pby - pey;
- const cey = pcy - pey;
- const dey = pdy - pey;
- const aez = paz - pez;
- const bez = pbz - pez;
- const cez = pcz - pez;
- const dez = pdz - pez;
-
- const ab = aex * bey - bex * aey;
- const bc = bex * cey - cex * bey;
- const cd = cex * dey - dex * cey;
- const da = dex * aey - aex * dey;
- const ac = aex * cey - cex * aey;
- const bd = bex * dey - dex * bey;
-
- const abc = aez * bc - bez * ac + cez * ab;
- const bcd = bez * cd - cez * bd + dez * bc;
- const cda = cez * da + dez * ac + aez * cd;
- const dab = dez * ab + aez * bd + bez * da;
-
- const alift = aex * aex + aey * aey + aez * aez;
- const blift = bex * bex + bey * bey + bez * bez;
- const clift = cex * cex + cey * cey + cez * cez;
- const dlift = dex * dex + dey * dey + dez * dez;
-
- return (clift * dab - dlift * abc) + (alift * bcd - blift * cda);
- }
-
- exports.incircle = incircle;
- exports.incirclefast = incirclefast;
- exports.insphere = insphere;
- exports.inspherefast = inspherefast;
- exports.orient2d = orient2d;
- exports.orient2dfast = orient2dfast;
- exports.orient3d = orient3d;
- exports.orient3dfast = orient3dfast;
-
- }));
|