Node-Red configuration
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

incircle.js 26KB

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