Node-Red configuration
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

incircle.js 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.predicates = {}));
  5. })(this, (function (exports) { 'use strict';
  6. const epsilon = 1.1102230246251565e-16;
  7. const splitter = 134217729;
  8. const resulterrbound = (3 + 8 * epsilon) * epsilon;
  9. // fast_expansion_sum_zeroelim routine from oritinal code
  10. function sum(elen, e, flen, f, h) {
  11. let Q, Qnew, hh, bvirt;
  12. let enow = e[0];
  13. let fnow = f[0];
  14. let eindex = 0;
  15. let findex = 0;
  16. if ((fnow > enow) === (fnow > -enow)) {
  17. Q = enow;
  18. enow = e[++eindex];
  19. } else {
  20. Q = fnow;
  21. fnow = f[++findex];
  22. }
  23. let hindex = 0;
  24. if (eindex < elen && findex < flen) {
  25. if ((fnow > enow) === (fnow > -enow)) {
  26. Qnew = enow + Q;
  27. hh = Q - (Qnew - enow);
  28. enow = e[++eindex];
  29. } else {
  30. Qnew = fnow + Q;
  31. hh = Q - (Qnew - fnow);
  32. fnow = f[++findex];
  33. }
  34. Q = Qnew;
  35. if (hh !== 0) {
  36. h[hindex++] = hh;
  37. }
  38. while (eindex < elen && findex < flen) {
  39. if ((fnow > enow) === (fnow > -enow)) {
  40. Qnew = Q + enow;
  41. bvirt = Qnew - Q;
  42. hh = Q - (Qnew - bvirt) + (enow - bvirt);
  43. enow = e[++eindex];
  44. } else {
  45. Qnew = Q + fnow;
  46. bvirt = Qnew - Q;
  47. hh = Q - (Qnew - bvirt) + (fnow - bvirt);
  48. fnow = f[++findex];
  49. }
  50. Q = Qnew;
  51. if (hh !== 0) {
  52. h[hindex++] = hh;
  53. }
  54. }
  55. }
  56. while (eindex < elen) {
  57. Qnew = Q + enow;
  58. bvirt = Qnew - Q;
  59. hh = Q - (Qnew - bvirt) + (enow - bvirt);
  60. enow = e[++eindex];
  61. Q = Qnew;
  62. if (hh !== 0) {
  63. h[hindex++] = hh;
  64. }
  65. }
  66. while (findex < flen) {
  67. Qnew = Q + fnow;
  68. bvirt = Qnew - Q;
  69. hh = Q - (Qnew - bvirt) + (fnow - bvirt);
  70. fnow = f[++findex];
  71. Q = Qnew;
  72. if (hh !== 0) {
  73. h[hindex++] = hh;
  74. }
  75. }
  76. if (Q !== 0 || hindex === 0) {
  77. h[hindex++] = Q;
  78. }
  79. return hindex;
  80. }
  81. function sum_three(alen, a, blen, b, clen, c, tmp, out) {
  82. return sum(sum(alen, a, blen, b, tmp), tmp, clen, c, out);
  83. }
  84. // scale_expansion_zeroelim routine from oritinal code
  85. function scale(elen, e, b, h) {
  86. let Q, sum, hh, product1, product0;
  87. let bvirt, c, ahi, alo, bhi, blo;
  88. c = splitter * b;
  89. bhi = c - (c - b);
  90. blo = b - bhi;
  91. let enow = e[0];
  92. Q = enow * b;
  93. c = splitter * enow;
  94. ahi = c - (c - enow);
  95. alo = enow - ahi;
  96. hh = alo * blo - (Q - ahi * bhi - alo * bhi - ahi * blo);
  97. let hindex = 0;
  98. if (hh !== 0) {
  99. h[hindex++] = hh;
  100. }
  101. for (let i = 1; i < elen; i++) {
  102. enow = e[i];
  103. product1 = enow * b;
  104. c = splitter * enow;
  105. ahi = c - (c - enow);
  106. alo = enow - ahi;
  107. product0 = alo * blo - (product1 - ahi * bhi - alo * bhi - ahi * blo);
  108. sum = Q + product0;
  109. bvirt = sum - Q;
  110. hh = Q - (sum - bvirt) + (product0 - bvirt);
  111. if (hh !== 0) {
  112. h[hindex++] = hh;
  113. }
  114. Q = product1 + sum;
  115. hh = sum - (Q - product1);
  116. if (hh !== 0) {
  117. h[hindex++] = hh;
  118. }
  119. }
  120. if (Q !== 0 || hindex === 0) {
  121. h[hindex++] = Q;
  122. }
  123. return hindex;
  124. }
  125. function estimate(elen, e) {
  126. let Q = e[0];
  127. for (let i = 1; i < elen; i++) Q += e[i];
  128. return Q;
  129. }
  130. function vec(n) {
  131. return new Float64Array(n);
  132. }
  133. const iccerrboundA = (10 + 96 * epsilon) * epsilon;
  134. const iccerrboundB = (4 + 48 * epsilon) * epsilon;
  135. const iccerrboundC = (44 + 576 * epsilon) * epsilon * epsilon;
  136. const bc = vec(4);
  137. const ca = vec(4);
  138. const ab = vec(4);
  139. const aa = vec(4);
  140. const bb = vec(4);
  141. const cc = vec(4);
  142. const u = vec(4);
  143. const v = vec(4);
  144. const axtbc = vec(8);
  145. const aytbc = vec(8);
  146. const bxtca = vec(8);
  147. const bytca = vec(8);
  148. const cxtab = vec(8);
  149. const cytab = vec(8);
  150. const abt = vec(8);
  151. const bct = vec(8);
  152. const cat = vec(8);
  153. const abtt = vec(4);
  154. const bctt = vec(4);
  155. const catt = vec(4);
  156. const _8 = vec(8);
  157. const _16 = vec(16);
  158. const _16b = vec(16);
  159. const _16c = vec(16);
  160. const _32 = vec(32);
  161. const _32b = vec(32);
  162. const _48 = vec(48);
  163. const _64 = vec(64);
  164. let fin = vec(1152);
  165. let fin2 = vec(1152);
  166. function finadd(finlen, a, alen) {
  167. finlen = sum(finlen, fin, a, alen, fin2);
  168. const tmp = fin; fin = fin2; fin2 = tmp;
  169. return finlen;
  170. }
  171. function incircleadapt(ax, ay, bx, by, cx, cy, dx, dy, permanent) {
  172. let finlen;
  173. let adxtail, bdxtail, cdxtail, adytail, bdytail, cdytail;
  174. let axtbclen, aytbclen, bxtcalen, bytcalen, cxtablen, cytablen;
  175. let abtlen, bctlen, catlen;
  176. let abttlen, bcttlen, cattlen;
  177. let n1, n0;
  178. let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
  179. const adx = ax - dx;
  180. const bdx = bx - dx;
  181. const cdx = cx - dx;
  182. const ady = ay - dy;
  183. const bdy = by - dy;
  184. const cdy = cy - dy;
  185. s1 = bdx * cdy;
  186. c = splitter * bdx;
  187. ahi = c - (c - bdx);
  188. alo = bdx - ahi;
  189. c = splitter * cdy;
  190. bhi = c - (c - cdy);
  191. blo = cdy - bhi;
  192. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  193. t1 = cdx * bdy;
  194. c = splitter * cdx;
  195. ahi = c - (c - cdx);
  196. alo = cdx - ahi;
  197. c = splitter * bdy;
  198. bhi = c - (c - bdy);
  199. blo = bdy - bhi;
  200. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  201. _i = s0 - t0;
  202. bvirt = s0 - _i;
  203. bc[0] = s0 - (_i + bvirt) + (bvirt - t0);
  204. _j = s1 + _i;
  205. bvirt = _j - s1;
  206. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  207. _i = _0 - t1;
  208. bvirt = _0 - _i;
  209. bc[1] = _0 - (_i + bvirt) + (bvirt - t1);
  210. u3 = _j + _i;
  211. bvirt = u3 - _j;
  212. bc[2] = _j - (u3 - bvirt) + (_i - bvirt);
  213. bc[3] = u3;
  214. s1 = cdx * ady;
  215. c = splitter * cdx;
  216. ahi = c - (c - cdx);
  217. alo = cdx - ahi;
  218. c = splitter * ady;
  219. bhi = c - (c - ady);
  220. blo = ady - bhi;
  221. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  222. t1 = adx * cdy;
  223. c = splitter * adx;
  224. ahi = c - (c - adx);
  225. alo = adx - ahi;
  226. c = splitter * cdy;
  227. bhi = c - (c - cdy);
  228. blo = cdy - bhi;
  229. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  230. _i = s0 - t0;
  231. bvirt = s0 - _i;
  232. ca[0] = s0 - (_i + bvirt) + (bvirt - t0);
  233. _j = s1 + _i;
  234. bvirt = _j - s1;
  235. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  236. _i = _0 - t1;
  237. bvirt = _0 - _i;
  238. ca[1] = _0 - (_i + bvirt) + (bvirt - t1);
  239. u3 = _j + _i;
  240. bvirt = u3 - _j;
  241. ca[2] = _j - (u3 - bvirt) + (_i - bvirt);
  242. ca[3] = u3;
  243. s1 = adx * bdy;
  244. c = splitter * adx;
  245. ahi = c - (c - adx);
  246. alo = adx - ahi;
  247. c = splitter * bdy;
  248. bhi = c - (c - bdy);
  249. blo = bdy - bhi;
  250. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  251. t1 = bdx * ady;
  252. c = splitter * bdx;
  253. ahi = c - (c - bdx);
  254. alo = bdx - ahi;
  255. c = splitter * ady;
  256. bhi = c - (c - ady);
  257. blo = ady - bhi;
  258. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  259. _i = s0 - t0;
  260. bvirt = s0 - _i;
  261. ab[0] = s0 - (_i + bvirt) + (bvirt - t0);
  262. _j = s1 + _i;
  263. bvirt = _j - s1;
  264. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  265. _i = _0 - t1;
  266. bvirt = _0 - _i;
  267. ab[1] = _0 - (_i + bvirt) + (bvirt - t1);
  268. u3 = _j + _i;
  269. bvirt = u3 - _j;
  270. ab[2] = _j - (u3 - bvirt) + (_i - bvirt);
  271. ab[3] = u3;
  272. finlen = sum(
  273. sum(
  274. sum(
  275. scale(scale(4, bc, adx, _8), _8, adx, _16), _16,
  276. scale(scale(4, bc, ady, _8), _8, ady, _16b), _16b, _32), _32,
  277. sum(
  278. scale(scale(4, ca, bdx, _8), _8, bdx, _16), _16,
  279. scale(scale(4, ca, bdy, _8), _8, bdy, _16b), _16b, _32b), _32b, _64), _64,
  280. sum(
  281. scale(scale(4, ab, cdx, _8), _8, cdx, _16), _16,
  282. scale(scale(4, ab, cdy, _8), _8, cdy, _16b), _16b, _32), _32, fin);
  283. let det = estimate(finlen, fin);
  284. let errbound = iccerrboundB * permanent;
  285. if (det >= errbound || -det >= errbound) {
  286. return det;
  287. }
  288. bvirt = ax - adx;
  289. adxtail = ax - (adx + bvirt) + (bvirt - dx);
  290. bvirt = ay - ady;
  291. adytail = ay - (ady + bvirt) + (bvirt - dy);
  292. bvirt = bx - bdx;
  293. bdxtail = bx - (bdx + bvirt) + (bvirt - dx);
  294. bvirt = by - bdy;
  295. bdytail = by - (bdy + bvirt) + (bvirt - dy);
  296. bvirt = cx - cdx;
  297. cdxtail = cx - (cdx + bvirt) + (bvirt - dx);
  298. bvirt = cy - cdy;
  299. cdytail = cy - (cdy + bvirt) + (bvirt - dy);
  300. if (adxtail === 0 && bdxtail === 0 && cdxtail === 0 && adytail === 0 && bdytail === 0 && cdytail === 0) {
  301. return det;
  302. }
  303. errbound = iccerrboundC * permanent + resulterrbound * Math.abs(det);
  304. det += ((adx * adx + ady * ady) * ((bdx * cdytail + cdy * bdxtail) - (bdy * cdxtail + cdx * bdytail)) +
  305. 2 * (adx * adxtail + ady * adytail) * (bdx * cdy - bdy * cdx)) +
  306. ((bdx * bdx + bdy * bdy) * ((cdx * adytail + ady * cdxtail) - (cdy * adxtail + adx * cdytail)) +
  307. 2 * (bdx * bdxtail + bdy * bdytail) * (cdx * ady - cdy * adx)) +
  308. ((cdx * cdx + cdy * cdy) * ((adx * bdytail + bdy * adxtail) - (ady * bdxtail + bdx * adytail)) +
  309. 2 * (cdx * cdxtail + cdy * cdytail) * (adx * bdy - ady * bdx));
  310. if (det >= errbound || -det >= errbound) {
  311. return det;
  312. }
  313. if (bdxtail !== 0 || bdytail !== 0 || cdxtail !== 0 || cdytail !== 0) {
  314. s1 = adx * adx;
  315. c = splitter * adx;
  316. ahi = c - (c - adx);
  317. alo = adx - ahi;
  318. s0 = alo * alo - (s1 - ahi * ahi - (ahi + ahi) * alo);
  319. t1 = ady * ady;
  320. c = splitter * ady;
  321. ahi = c - (c - ady);
  322. alo = ady - ahi;
  323. t0 = alo * alo - (t1 - ahi * ahi - (ahi + ahi) * alo);
  324. _i = s0 + t0;
  325. bvirt = _i - s0;
  326. aa[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  327. _j = s1 + _i;
  328. bvirt = _j - s1;
  329. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  330. _i = _0 + t1;
  331. bvirt = _i - _0;
  332. aa[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  333. u3 = _j + _i;
  334. bvirt = u3 - _j;
  335. aa[2] = _j - (u3 - bvirt) + (_i - bvirt);
  336. aa[3] = u3;
  337. }
  338. if (cdxtail !== 0 || cdytail !== 0 || adxtail !== 0 || adytail !== 0) {
  339. s1 = bdx * bdx;
  340. c = splitter * bdx;
  341. ahi = c - (c - bdx);
  342. alo = bdx - ahi;
  343. s0 = alo * alo - (s1 - ahi * ahi - (ahi + ahi) * alo);
  344. t1 = bdy * bdy;
  345. c = splitter * bdy;
  346. ahi = c - (c - bdy);
  347. alo = bdy - ahi;
  348. t0 = alo * alo - (t1 - ahi * ahi - (ahi + ahi) * alo);
  349. _i = s0 + t0;
  350. bvirt = _i - s0;
  351. bb[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  352. _j = s1 + _i;
  353. bvirt = _j - s1;
  354. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  355. _i = _0 + t1;
  356. bvirt = _i - _0;
  357. bb[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  358. u3 = _j + _i;
  359. bvirt = u3 - _j;
  360. bb[2] = _j - (u3 - bvirt) + (_i - bvirt);
  361. bb[3] = u3;
  362. }
  363. if (adxtail !== 0 || adytail !== 0 || bdxtail !== 0 || bdytail !== 0) {
  364. s1 = cdx * cdx;
  365. c = splitter * cdx;
  366. ahi = c - (c - cdx);
  367. alo = cdx - ahi;
  368. s0 = alo * alo - (s1 - ahi * ahi - (ahi + ahi) * alo);
  369. t1 = cdy * cdy;
  370. c = splitter * cdy;
  371. ahi = c - (c - cdy);
  372. alo = cdy - ahi;
  373. t0 = alo * alo - (t1 - ahi * ahi - (ahi + ahi) * alo);
  374. _i = s0 + t0;
  375. bvirt = _i - s0;
  376. cc[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  377. _j = s1 + _i;
  378. bvirt = _j - s1;
  379. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  380. _i = _0 + t1;
  381. bvirt = _i - _0;
  382. cc[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  383. u3 = _j + _i;
  384. bvirt = u3 - _j;
  385. cc[2] = _j - (u3 - bvirt) + (_i - bvirt);
  386. cc[3] = u3;
  387. }
  388. if (adxtail !== 0) {
  389. axtbclen = scale(4, bc, adxtail, axtbc);
  390. finlen = finadd(finlen, sum_three(
  391. scale(axtbclen, axtbc, 2 * adx, _16), _16,
  392. scale(scale(4, cc, adxtail, _8), _8, bdy, _16b), _16b,
  393. scale(scale(4, bb, adxtail, _8), _8, -cdy, _16c), _16c, _32, _48), _48);
  394. }
  395. if (adytail !== 0) {
  396. aytbclen = scale(4, bc, adytail, aytbc);
  397. finlen = finadd(finlen, sum_three(
  398. scale(aytbclen, aytbc, 2 * ady, _16), _16,
  399. scale(scale(4, bb, adytail, _8), _8, cdx, _16b), _16b,
  400. scale(scale(4, cc, adytail, _8), _8, -bdx, _16c), _16c, _32, _48), _48);
  401. }
  402. if (bdxtail !== 0) {
  403. bxtcalen = scale(4, ca, bdxtail, bxtca);
  404. finlen = finadd(finlen, sum_three(
  405. scale(bxtcalen, bxtca, 2 * bdx, _16), _16,
  406. scale(scale(4, aa, bdxtail, _8), _8, cdy, _16b), _16b,
  407. scale(scale(4, cc, bdxtail, _8), _8, -ady, _16c), _16c, _32, _48), _48);
  408. }
  409. if (bdytail !== 0) {
  410. bytcalen = scale(4, ca, bdytail, bytca);
  411. finlen = finadd(finlen, sum_three(
  412. scale(bytcalen, bytca, 2 * bdy, _16), _16,
  413. scale(scale(4, cc, bdytail, _8), _8, adx, _16b), _16b,
  414. scale(scale(4, aa, bdytail, _8), _8, -cdx, _16c), _16c, _32, _48), _48);
  415. }
  416. if (cdxtail !== 0) {
  417. cxtablen = scale(4, ab, cdxtail, cxtab);
  418. finlen = finadd(finlen, sum_three(
  419. scale(cxtablen, cxtab, 2 * cdx, _16), _16,
  420. scale(scale(4, bb, cdxtail, _8), _8, ady, _16b), _16b,
  421. scale(scale(4, aa, cdxtail, _8), _8, -bdy, _16c), _16c, _32, _48), _48);
  422. }
  423. if (cdytail !== 0) {
  424. cytablen = scale(4, ab, cdytail, cytab);
  425. finlen = finadd(finlen, sum_three(
  426. scale(cytablen, cytab, 2 * cdy, _16), _16,
  427. scale(scale(4, aa, cdytail, _8), _8, bdx, _16b), _16b,
  428. scale(scale(4, bb, cdytail, _8), _8, -adx, _16c), _16c, _32, _48), _48);
  429. }
  430. if (adxtail !== 0 || adytail !== 0) {
  431. if (bdxtail !== 0 || bdytail !== 0 || cdxtail !== 0 || cdytail !== 0) {
  432. s1 = bdxtail * cdy;
  433. c = splitter * bdxtail;
  434. ahi = c - (c - bdxtail);
  435. alo = bdxtail - ahi;
  436. c = splitter * cdy;
  437. bhi = c - (c - cdy);
  438. blo = cdy - bhi;
  439. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  440. t1 = bdx * cdytail;
  441. c = splitter * bdx;
  442. ahi = c - (c - bdx);
  443. alo = bdx - ahi;
  444. c = splitter * cdytail;
  445. bhi = c - (c - cdytail);
  446. blo = cdytail - bhi;
  447. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  448. _i = s0 + t0;
  449. bvirt = _i - s0;
  450. u[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  451. _j = s1 + _i;
  452. bvirt = _j - s1;
  453. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  454. _i = _0 + t1;
  455. bvirt = _i - _0;
  456. u[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  457. u3 = _j + _i;
  458. bvirt = u3 - _j;
  459. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  460. u[3] = u3;
  461. s1 = cdxtail * -bdy;
  462. c = splitter * cdxtail;
  463. ahi = c - (c - cdxtail);
  464. alo = cdxtail - ahi;
  465. c = splitter * -bdy;
  466. bhi = c - (c - -bdy);
  467. blo = -bdy - bhi;
  468. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  469. t1 = cdx * -bdytail;
  470. c = splitter * cdx;
  471. ahi = c - (c - cdx);
  472. alo = cdx - ahi;
  473. c = splitter * -bdytail;
  474. bhi = c - (c - -bdytail);
  475. blo = -bdytail - bhi;
  476. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  477. _i = s0 + t0;
  478. bvirt = _i - s0;
  479. v[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  480. _j = s1 + _i;
  481. bvirt = _j - s1;
  482. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  483. _i = _0 + t1;
  484. bvirt = _i - _0;
  485. v[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  486. u3 = _j + _i;
  487. bvirt = u3 - _j;
  488. v[2] = _j - (u3 - bvirt) + (_i - bvirt);
  489. v[3] = u3;
  490. bctlen = sum(4, u, 4, v, bct);
  491. s1 = bdxtail * cdytail;
  492. c = splitter * bdxtail;
  493. ahi = c - (c - bdxtail);
  494. alo = bdxtail - ahi;
  495. c = splitter * cdytail;
  496. bhi = c - (c - cdytail);
  497. blo = cdytail - bhi;
  498. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  499. t1 = cdxtail * bdytail;
  500. c = splitter * cdxtail;
  501. ahi = c - (c - cdxtail);
  502. alo = cdxtail - ahi;
  503. c = splitter * bdytail;
  504. bhi = c - (c - bdytail);
  505. blo = bdytail - bhi;
  506. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  507. _i = s0 - t0;
  508. bvirt = s0 - _i;
  509. bctt[0] = s0 - (_i + bvirt) + (bvirt - t0);
  510. _j = s1 + _i;
  511. bvirt = _j - s1;
  512. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  513. _i = _0 - t1;
  514. bvirt = _0 - _i;
  515. bctt[1] = _0 - (_i + bvirt) + (bvirt - t1);
  516. u3 = _j + _i;
  517. bvirt = u3 - _j;
  518. bctt[2] = _j - (u3 - bvirt) + (_i - bvirt);
  519. bctt[3] = u3;
  520. bcttlen = 4;
  521. } else {
  522. bct[0] = 0;
  523. bctlen = 1;
  524. bctt[0] = 0;
  525. bcttlen = 1;
  526. }
  527. if (adxtail !== 0) {
  528. const len = scale(bctlen, bct, adxtail, _16c);
  529. finlen = finadd(finlen, sum(
  530. scale(axtbclen, axtbc, adxtail, _16), _16,
  531. scale(len, _16c, 2 * adx, _32), _32, _48), _48);
  532. const len2 = scale(bcttlen, bctt, adxtail, _8);
  533. finlen = finadd(finlen, sum_three(
  534. scale(len2, _8, 2 * adx, _16), _16,
  535. scale(len2, _8, adxtail, _16b), _16b,
  536. scale(len, _16c, adxtail, _32), _32, _32b, _64), _64);
  537. if (bdytail !== 0) {
  538. finlen = finadd(finlen, scale(scale(4, cc, adxtail, _8), _8, bdytail, _16), _16);
  539. }
  540. if (cdytail !== 0) {
  541. finlen = finadd(finlen, scale(scale(4, bb, -adxtail, _8), _8, cdytail, _16), _16);
  542. }
  543. }
  544. if (adytail !== 0) {
  545. const len = scale(bctlen, bct, adytail, _16c);
  546. finlen = finadd(finlen, sum(
  547. scale(aytbclen, aytbc, adytail, _16), _16,
  548. scale(len, _16c, 2 * ady, _32), _32, _48), _48);
  549. const len2 = scale(bcttlen, bctt, adytail, _8);
  550. finlen = finadd(finlen, sum_three(
  551. scale(len2, _8, 2 * ady, _16), _16,
  552. scale(len2, _8, adytail, _16b), _16b,
  553. scale(len, _16c, adytail, _32), _32, _32b, _64), _64);
  554. }
  555. }
  556. if (bdxtail !== 0 || bdytail !== 0) {
  557. if (cdxtail !== 0 || cdytail !== 0 || adxtail !== 0 || adytail !== 0) {
  558. s1 = cdxtail * ady;
  559. c = splitter * cdxtail;
  560. ahi = c - (c - cdxtail);
  561. alo = cdxtail - ahi;
  562. c = splitter * ady;
  563. bhi = c - (c - ady);
  564. blo = ady - bhi;
  565. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  566. t1 = cdx * adytail;
  567. c = splitter * cdx;
  568. ahi = c - (c - cdx);
  569. alo = cdx - ahi;
  570. c = splitter * adytail;
  571. bhi = c - (c - adytail);
  572. blo = adytail - bhi;
  573. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  574. _i = s0 + t0;
  575. bvirt = _i - s0;
  576. u[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  577. _j = s1 + _i;
  578. bvirt = _j - s1;
  579. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  580. _i = _0 + t1;
  581. bvirt = _i - _0;
  582. u[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  583. u3 = _j + _i;
  584. bvirt = u3 - _j;
  585. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  586. u[3] = u3;
  587. n1 = -cdy;
  588. n0 = -cdytail;
  589. s1 = adxtail * n1;
  590. c = splitter * adxtail;
  591. ahi = c - (c - adxtail);
  592. alo = adxtail - ahi;
  593. c = splitter * n1;
  594. bhi = c - (c - n1);
  595. blo = n1 - bhi;
  596. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  597. t1 = adx * n0;
  598. c = splitter * adx;
  599. ahi = c - (c - adx);
  600. alo = adx - ahi;
  601. c = splitter * n0;
  602. bhi = c - (c - n0);
  603. blo = n0 - bhi;
  604. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  605. _i = s0 + t0;
  606. bvirt = _i - s0;
  607. v[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  608. _j = s1 + _i;
  609. bvirt = _j - s1;
  610. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  611. _i = _0 + t1;
  612. bvirt = _i - _0;
  613. v[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  614. u3 = _j + _i;
  615. bvirt = u3 - _j;
  616. v[2] = _j - (u3 - bvirt) + (_i - bvirt);
  617. v[3] = u3;
  618. catlen = sum(4, u, 4, v, cat);
  619. s1 = cdxtail * adytail;
  620. c = splitter * cdxtail;
  621. ahi = c - (c - cdxtail);
  622. alo = cdxtail - ahi;
  623. c = splitter * adytail;
  624. bhi = c - (c - adytail);
  625. blo = adytail - bhi;
  626. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  627. t1 = adxtail * cdytail;
  628. c = splitter * adxtail;
  629. ahi = c - (c - adxtail);
  630. alo = adxtail - ahi;
  631. c = splitter * cdytail;
  632. bhi = c - (c - cdytail);
  633. blo = cdytail - bhi;
  634. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  635. _i = s0 - t0;
  636. bvirt = s0 - _i;
  637. catt[0] = s0 - (_i + bvirt) + (bvirt - t0);
  638. _j = s1 + _i;
  639. bvirt = _j - s1;
  640. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  641. _i = _0 - t1;
  642. bvirt = _0 - _i;
  643. catt[1] = _0 - (_i + bvirt) + (bvirt - t1);
  644. u3 = _j + _i;
  645. bvirt = u3 - _j;
  646. catt[2] = _j - (u3 - bvirt) + (_i - bvirt);
  647. catt[3] = u3;
  648. cattlen = 4;
  649. } else {
  650. cat[0] = 0;
  651. catlen = 1;
  652. catt[0] = 0;
  653. cattlen = 1;
  654. }
  655. if (bdxtail !== 0) {
  656. const len = scale(catlen, cat, bdxtail, _16c);
  657. finlen = finadd(finlen, sum(
  658. scale(bxtcalen, bxtca, bdxtail, _16), _16,
  659. scale(len, _16c, 2 * bdx, _32), _32, _48), _48);
  660. const len2 = scale(cattlen, catt, bdxtail, _8);
  661. finlen = finadd(finlen, sum_three(
  662. scale(len2, _8, 2 * bdx, _16), _16,
  663. scale(len2, _8, bdxtail, _16b), _16b,
  664. scale(len, _16c, bdxtail, _32), _32, _32b, _64), _64);
  665. if (cdytail !== 0) {
  666. finlen = finadd(finlen, scale(scale(4, aa, bdxtail, _8), _8, cdytail, _16), _16);
  667. }
  668. if (adytail !== 0) {
  669. finlen = finadd(finlen, scale(scale(4, cc, -bdxtail, _8), _8, adytail, _16), _16);
  670. }
  671. }
  672. if (bdytail !== 0) {
  673. const len = scale(catlen, cat, bdytail, _16c);
  674. finlen = finadd(finlen, sum(
  675. scale(bytcalen, bytca, bdytail, _16), _16,
  676. scale(len, _16c, 2 * bdy, _32), _32, _48), _48);
  677. const len2 = scale(cattlen, catt, bdytail, _8);
  678. finlen = finadd(finlen, sum_three(
  679. scale(len2, _8, 2 * bdy, _16), _16,
  680. scale(len2, _8, bdytail, _16b), _16b,
  681. scale(len, _16c, bdytail, _32), _32, _32b, _64), _64);
  682. }
  683. }
  684. if (cdxtail !== 0 || cdytail !== 0) {
  685. if (adxtail !== 0 || adytail !== 0 || bdxtail !== 0 || bdytail !== 0) {
  686. s1 = adxtail * bdy;
  687. c = splitter * adxtail;
  688. ahi = c - (c - adxtail);
  689. alo = adxtail - ahi;
  690. c = splitter * bdy;
  691. bhi = c - (c - bdy);
  692. blo = bdy - bhi;
  693. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  694. t1 = adx * bdytail;
  695. c = splitter * adx;
  696. ahi = c - (c - adx);
  697. alo = adx - ahi;
  698. c = splitter * bdytail;
  699. bhi = c - (c - bdytail);
  700. blo = bdytail - bhi;
  701. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  702. _i = s0 + t0;
  703. bvirt = _i - s0;
  704. u[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  705. _j = s1 + _i;
  706. bvirt = _j - s1;
  707. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  708. _i = _0 + t1;
  709. bvirt = _i - _0;
  710. u[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  711. u3 = _j + _i;
  712. bvirt = u3 - _j;
  713. u[2] = _j - (u3 - bvirt) + (_i - bvirt);
  714. u[3] = u3;
  715. n1 = -ady;
  716. n0 = -adytail;
  717. s1 = bdxtail * n1;
  718. c = splitter * bdxtail;
  719. ahi = c - (c - bdxtail);
  720. alo = bdxtail - ahi;
  721. c = splitter * n1;
  722. bhi = c - (c - n1);
  723. blo = n1 - bhi;
  724. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  725. t1 = bdx * n0;
  726. c = splitter * bdx;
  727. ahi = c - (c - bdx);
  728. alo = bdx - ahi;
  729. c = splitter * n0;
  730. bhi = c - (c - n0);
  731. blo = n0 - bhi;
  732. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  733. _i = s0 + t0;
  734. bvirt = _i - s0;
  735. v[0] = s0 - (_i - bvirt) + (t0 - bvirt);
  736. _j = s1 + _i;
  737. bvirt = _j - s1;
  738. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  739. _i = _0 + t1;
  740. bvirt = _i - _0;
  741. v[1] = _0 - (_i - bvirt) + (t1 - bvirt);
  742. u3 = _j + _i;
  743. bvirt = u3 - _j;
  744. v[2] = _j - (u3 - bvirt) + (_i - bvirt);
  745. v[3] = u3;
  746. abtlen = sum(4, u, 4, v, abt);
  747. s1 = adxtail * bdytail;
  748. c = splitter * adxtail;
  749. ahi = c - (c - adxtail);
  750. alo = adxtail - ahi;
  751. c = splitter * bdytail;
  752. bhi = c - (c - bdytail);
  753. blo = bdytail - bhi;
  754. s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
  755. t1 = bdxtail * adytail;
  756. c = splitter * bdxtail;
  757. ahi = c - (c - bdxtail);
  758. alo = bdxtail - ahi;
  759. c = splitter * adytail;
  760. bhi = c - (c - adytail);
  761. blo = adytail - bhi;
  762. t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
  763. _i = s0 - t0;
  764. bvirt = s0 - _i;
  765. abtt[0] = s0 - (_i + bvirt) + (bvirt - t0);
  766. _j = s1 + _i;
  767. bvirt = _j - s1;
  768. _0 = s1 - (_j - bvirt) + (_i - bvirt);
  769. _i = _0 - t1;
  770. bvirt = _0 - _i;
  771. abtt[1] = _0 - (_i + bvirt) + (bvirt - t1);
  772. u3 = _j + _i;
  773. bvirt = u3 - _j;
  774. abtt[2] = _j - (u3 - bvirt) + (_i - bvirt);
  775. abtt[3] = u3;
  776. abttlen = 4;
  777. } else {
  778. abt[0] = 0;
  779. abtlen = 1;
  780. abtt[0] = 0;
  781. abttlen = 1;
  782. }
  783. if (cdxtail !== 0) {
  784. const len = scale(abtlen, abt, cdxtail, _16c);
  785. finlen = finadd(finlen, sum(
  786. scale(cxtablen, cxtab, cdxtail, _16), _16,
  787. scale(len, _16c, 2 * cdx, _32), _32, _48), _48);
  788. const len2 = scale(abttlen, abtt, cdxtail, _8);
  789. finlen = finadd(finlen, sum_three(
  790. scale(len2, _8, 2 * cdx, _16), _16,
  791. scale(len2, _8, cdxtail, _16b), _16b,
  792. scale(len, _16c, cdxtail, _32), _32, _32b, _64), _64);
  793. if (adytail !== 0) {
  794. finlen = finadd(finlen, scale(scale(4, bb, cdxtail, _8), _8, adytail, _16), _16);
  795. }
  796. if (bdytail !== 0) {
  797. finlen = finadd(finlen, scale(scale(4, aa, -cdxtail, _8), _8, bdytail, _16), _16);
  798. }
  799. }
  800. if (cdytail !== 0) {
  801. const len = scale(abtlen, abt, cdytail, _16c);
  802. finlen = finadd(finlen, sum(
  803. scale(cytablen, cytab, cdytail, _16), _16,
  804. scale(len, _16c, 2 * cdy, _32), _32, _48), _48);
  805. const len2 = scale(abttlen, abtt, cdytail, _8);
  806. finlen = finadd(finlen, sum_three(
  807. scale(len2, _8, 2 * cdy, _16), _16,
  808. scale(len2, _8, cdytail, _16b), _16b,
  809. scale(len, _16c, cdytail, _32), _32, _32b, _64), _64);
  810. }
  811. }
  812. return fin[finlen - 1];
  813. }
  814. function incircle(ax, ay, bx, by, cx, cy, dx, dy) {
  815. const adx = ax - dx;
  816. const bdx = bx - dx;
  817. const cdx = cx - dx;
  818. const ady = ay - dy;
  819. const bdy = by - dy;
  820. const cdy = cy - dy;
  821. const bdxcdy = bdx * cdy;
  822. const cdxbdy = cdx * bdy;
  823. const alift = adx * adx + ady * ady;
  824. const cdxady = cdx * ady;
  825. const adxcdy = adx * cdy;
  826. const blift = bdx * bdx + bdy * bdy;
  827. const adxbdy = adx * bdy;
  828. const bdxady = bdx * ady;
  829. const clift = cdx * cdx + cdy * cdy;
  830. const det =
  831. alift * (bdxcdy - cdxbdy) +
  832. blift * (cdxady - adxcdy) +
  833. clift * (adxbdy - bdxady);
  834. const permanent =
  835. (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * alift +
  836. (Math.abs(cdxady) + Math.abs(adxcdy)) * blift +
  837. (Math.abs(adxbdy) + Math.abs(bdxady)) * clift;
  838. const errbound = iccerrboundA * permanent;
  839. if (det > errbound || -det > errbound) {
  840. return det;
  841. }
  842. return incircleadapt(ax, ay, bx, by, cx, cy, dx, dy, permanent);
  843. }
  844. function incirclefast(ax, ay, bx, by, cx, cy, dx, dy) {
  845. const adx = ax - dx;
  846. const ady = ay - dy;
  847. const bdx = bx - dx;
  848. const bdy = by - dy;
  849. const cdx = cx - dx;
  850. const cdy = cy - dy;
  851. const abdet = adx * bdy - bdx * ady;
  852. const bcdet = bdx * cdy - cdx * bdy;
  853. const cadet = cdx * ady - adx * cdy;
  854. const alift = adx * adx + ady * ady;
  855. const blift = bdx * bdx + bdy * bdy;
  856. const clift = cdx * cdx + cdy * cdy;
  857. return alift * bcdet + blift * cadet + clift * abdet;
  858. }
  859. exports.incircle = incircle;
  860. exports.incirclefast = incirclefast;
  861. }));