@fieldnotes/core 0.50.2 → 0.50.3

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.cjs CHANGED
@@ -2320,6 +2320,9 @@ var MAX_DEPTH = 8;
2320
2320
  function intersects(a, b) {
2321
2321
  return a.x <= b.x + b.w && a.x + a.w >= b.x && a.y <= b.y + b.h && a.y + a.h >= b.y;
2322
2322
  }
2323
+ function contains(outer, inner) {
2324
+ return inner.x >= outer.x && inner.x + inner.w <= outer.x + outer.w && inner.y >= outer.y && inner.y + inner.h <= outer.y + outer.h;
2325
+ }
2323
2326
  var QuadNode = class _QuadNode {
2324
2327
  constructor(bounds, depth) {
2325
2328
  this.bounds = bounds;
@@ -2372,6 +2375,14 @@ var QuadNode = class _QuadNode {
2372
2375
  }
2373
2376
  }
2374
2377
  }
2378
+ collect(result) {
2379
+ result.push(...this.items);
2380
+ if (this.children) {
2381
+ for (const child of this.children) {
2382
+ child.collect(result);
2383
+ }
2384
+ }
2385
+ }
2375
2386
  getChildIndex(itemBounds) {
2376
2387
  const midX = this.bounds.x + this.bounds.w / 2;
2377
2388
  const midY = this.bounds.y + this.bounds.h / 2;
@@ -2435,6 +2446,7 @@ var Quadtree = class {
2435
2446
  return this._size;
2436
2447
  }
2437
2448
  insert(id, bounds) {
2449
+ this.expandToFit(bounds);
2438
2450
  this.root.insert({ id, bounds });
2439
2451
  this._size++;
2440
2452
  }
@@ -2459,6 +2471,24 @@ var Quadtree = class {
2459
2471
  this.root = new QuadNode(this.worldBounds, 0);
2460
2472
  this._size = 0;
2461
2473
  }
2474
+ expandToFit(bounds) {
2475
+ const current = this.root.bounds;
2476
+ if (contains(current, bounds)) return;
2477
+ const currentRight = current.x + current.w;
2478
+ const currentBottom = current.y + current.h;
2479
+ const requiredWidth = Math.max(currentRight, bounds.x + bounds.w) - Math.min(current.x, bounds.x);
2480
+ const requiredHeight = Math.max(currentBottom, bounds.y + bounds.h) - Math.min(current.y, bounds.y);
2481
+ const width = Math.max(current.w * 2, requiredWidth);
2482
+ const height = Math.max(current.h * 2, requiredHeight);
2483
+ const x = bounds.x < current.x ? currentRight - width : current.x;
2484
+ const y = bounds.y < current.y ? currentBottom - height : current.y;
2485
+ const entries = [];
2486
+ this.root.collect(entries);
2487
+ this.root = new QuadNode({ x, y, w: width, h: height }, 0);
2488
+ for (const entry of entries) {
2489
+ this.root.insert(entry);
2490
+ }
2491
+ }
2462
2492
  };
2463
2493
 
2464
2494
  // src/elements/stroke-smoothing.ts
@@ -10676,7 +10706,7 @@ var LaserTool = class {
10676
10706
  };
10677
10707
 
10678
10708
  // src/index.ts
10679
- var VERSION = "0.50.2";
10709
+ var VERSION = "0.50.3";
10680
10710
  // Annotate the CommonJS export names for ESM import in node:
10681
10711
  0 && (module.exports = {
10682
10712
  ArrowTool,