@hpcc-js/tree 2.25.0 → 2.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -5,8 +5,8 @@
5
5
  }(this, (function (exports, api, common) { 'use strict';
6
6
 
7
7
  var PKG_NAME = "@hpcc-js/tree";
8
- var PKG_VERSION = "2.25.0";
9
- var BUILD_VERSION = "2.76.0";
8
+ var PKG_VERSION = "2.31.0";
9
+ var BUILD_VERSION = "2.88.0";
10
10
 
11
11
  /*! *****************************************************************************
12
12
  Copyright (c) Microsoft Corporation.
@@ -329,83 +329,92 @@
329
329
  copy: node_copy
330
330
  };
331
331
 
332
- function Node$1(value) {
333
- this._ = value;
334
- this.next = null;
335
- }
332
+ var slice = Array.prototype.slice;
336
333
 
337
334
  function shuffle(array) {
338
- var i,
339
- n = (array = array.slice()).length,
340
- head = null,
341
- node = head;
342
-
343
- while (n) {
344
- var next = new Node$1(array[n - 1]);
345
- if (node) node = node.next = next;
346
- else node = head = next;
347
- array[i] = array[--n];
335
+ var m = array.length,
336
+ t,
337
+ i;
338
+
339
+ while (m) {
340
+ i = Math.random() * m-- | 0;
341
+ t = array[m];
342
+ array[m] = array[i];
343
+ array[i] = t;
348
344
  }
349
345
 
350
- return {
351
- head: head,
352
- tail: node
353
- };
346
+ return array;
354
347
  }
355
348
 
356
349
  function enclose(circles) {
357
- return encloseN(shuffle(circles), []);
358
- }
350
+ var i = 0, n = (circles = shuffle(slice.call(circles))).length, B = [], p, e;
351
+
352
+ while (i < n) {
353
+ p = circles[i];
354
+ if (e && enclosesWeak(e, p)) ++i;
355
+ else e = encloseBasis(B = extendBasis(B, p)), i = 0;
356
+ }
359
357
 
360
- function encloses(a, b) {
361
- var dx = b.x - a.x,
362
- dy = b.y - a.y,
363
- dr = a.r - b.r;
364
- return dr * dr + 1e-6 > dx * dx + dy * dy;
358
+ return e;
365
359
  }
366
360
 
367
- // Returns the smallest circle that contains circles L and intersects circles B.
368
- function encloseN(L, B) {
369
- var circle,
370
- l0 = null,
371
- l1 = L.head,
372
- l2,
373
- p1;
361
+ function extendBasis(B, p) {
362
+ var i, j;
374
363
 
375
- switch (B.length) {
376
- case 1: circle = enclose1(B[0]); break;
377
- case 2: circle = enclose2(B[0], B[1]); break;
378
- case 3: circle = enclose3(B[0], B[1], B[2]); break;
364
+ if (enclosesWeakAll(p, B)) return [p];
365
+
366
+ // If we get here then B must have at least one element.
367
+ for (i = 0; i < B.length; ++i) {
368
+ if (enclosesNot(p, B[i])
369
+ && enclosesWeakAll(encloseBasis2(B[i], p), B)) {
370
+ return [B[i], p];
371
+ }
379
372
  }
380
373
 
381
- while (l1) {
382
- p1 = l1._, l2 = l1.next;
383
- if (!circle || !encloses(circle, p1)) {
374
+ // If we get here then B must have at least two elements.
375
+ for (i = 0; i < B.length - 1; ++i) {
376
+ for (j = i + 1; j < B.length; ++j) {
377
+ if (enclosesNot(encloseBasis2(B[i], B[j]), p)
378
+ && enclosesNot(encloseBasis2(B[i], p), B[j])
379
+ && enclosesNot(encloseBasis2(B[j], p), B[i])
380
+ && enclosesWeakAll(encloseBasis3(B[i], B[j], p), B)) {
381
+ return [B[i], B[j], p];
382
+ }
383
+ }
384
+ }
384
385
 
385
- // Temporarily truncate L before l1.
386
- if (l0) L.tail = l0, l0.next = null;
387
- else L.head = L.tail = null;
386
+ // If we get here then something is very wrong.
387
+ throw new Error;
388
+ }
388
389
 
389
- B.push(p1);
390
- circle = encloseN(L, B); // Note: reorders L!
391
- B.pop();
390
+ function enclosesNot(a, b) {
391
+ var dr = a.r - b.r, dx = b.x - a.x, dy = b.y - a.y;
392
+ return dr < 0 || dr * dr < dx * dx + dy * dy;
393
+ }
392
394
 
393
- // Move l1 to the front of L and reconnect the truncated list L.
394
- if (L.head) l1.next = L.head, L.head = l1;
395
- else l1.next = null, L.head = L.tail = l1;
396
- l0 = L.tail, l0.next = l2;
395
+ function enclosesWeak(a, b) {
396
+ var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
397
+ return dr > 0 && dr * dr > dx * dx + dy * dy;
398
+ }
397
399
 
398
- } else {
399
- l0 = l1;
400
+ function enclosesWeakAll(a, B) {
401
+ for (var i = 0; i < B.length; ++i) {
402
+ if (!enclosesWeak(a, B[i])) {
403
+ return false;
400
404
  }
401
- l1 = l2;
402
405
  }
406
+ return true;
407
+ }
403
408
 
404
- L.tail = l0;
405
- return circle;
409
+ function encloseBasis(B) {
410
+ switch (B.length) {
411
+ case 1: return encloseBasis1(B[0]);
412
+ case 2: return encloseBasis2(B[0], B[1]);
413
+ case 3: return encloseBasis3(B[0], B[1], B[2]);
414
+ }
406
415
  }
407
416
 
408
- function enclose1(a) {
417
+ function encloseBasis1(a) {
409
418
  return {
410
419
  x: a.x,
411
420
  y: a.y,
@@ -413,7 +422,7 @@
413
422
  };
414
423
  }
415
424
 
416
- function enclose2(a, b) {
425
+ function encloseBasis2(a, b) {
417
426
  var x1 = a.x, y1 = a.y, r1 = a.r,
418
427
  x2 = b.x, y2 = b.y, r2 = b.r,
419
428
  x21 = x2 - x1, y21 = y2 - y1, r21 = r2 - r1,
@@ -425,70 +434,74 @@
425
434
  };
426
435
  }
427
436
 
428
- function enclose3(a, b, c) {
437
+ function encloseBasis3(a, b, c) {
429
438
  var x1 = a.x, y1 = a.y, r1 = a.r,
430
439
  x2 = b.x, y2 = b.y, r2 = b.r,
431
440
  x3 = c.x, y3 = c.y, r3 = c.r,
432
- a2 = 2 * (x1 - x2),
433
- b2 = 2 * (y1 - y2),
434
- c2 = 2 * (r2 - r1),
435
- d2 = x1 * x1 + y1 * y1 - r1 * r1 - x2 * x2 - y2 * y2 + r2 * r2,
436
- a3 = 2 * (x1 - x3),
437
- b3 = 2 * (y1 - y3),
438
- c3 = 2 * (r3 - r1),
439
- d3 = x1 * x1 + y1 * y1 - r1 * r1 - x3 * x3 - y3 * y3 + r3 * r3,
441
+ a2 = x1 - x2,
442
+ a3 = x1 - x3,
443
+ b2 = y1 - y2,
444
+ b3 = y1 - y3,
445
+ c2 = r2 - r1,
446
+ c3 = r3 - r1,
447
+ d1 = x1 * x1 + y1 * y1 - r1 * r1,
448
+ d2 = d1 - x2 * x2 - y2 * y2 + r2 * r2,
449
+ d3 = d1 - x3 * x3 - y3 * y3 + r3 * r3,
440
450
  ab = a3 * b2 - a2 * b3,
441
- xa = (b2 * d3 - b3 * d2) / ab - x1,
451
+ xa = (b2 * d3 - b3 * d2) / (ab * 2) - x1,
442
452
  xb = (b3 * c2 - b2 * c3) / ab,
443
- ya = (a3 * d2 - a2 * d3) / ab - y1,
453
+ ya = (a3 * d2 - a2 * d3) / (ab * 2) - y1,
444
454
  yb = (a2 * c3 - a3 * c2) / ab,
445
455
  A = xb * xb + yb * yb - 1,
446
- B = 2 * (xa * xb + ya * yb + r1),
456
+ B = 2 * (r1 + xa * xb + ya * yb),
447
457
  C = xa * xa + ya * ya - r1 * r1,
448
- r = (-B - Math.sqrt(B * B - 4 * A * C)) / (2 * A);
458
+ r = -(A ? (B + Math.sqrt(B * B - 4 * A * C)) / (2 * A) : C / B);
449
459
  return {
450
- x: xa + xb * r + x1,
451
- y: ya + yb * r + y1,
460
+ x: x1 + xa + xb * r,
461
+ y: y1 + ya + yb * r,
452
462
  r: r
453
463
  };
454
464
  }
455
465
 
456
- function place(a, b, c) {
457
- var ax = a.x,
458
- ay = a.y,
459
- da = b.r + c.r,
460
- db = a.r + c.r,
461
- dx = b.x - ax,
462
- dy = b.y - ay,
463
- dc = dx * dx + dy * dy;
464
- if (dc) {
465
- var x = 0.5 + ((db *= db) - (da *= da)) / (2 * dc),
466
- y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
467
- c.x = ax + x * dx + y * dy;
468
- c.y = ay + x * dy - y * dx;
466
+ function place(b, a, c) {
467
+ var dx = b.x - a.x, x, a2,
468
+ dy = b.y - a.y, y, b2,
469
+ d2 = dx * dx + dy * dy;
470
+ if (d2) {
471
+ a2 = a.r + c.r, a2 *= a2;
472
+ b2 = b.r + c.r, b2 *= b2;
473
+ if (a2 > b2) {
474
+ x = (d2 + b2 - a2) / (2 * d2);
475
+ y = Math.sqrt(Math.max(0, b2 / d2 - x * x));
476
+ c.x = b.x - x * dx - y * dy;
477
+ c.y = b.y - x * dy + y * dx;
478
+ } else {
479
+ x = (d2 + a2 - b2) / (2 * d2);
480
+ y = Math.sqrt(Math.max(0, a2 / d2 - x * x));
481
+ c.x = a.x + x * dx - y * dy;
482
+ c.y = a.y + x * dy + y * dx;
483
+ }
469
484
  } else {
470
- c.x = ax + db;
471
- c.y = ay;
485
+ c.x = a.x + c.r;
486
+ c.y = a.y;
472
487
  }
473
488
  }
474
489
 
475
490
  function intersects(a, b) {
476
- var dx = b.x - a.x,
477
- dy = b.y - a.y,
478
- dr = a.r + b.r;
479
- return dr * dr - 1e-6 > dx * dx + dy * dy;
491
+ var dr = a.r + b.r - 1e-6, dx = b.x - a.x, dy = b.y - a.y;
492
+ return dr > 0 && dr * dr > dx * dx + dy * dy;
480
493
  }
481
494
 
482
- function distance2(node, x, y) {
495
+ function score(node) {
483
496
  var a = node._,
484
497
  b = node.next._,
485
498
  ab = a.r + b.r,
486
- dx = (a.x * b.r + b.x * a.r) / ab - x,
487
- dy = (a.y * b.r + b.y * a.r) / ab - y;
499
+ dx = (a.x * b.r + b.x * a.r) / ab,
500
+ dy = (a.y * b.r + b.y * a.r) / ab;
488
501
  return dx * dx + dy * dy;
489
502
  }
490
503
 
491
- function Node$2(circle) {
504
+ function Node$1(circle) {
492
505
  this._ = circle;
493
506
  this.next = null;
494
507
  this.previous = null;
@@ -497,7 +510,7 @@
497
510
  function packEnclose(circles) {
498
511
  if (!(n = circles.length)) return 0;
499
512
 
500
- var a, b, c, n;
513
+ var a, b, c, n, aa, ca, i, j, k, sj, sk;
501
514
 
502
515
  // Place the first circle.
503
516
  a = circles[0], a.x = 0, a.y = 0;
@@ -510,24 +523,15 @@
510
523
  // Place the third circle.
511
524
  place(b, a, c = circles[2]);
512
525
 
513
- // Initialize the weighted centroid.
514
- var aa = a.r * a.r,
515
- ba = b.r * b.r,
516
- ca = c.r * c.r,
517
- oa = aa + ba + ca,
518
- ox = aa * a.x + ba * b.x + ca * c.x,
519
- oy = aa * a.y + ba * b.y + ca * c.y,
520
- cx, cy, i, j, k, sj, sk;
521
-
522
526
  // Initialize the front-chain using the first three circles a, b and c.
523
- a = new Node$2(a), b = new Node$2(b), c = new Node$2(c);
527
+ a = new Node$1(a), b = new Node$1(b), c = new Node$1(c);
524
528
  a.next = c.previous = b;
525
529
  b.next = a.previous = c;
526
530
  c.next = b.previous = a;
527
531
 
528
532
  // Attempt to place each remaining circle…
529
533
  pack: for (i = 3; i < n; ++i) {
530
- place(a._, b._, c = circles[i]), c = new Node$2(c);
534
+ place(a._, b._, c = circles[i]), c = new Node$1(c);
531
535
 
532
536
  // Find the closest intersecting circle on the front-chain, if any.
533
537
  // “Closeness” is determined by linear distance along the front-chain.
@@ -552,15 +556,10 @@
552
556
  // Success! Insert the new circle c between a and b.
553
557
  c.previous = a, c.next = b, a.next = b.previous = b = c;
554
558
 
555
- // Update the weighted centroid.
556
- oa += ca = c._.r * c._.r;
557
- ox += ca * c._.x;
558
- oy += ca * c._.y;
559
-
560
559
  // Compute the new closest circle pair to the centroid.
561
- aa = distance2(a, cx = ox / oa, cy = oy / oa);
560
+ aa = score(a);
562
561
  while ((c = c.next) !== b) {
563
- if ((ca = distance2(c, cx, cy)) < aa) {
562
+ if ((ca = score(c)) < aa) {
564
563
  a = c, aa = ca;
565
564
  }
566
565
  }
@@ -2120,7 +2119,7 @@
2120
2119
  }
2121
2120
  },
2122
2121
  arc: function(x, y, r, a0, a1, ccw) {
2123
- x = +x, y = +y, r = +r;
2122
+ x = +x, y = +y, r = +r, ccw = !!ccw;
2124
2123
  var dx = r * Math.cos(a0),
2125
2124
  dy = r * Math.sin(a0),
2126
2125
  x0 = x + dx,
@@ -2215,7 +2214,9 @@
2215
2214
  function intersect(x0, y0, x1, y1, x2, y2, x3, y3) {
2216
2215
  var x10 = x1 - x0, y10 = y1 - y0,
2217
2216
  x32 = x3 - x2, y32 = y3 - y2,
2218
- t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / (y32 * x10 - x32 * y10);
2217
+ t = y32 * x10 - x32 * y10;
2218
+ if (t * t < epsilon$1) return;
2219
+ t = (x32 * (y0 - y2) - y32 * (x0 - x2)) / t;
2219
2220
  return [x0 + t * x10, y0 + t * y10];
2220
2221
  }
2221
2222
 
@@ -2336,12 +2337,12 @@
2336
2337
  var x11 = r1 * cos(a11),
2337
2338
  y11 = r1 * sin(a11),
2338
2339
  x00 = r0 * cos(a00),
2339
- y00 = r0 * sin(a00);
2340
+ y00 = r0 * sin(a00),
2341
+ oc;
2340
2342
 
2341
2343
  // Restrict the corner radius according to the sector angle.
2342
- if (da < pi$1) {
2343
- var oc = da0 > epsilon$1 ? intersect(x01, y01, x00, y00, x11, y11, x10, y10) : [x10, y10],
2344
- ax = x01 - oc[0],
2344
+ if (da < pi$1 && (oc = intersect(x01, y01, x00, y00, x11, y11, x10, y10))) {
2345
+ var ax = x01 - oc[0],
2345
2346
  ay = y01 - oc[1],
2346
2347
  bx = x11 - oc[0],
2347
2348
  by = y11 - oc[1],
@@ -2448,103 +2449,6 @@
2448
2449
  return arc;
2449
2450
  }
2450
2451
 
2451
- function sign(x) {
2452
- return x < 0 ? -1 : 1;
2453
- }
2454
-
2455
- // Calculate the slopes of the tangents (Hermite-type interpolation) based on
2456
- // the following paper: Steffen, M. 1990. A Simple Method for Monotonic
2457
- // Interpolation in One Dimension. Astronomy and Astrophysics, Vol. 239, NO.
2458
- // NOV(II), P. 443, 1990.
2459
- function slope3(that, x2, y2) {
2460
- var h0 = that._x1 - that._x0,
2461
- h1 = x2 - that._x1,
2462
- s0 = (that._y1 - that._y0) / (h0 || h1 < 0 && -0),
2463
- s1 = (y2 - that._y1) / (h1 || h0 < 0 && -0),
2464
- p = (s0 * h1 + s1 * h0) / (h0 + h1);
2465
- return (sign(s0) + sign(s1)) * Math.min(Math.abs(s0), Math.abs(s1), 0.5 * Math.abs(p)) || 0;
2466
- }
2467
-
2468
- // Calculate a one-sided slope.
2469
- function slope2(that, t) {
2470
- var h = that._x1 - that._x0;
2471
- return h ? (3 * (that._y1 - that._y0) / h - t) / 2 : t;
2472
- }
2473
-
2474
- // According to https://en.wikipedia.org/wiki/Cubic_Hermite_spline#Representations
2475
- // "you can express cubic Hermite interpolation in terms of cubic Bézier curves
2476
- // with respect to the four values p0, p0 + m0 / 3, p1 - m1 / 3, p1".
2477
- function point(that, t0, t1) {
2478
- var x0 = that._x0,
2479
- y0 = that._y0,
2480
- x1 = that._x1,
2481
- y1 = that._y1,
2482
- dx = (x1 - x0) / 3;
2483
- that._context.bezierCurveTo(x0 + dx, y0 + dx * t0, x1 - dx, y1 - dx * t1, x1, y1);
2484
- }
2485
-
2486
- function MonotoneX(context) {
2487
- this._context = context;
2488
- }
2489
-
2490
- MonotoneX.prototype = {
2491
- areaStart: function() {
2492
- this._line = 0;
2493
- },
2494
- areaEnd: function() {
2495
- this._line = NaN;
2496
- },
2497
- lineStart: function() {
2498
- this._x0 = this._x1 =
2499
- this._y0 = this._y1 =
2500
- this._t0 = NaN;
2501
- this._point = 0;
2502
- },
2503
- lineEnd: function() {
2504
- switch (this._point) {
2505
- case 2: this._context.lineTo(this._x1, this._y1); break;
2506
- case 3: point(this, this._t0, slope2(this, this._t0)); break;
2507
- }
2508
- if (this._line || (this._line !== 0 && this._point === 1)) this._context.closePath();
2509
- this._line = 1 - this._line;
2510
- },
2511
- point: function(x, y) {
2512
- var t1 = NaN;
2513
-
2514
- x = +x, y = +y;
2515
- if (x === this._x1 && y === this._y1) return; // Ignore coincident points.
2516
- switch (this._point) {
2517
- case 0: this._point = 1; this._line ? this._context.lineTo(x, y) : this._context.moveTo(x, y); break;
2518
- case 1: this._point = 2; break;
2519
- case 2: this._point = 3; point(this, slope2(this, t1 = slope3(this, x, y)), t1); break;
2520
- default: point(this, this._t0, t1 = slope3(this, x, y)); break;
2521
- }
2522
-
2523
- this._x0 = this._x1, this._x1 = x;
2524
- this._y0 = this._y1, this._y1 = y;
2525
- this._t0 = t1;
2526
- }
2527
- };
2528
-
2529
- function MonotoneY(context) {
2530
- this._context = new ReflectContext(context);
2531
- }
2532
-
2533
- (MonotoneY.prototype = Object.create(MonotoneX.prototype)).point = function(x, y) {
2534
- MonotoneX.prototype.point.call(this, y, x);
2535
- };
2536
-
2537
- function ReflectContext(context) {
2538
- this._context = context;
2539
- }
2540
-
2541
- ReflectContext.prototype = {
2542
- moveTo: function(x, y) { this._context.moveTo(y, x); },
2543
- closePath: function() { this._context.closePath(); },
2544
- lineTo: function(x, y) { this._context.lineTo(y, x); },
2545
- bezierCurveTo: function(x1, y1, x2, y2, x, y) { this._context.bezierCurveTo(y1, x1, y2, x2, y, x); }
2546
- };
2547
-
2548
2452
  var css_248z$3 = ".tree_Sunburst path{stroke:#fff;stroke-width:.5px;fill-rule:evenodd}";
2549
2453
  styleInject(css_248z$3);
2550
2454