123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765 |
- import {epsilon, splitter, resulterrbound, estimate, vec, sum, sum_three, scale} from './util.js';
-
- const iccerrboundA = (10 + 96 * epsilon) * epsilon;
- const iccerrboundB = (4 + 48 * epsilon) * epsilon;
- const iccerrboundC = (44 + 576 * epsilon) * epsilon * epsilon;
-
- const bc = vec(4);
- const ca = vec(4);
- const ab = 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 = vec(8);
- const _16 = vec(16);
- const _16b = vec(16);
- const _16c = vec(16);
- const _32 = vec(32);
- const _32b = vec(32);
- const _48 = vec(48);
- const _64 = vec(64);
-
- let fin = vec(1152);
- let fin2 = vec(1152);
-
- function finadd(finlen, a, alen) {
- finlen = sum(finlen, fin, a, alen, fin2);
- const tmp = fin; fin = 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[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 = 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[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;
-
- finlen = sum(
- sum(
- sum(
- scale(scale(4, bc, adx, _8), _8, adx, _16), _16,
- scale(scale(4, bc, ady, _8), _8, ady, _16b), _16b, _32), _32,
- sum(
- scale(scale(4, ca, bdx, _8), _8, bdx, _16), _16,
- scale(scale(4, ca, bdy, _8), _8, bdy, _16b), _16b, _32b), _32b, _64), _64,
- sum(
- scale(scale(4, ab, cdx, _8), _8, cdx, _16), _16,
- scale(scale(4, ab, cdy, _8), _8, cdy, _16b), _16b, _32), _32, fin);
-
- let det = estimate(finlen, fin);
- 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, adxtail, axtbc);
- finlen = finadd(finlen, sum_three(
- scale(axtbclen, axtbc, 2 * adx, _16), _16,
- scale(scale(4, cc, adxtail, _8), _8, bdy, _16b), _16b,
- scale(scale(4, bb, adxtail, _8), _8, -cdy, _16c), _16c, _32, _48), _48);
- }
- if (adytail !== 0) {
- aytbclen = scale(4, bc, adytail, aytbc);
- finlen = finadd(finlen, sum_three(
- scale(aytbclen, aytbc, 2 * ady, _16), _16,
- scale(scale(4, bb, adytail, _8), _8, cdx, _16b), _16b,
- scale(scale(4, cc, adytail, _8), _8, -bdx, _16c), _16c, _32, _48), _48);
- }
- if (bdxtail !== 0) {
- bxtcalen = scale(4, ca, bdxtail, bxtca);
- finlen = finadd(finlen, sum_three(
- scale(bxtcalen, bxtca, 2 * bdx, _16), _16,
- scale(scale(4, aa, bdxtail, _8), _8, cdy, _16b), _16b,
- scale(scale(4, cc, bdxtail, _8), _8, -ady, _16c), _16c, _32, _48), _48);
- }
- if (bdytail !== 0) {
- bytcalen = scale(4, ca, bdytail, bytca);
- finlen = finadd(finlen, sum_three(
- scale(bytcalen, bytca, 2 * bdy, _16), _16,
- scale(scale(4, cc, bdytail, _8), _8, adx, _16b), _16b,
- scale(scale(4, aa, bdytail, _8), _8, -cdx, _16c), _16c, _32, _48), _48);
- }
- if (cdxtail !== 0) {
- cxtablen = scale(4, ab, cdxtail, cxtab);
- finlen = finadd(finlen, sum_three(
- scale(cxtablen, cxtab, 2 * cdx, _16), _16,
- scale(scale(4, bb, cdxtail, _8), _8, ady, _16b), _16b,
- scale(scale(4, aa, cdxtail, _8), _8, -bdy, _16c), _16c, _32, _48), _48);
- }
- if (cdytail !== 0) {
- cytablen = scale(4, ab, cdytail, cytab);
- finlen = finadd(finlen, sum_three(
- scale(cytablen, cytab, 2 * cdy, _16), _16,
- scale(scale(4, aa, cdytail, _8), _8, bdx, _16b), _16b,
- scale(scale(4, bb, cdytail, _8), _8, -adx, _16c), _16c, _32, _48), _48);
- }
-
- 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), _16,
- scale(len, _16c, 2 * adx, _32), _32, _48), _48);
-
- const len2 = scale(bcttlen, bctt, adxtail, _8);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8, 2 * adx, _16), _16,
- scale(len2, _8, adxtail, _16b), _16b,
- scale(len, _16c, adxtail, _32), _32, _32b, _64), _64);
-
- if (bdytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, cc, adxtail, _8), _8, bdytail, _16), _16);
- }
- if (cdytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, bb, -adxtail, _8), _8, cdytail, _16), _16);
- }
- }
- if (adytail !== 0) {
- const len = scale(bctlen, bct, adytail, _16c);
- finlen = finadd(finlen, sum(
- scale(aytbclen, aytbc, adytail, _16), _16,
- scale(len, _16c, 2 * ady, _32), _32, _48), _48);
-
- const len2 = scale(bcttlen, bctt, adytail, _8);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8, 2 * ady, _16), _16,
- scale(len2, _8, 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), _16,
- scale(len, _16c, 2 * bdx, _32), _32, _48), _48);
-
- const len2 = scale(cattlen, catt, bdxtail, _8);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8, 2 * bdx, _16), _16,
- scale(len2, _8, bdxtail, _16b), _16b,
- scale(len, _16c, bdxtail, _32), _32, _32b, _64), _64);
-
- if (cdytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, aa, bdxtail, _8), _8, cdytail, _16), _16);
- }
- if (adytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, cc, -bdxtail, _8), _8, adytail, _16), _16);
- }
- }
- if (bdytail !== 0) {
- const len = scale(catlen, cat, bdytail, _16c);
- finlen = finadd(finlen, sum(
- scale(bytcalen, bytca, bdytail, _16), _16,
- scale(len, _16c, 2 * bdy, _32), _32, _48), _48);
-
- const len2 = scale(cattlen, catt, bdytail, _8);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8, 2 * bdy, _16), _16,
- scale(len2, _8, 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), _16,
- scale(len, _16c, 2 * cdx, _32), _32, _48), _48);
-
- const len2 = scale(abttlen, abtt, cdxtail, _8);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8, 2 * cdx, _16), _16,
- scale(len2, _8, cdxtail, _16b), _16b,
- scale(len, _16c, cdxtail, _32), _32, _32b, _64), _64);
-
- if (adytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, bb, cdxtail, _8), _8, adytail, _16), _16);
- }
- if (bdytail !== 0) {
- finlen = finadd(finlen, scale(scale(4, aa, -cdxtail, _8), _8, bdytail, _16), _16);
- }
- }
- if (cdytail !== 0) {
- const len = scale(abtlen, abt, cdytail, _16c);
- finlen = finadd(finlen, sum(
- scale(cytablen, cytab, cdytail, _16), _16,
- scale(len, _16c, 2 * cdy, _32), _32, _48), _48);
-
- const len2 = scale(abttlen, abtt, cdytail, _8);
- finlen = finadd(finlen, sum_three(
- scale(len2, _8, 2 * cdy, _16), _16,
- scale(len2, _8, cdytail, _16b), _16b,
- scale(len, _16c, cdytail, _32), _32, _32b, _64), _64);
- }
- }
-
- return fin[finlen - 1];
- }
-
- export 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);
- }
-
- export 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;
- }
|