microboard-temp 0.4.52 → 0.4.53

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.
@@ -19030,6 +19030,9 @@ class Comment {
19030
19030
  getItemToFollow() {
19031
19031
  return this.itemToFollow;
19032
19032
  }
19033
+ getMbrWithChildren() {
19034
+ return this.getMbr();
19035
+ }
19033
19036
  setItemToFollow(itemId) {
19034
19037
  this.emit({
19035
19038
  class: "Comment",
@@ -20727,9 +20730,9 @@ class SpatialIndex {
20727
20730
  return;
20728
20731
  }
20729
20732
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
20730
- this.Mbr = item.getMbr().copy();
20733
+ this.Mbr = item.getMbrWithChildren().copy();
20731
20734
  } else {
20732
- this.Mbr.combine([item.getMbr()]);
20735
+ this.Mbr.combine([item.getMbrWithChildren()]);
20733
20736
  }
20734
20737
  item.subject.subscribe(this.change);
20735
20738
  this.subject.publish(this.items);
@@ -20737,9 +20740,9 @@ class SpatialIndex {
20737
20740
  change = (item) => {
20738
20741
  this.itemsIndex.change(item);
20739
20742
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
20740
- this.Mbr = item.getMbr().copy();
20743
+ this.Mbr = item.getMbrWithChildren().copy();
20741
20744
  } else {
20742
- this.Mbr.combine([item.getMbr()]);
20745
+ this.Mbr.combine([item.getMbrWithChildren()]);
20743
20746
  }
20744
20747
  this.subject.publish(this.items);
20745
20748
  };
@@ -20750,7 +20753,7 @@ class SpatialIndex {
20750
20753
  this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
20751
20754
  this.itemsIndex.remove(item);
20752
20755
  this.Mbr = new Mbr;
20753
- this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbr()]));
20756
+ this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbrWithChildren()]));
20754
20757
  this.subject.publish(this.items);
20755
20758
  }
20756
20759
  copy() {
@@ -20865,46 +20868,60 @@ class SpatialIndex {
20865
20868
  const mbr = new Mbr(left, top, right, bottom);
20866
20869
  const items = this.itemsIndex.getEnclosed(mbr);
20867
20870
  const children = [];
20868
- items.forEach((item) => {
20871
+ const clearItems = items.filter((item) => {
20869
20872
  if ("index" in item && item.index) {
20870
20873
  children.push(...item.index.getEnclosed(left, top, right, bottom));
20874
+ if (!item.getMbr().isEnclosedBy(mbr)) {
20875
+ return false;
20876
+ }
20871
20877
  }
20878
+ return true;
20872
20879
  });
20873
- return [...items, ...children];
20880
+ return [...clearItems, ...children];
20874
20881
  }
20875
20882
  getEnclosedOrCrossed(left, top, right, bottom) {
20876
20883
  const mbr = new Mbr(left, top, right, bottom);
20877
20884
  const items = this.itemsIndex.getEnclosedOrCrossedBy(mbr);
20878
20885
  const children = [];
20879
- items.forEach((item) => {
20886
+ const clearItems = items.filter((item) => {
20880
20887
  if ("index" in item && item.index) {
20881
20888
  children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
20889
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
20890
+ return false;
20891
+ }
20882
20892
  }
20893
+ return true;
20883
20894
  });
20884
- return [...items, ...children];
20895
+ return [...clearItems, ...children];
20885
20896
  }
20886
20897
  getUnderPoint(point3, tolerance = 5) {
20887
20898
  const items = this.itemsIndex.getUnderPoint(point3, tolerance);
20888
20899
  const children = [];
20889
- items.forEach((item) => {
20900
+ const clearItems = items.filter((item) => {
20890
20901
  if ("index" in item && item.index) {
20891
20902
  children.push(...item.index.getUnderPoint(point3, tolerance));
20903
+ if (!item.getMbr().isUnderPoint(point3)) {
20904
+ return false;
20905
+ }
20892
20906
  }
20907
+ return true;
20893
20908
  });
20894
- return [...items, ...children];
20909
+ return [...clearItems, ...children];
20895
20910
  }
20896
20911
  getRectsEnclosedOrCrossed(left, top, right, bottom) {
20897
20912
  const mbr = new Mbr(left, top, right, bottom);
20898
20913
  const items = this.itemsIndex.getRectsEnclosedOrCrossedBy(mbr);
20899
20914
  const children = [];
20900
- items.forEach((item) => {
20901
- items.forEach((item2) => {
20902
- if ("index" in item2 && item2.index) {
20903
- children.push(...item2.index.getEnclosedOrCrossed(left, top, right, bottom));
20915
+ const clearItems = items.filter((item) => {
20916
+ if ("index" in item && item.index) {
20917
+ children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
20918
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
20919
+ return false;
20904
20920
  }
20905
- });
20921
+ }
20922
+ return true;
20906
20923
  });
20907
- return [...items, ...children];
20924
+ return [...clearItems, ...children];
20908
20925
  }
20909
20926
  getItemsEnclosedOrCrossed(left, top, right, bottom) {
20910
20927
  return this.getRectsEnclosedOrCrossed(left, top, right, bottom);
@@ -21555,6 +21572,24 @@ class BaseItem extends Mbr {
21555
21572
  getPathMbr() {
21556
21573
  return this.getMbr().copy();
21557
21574
  }
21575
+ isEnclosedBy(rect) {
21576
+ return this.getMbrWithChildren().isEnclosedBy(rect);
21577
+ }
21578
+ isUnderPoint(point3) {
21579
+ return this.getMbrWithChildren().isUnderPoint(point3);
21580
+ }
21581
+ isNearPoint(point3, distance) {
21582
+ return distance > this.getMbrWithChildren().getDistanceToPoint(point3);
21583
+ }
21584
+ isEnclosedOrCrossedBy(rect) {
21585
+ return this.getMbrWithChildren().isEnclosedOrCrossedBy(rect);
21586
+ }
21587
+ getMbrWithChildren() {
21588
+ if (!this.index) {
21589
+ return this.getMbr();
21590
+ }
21591
+ return this.getMbr().combine(this.index.list().map((item) => item.getMbr()));
21592
+ }
21558
21593
  getPath() {
21559
21594
  return new Path(this.getMbr().getLines());
21560
21595
  }
package/dist/cjs/index.js CHANGED
@@ -19030,6 +19030,9 @@ class Comment {
19030
19030
  getItemToFollow() {
19031
19031
  return this.itemToFollow;
19032
19032
  }
19033
+ getMbrWithChildren() {
19034
+ return this.getMbr();
19035
+ }
19033
19036
  setItemToFollow(itemId) {
19034
19037
  this.emit({
19035
19038
  class: "Comment",
@@ -20727,9 +20730,9 @@ class SpatialIndex {
20727
20730
  return;
20728
20731
  }
20729
20732
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
20730
- this.Mbr = item.getMbr().copy();
20733
+ this.Mbr = item.getMbrWithChildren().copy();
20731
20734
  } else {
20732
- this.Mbr.combine([item.getMbr()]);
20735
+ this.Mbr.combine([item.getMbrWithChildren()]);
20733
20736
  }
20734
20737
  item.subject.subscribe(this.change);
20735
20738
  this.subject.publish(this.items);
@@ -20737,9 +20740,9 @@ class SpatialIndex {
20737
20740
  change = (item) => {
20738
20741
  this.itemsIndex.change(item);
20739
20742
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
20740
- this.Mbr = item.getMbr().copy();
20743
+ this.Mbr = item.getMbrWithChildren().copy();
20741
20744
  } else {
20742
- this.Mbr.combine([item.getMbr()]);
20745
+ this.Mbr.combine([item.getMbrWithChildren()]);
20743
20746
  }
20744
20747
  this.subject.publish(this.items);
20745
20748
  };
@@ -20750,7 +20753,7 @@ class SpatialIndex {
20750
20753
  this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
20751
20754
  this.itemsIndex.remove(item);
20752
20755
  this.Mbr = new Mbr;
20753
- this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbr()]));
20756
+ this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbrWithChildren()]));
20754
20757
  this.subject.publish(this.items);
20755
20758
  }
20756
20759
  copy() {
@@ -20865,46 +20868,60 @@ class SpatialIndex {
20865
20868
  const mbr = new Mbr(left, top, right, bottom);
20866
20869
  const items = this.itemsIndex.getEnclosed(mbr);
20867
20870
  const children = [];
20868
- items.forEach((item) => {
20871
+ const clearItems = items.filter((item) => {
20869
20872
  if ("index" in item && item.index) {
20870
20873
  children.push(...item.index.getEnclosed(left, top, right, bottom));
20874
+ if (!item.getMbr().isEnclosedBy(mbr)) {
20875
+ return false;
20876
+ }
20871
20877
  }
20878
+ return true;
20872
20879
  });
20873
- return [...items, ...children];
20880
+ return [...clearItems, ...children];
20874
20881
  }
20875
20882
  getEnclosedOrCrossed(left, top, right, bottom) {
20876
20883
  const mbr = new Mbr(left, top, right, bottom);
20877
20884
  const items = this.itemsIndex.getEnclosedOrCrossedBy(mbr);
20878
20885
  const children = [];
20879
- items.forEach((item) => {
20886
+ const clearItems = items.filter((item) => {
20880
20887
  if ("index" in item && item.index) {
20881
20888
  children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
20889
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
20890
+ return false;
20891
+ }
20882
20892
  }
20893
+ return true;
20883
20894
  });
20884
- return [...items, ...children];
20895
+ return [...clearItems, ...children];
20885
20896
  }
20886
20897
  getUnderPoint(point3, tolerance = 5) {
20887
20898
  const items = this.itemsIndex.getUnderPoint(point3, tolerance);
20888
20899
  const children = [];
20889
- items.forEach((item) => {
20900
+ const clearItems = items.filter((item) => {
20890
20901
  if ("index" in item && item.index) {
20891
20902
  children.push(...item.index.getUnderPoint(point3, tolerance));
20903
+ if (!item.getMbr().isUnderPoint(point3)) {
20904
+ return false;
20905
+ }
20892
20906
  }
20907
+ return true;
20893
20908
  });
20894
- return [...items, ...children];
20909
+ return [...clearItems, ...children];
20895
20910
  }
20896
20911
  getRectsEnclosedOrCrossed(left, top, right, bottom) {
20897
20912
  const mbr = new Mbr(left, top, right, bottom);
20898
20913
  const items = this.itemsIndex.getRectsEnclosedOrCrossedBy(mbr);
20899
20914
  const children = [];
20900
- items.forEach((item) => {
20901
- items.forEach((item2) => {
20902
- if ("index" in item2 && item2.index) {
20903
- children.push(...item2.index.getEnclosedOrCrossed(left, top, right, bottom));
20915
+ const clearItems = items.filter((item) => {
20916
+ if ("index" in item && item.index) {
20917
+ children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
20918
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
20919
+ return false;
20904
20920
  }
20905
- });
20921
+ }
20922
+ return true;
20906
20923
  });
20907
- return [...items, ...children];
20924
+ return [...clearItems, ...children];
20908
20925
  }
20909
20926
  getItemsEnclosedOrCrossed(left, top, right, bottom) {
20910
20927
  return this.getRectsEnclosedOrCrossed(left, top, right, bottom);
@@ -21555,6 +21572,24 @@ class BaseItem extends Mbr {
21555
21572
  getPathMbr() {
21556
21573
  return this.getMbr().copy();
21557
21574
  }
21575
+ isEnclosedBy(rect) {
21576
+ return this.getMbrWithChildren().isEnclosedBy(rect);
21577
+ }
21578
+ isUnderPoint(point3) {
21579
+ return this.getMbrWithChildren().isUnderPoint(point3);
21580
+ }
21581
+ isNearPoint(point3, distance) {
21582
+ return distance > this.getMbrWithChildren().getDistanceToPoint(point3);
21583
+ }
21584
+ isEnclosedOrCrossedBy(rect) {
21585
+ return this.getMbrWithChildren().isEnclosedOrCrossedBy(rect);
21586
+ }
21587
+ getMbrWithChildren() {
21588
+ if (!this.index) {
21589
+ return this.getMbr();
21590
+ }
21591
+ return this.getMbr().combine(this.index.list().map((item) => item.getMbr()));
21592
+ }
21558
21593
  getPath() {
21559
21594
  return new Path(this.getMbr().getLines());
21560
21595
  }
package/dist/cjs/node.js CHANGED
@@ -21569,6 +21569,9 @@ class Comment {
21569
21569
  getItemToFollow() {
21570
21570
  return this.itemToFollow;
21571
21571
  }
21572
+ getMbrWithChildren() {
21573
+ return this.getMbr();
21574
+ }
21572
21575
  setItemToFollow(itemId) {
21573
21576
  this.emit({
21574
21577
  class: "Comment",
@@ -23199,9 +23202,9 @@ class SpatialIndex {
23199
23202
  return;
23200
23203
  }
23201
23204
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
23202
- this.Mbr = item.getMbr().copy();
23205
+ this.Mbr = item.getMbrWithChildren().copy();
23203
23206
  } else {
23204
- this.Mbr.combine([item.getMbr()]);
23207
+ this.Mbr.combine([item.getMbrWithChildren()]);
23205
23208
  }
23206
23209
  item.subject.subscribe(this.change);
23207
23210
  this.subject.publish(this.items);
@@ -23209,9 +23212,9 @@ class SpatialIndex {
23209
23212
  change = (item) => {
23210
23213
  this.itemsIndex.change(item);
23211
23214
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
23212
- this.Mbr = item.getMbr().copy();
23215
+ this.Mbr = item.getMbrWithChildren().copy();
23213
23216
  } else {
23214
- this.Mbr.combine([item.getMbr()]);
23217
+ this.Mbr.combine([item.getMbrWithChildren()]);
23215
23218
  }
23216
23219
  this.subject.publish(this.items);
23217
23220
  };
@@ -23222,7 +23225,7 @@ class SpatialIndex {
23222
23225
  this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
23223
23226
  this.itemsIndex.remove(item);
23224
23227
  this.Mbr = new Mbr;
23225
- this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbr()]));
23228
+ this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbrWithChildren()]));
23226
23229
  this.subject.publish(this.items);
23227
23230
  }
23228
23231
  copy() {
@@ -23337,46 +23340,60 @@ class SpatialIndex {
23337
23340
  const mbr = new Mbr(left, top, right, bottom);
23338
23341
  const items = this.itemsIndex.getEnclosed(mbr);
23339
23342
  const children = [];
23340
- items.forEach((item) => {
23343
+ const clearItems = items.filter((item) => {
23341
23344
  if ("index" in item && item.index) {
23342
23345
  children.push(...item.index.getEnclosed(left, top, right, bottom));
23346
+ if (!item.getMbr().isEnclosedBy(mbr)) {
23347
+ return false;
23348
+ }
23343
23349
  }
23350
+ return true;
23344
23351
  });
23345
- return [...items, ...children];
23352
+ return [...clearItems, ...children];
23346
23353
  }
23347
23354
  getEnclosedOrCrossed(left, top, right, bottom) {
23348
23355
  const mbr = new Mbr(left, top, right, bottom);
23349
23356
  const items = this.itemsIndex.getEnclosedOrCrossedBy(mbr);
23350
23357
  const children = [];
23351
- items.forEach((item) => {
23358
+ const clearItems = items.filter((item) => {
23352
23359
  if ("index" in item && item.index) {
23353
23360
  children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
23361
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
23362
+ return false;
23363
+ }
23354
23364
  }
23365
+ return true;
23355
23366
  });
23356
- return [...items, ...children];
23367
+ return [...clearItems, ...children];
23357
23368
  }
23358
23369
  getUnderPoint(point3, tolerance = 5) {
23359
23370
  const items = this.itemsIndex.getUnderPoint(point3, tolerance);
23360
23371
  const children = [];
23361
- items.forEach((item) => {
23372
+ const clearItems = items.filter((item) => {
23362
23373
  if ("index" in item && item.index) {
23363
23374
  children.push(...item.index.getUnderPoint(point3, tolerance));
23375
+ if (!item.getMbr().isUnderPoint(point3)) {
23376
+ return false;
23377
+ }
23364
23378
  }
23379
+ return true;
23365
23380
  });
23366
- return [...items, ...children];
23381
+ return [...clearItems, ...children];
23367
23382
  }
23368
23383
  getRectsEnclosedOrCrossed(left, top, right, bottom) {
23369
23384
  const mbr = new Mbr(left, top, right, bottom);
23370
23385
  const items = this.itemsIndex.getRectsEnclosedOrCrossedBy(mbr);
23371
23386
  const children = [];
23372
- items.forEach((item) => {
23373
- items.forEach((item2) => {
23374
- if ("index" in item2 && item2.index) {
23375
- children.push(...item2.index.getEnclosedOrCrossed(left, top, right, bottom));
23387
+ const clearItems = items.filter((item) => {
23388
+ if ("index" in item && item.index) {
23389
+ children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
23390
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
23391
+ return false;
23376
23392
  }
23377
- });
23393
+ }
23394
+ return true;
23378
23395
  });
23379
- return [...items, ...children];
23396
+ return [...clearItems, ...children];
23380
23397
  }
23381
23398
  getItemsEnclosedOrCrossed(left, top, right, bottom) {
23382
23399
  return this.getRectsEnclosedOrCrossed(left, top, right, bottom);
@@ -24027,6 +24044,24 @@ class BaseItem extends Mbr {
24027
24044
  getPathMbr() {
24028
24045
  return this.getMbr().copy();
24029
24046
  }
24047
+ isEnclosedBy(rect) {
24048
+ return this.getMbrWithChildren().isEnclosedBy(rect);
24049
+ }
24050
+ isUnderPoint(point3) {
24051
+ return this.getMbrWithChildren().isUnderPoint(point3);
24052
+ }
24053
+ isNearPoint(point3, distance) {
24054
+ return distance > this.getMbrWithChildren().getDistanceToPoint(point3);
24055
+ }
24056
+ isEnclosedOrCrossedBy(rect) {
24057
+ return this.getMbrWithChildren().isEnclosedOrCrossedBy(rect);
24058
+ }
24059
+ getMbrWithChildren() {
24060
+ if (!this.index) {
24061
+ return this.getMbr();
24062
+ }
24063
+ return this.getMbr().combine(this.index.list().map((item) => item.getMbr()));
24064
+ }
24030
24065
  getPath() {
24031
24066
  return new Path(this.getMbr().getLines());
24032
24067
  }
@@ -18880,6 +18880,9 @@ class Comment {
18880
18880
  getItemToFollow() {
18881
18881
  return this.itemToFollow;
18882
18882
  }
18883
+ getMbrWithChildren() {
18884
+ return this.getMbr();
18885
+ }
18883
18886
  setItemToFollow(itemId) {
18884
18887
  this.emit({
18885
18888
  class: "Comment",
@@ -20577,9 +20580,9 @@ class SpatialIndex {
20577
20580
  return;
20578
20581
  }
20579
20582
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
20580
- this.Mbr = item.getMbr().copy();
20583
+ this.Mbr = item.getMbrWithChildren().copy();
20581
20584
  } else {
20582
- this.Mbr.combine([item.getMbr()]);
20585
+ this.Mbr.combine([item.getMbrWithChildren()]);
20583
20586
  }
20584
20587
  item.subject.subscribe(this.change);
20585
20588
  this.subject.publish(this.items);
@@ -20587,9 +20590,9 @@ class SpatialIndex {
20587
20590
  change = (item) => {
20588
20591
  this.itemsIndex.change(item);
20589
20592
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
20590
- this.Mbr = item.getMbr().copy();
20593
+ this.Mbr = item.getMbrWithChildren().copy();
20591
20594
  } else {
20592
- this.Mbr.combine([item.getMbr()]);
20595
+ this.Mbr.combine([item.getMbrWithChildren()]);
20593
20596
  }
20594
20597
  this.subject.publish(this.items);
20595
20598
  };
@@ -20600,7 +20603,7 @@ class SpatialIndex {
20600
20603
  this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
20601
20604
  this.itemsIndex.remove(item);
20602
20605
  this.Mbr = new Mbr;
20603
- this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbr()]));
20606
+ this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbrWithChildren()]));
20604
20607
  this.subject.publish(this.items);
20605
20608
  }
20606
20609
  copy() {
@@ -20715,46 +20718,60 @@ class SpatialIndex {
20715
20718
  const mbr = new Mbr(left, top, right, bottom);
20716
20719
  const items = this.itemsIndex.getEnclosed(mbr);
20717
20720
  const children = [];
20718
- items.forEach((item) => {
20721
+ const clearItems = items.filter((item) => {
20719
20722
  if ("index" in item && item.index) {
20720
20723
  children.push(...item.index.getEnclosed(left, top, right, bottom));
20724
+ if (!item.getMbr().isEnclosedBy(mbr)) {
20725
+ return false;
20726
+ }
20721
20727
  }
20728
+ return true;
20722
20729
  });
20723
- return [...items, ...children];
20730
+ return [...clearItems, ...children];
20724
20731
  }
20725
20732
  getEnclosedOrCrossed(left, top, right, bottom) {
20726
20733
  const mbr = new Mbr(left, top, right, bottom);
20727
20734
  const items = this.itemsIndex.getEnclosedOrCrossedBy(mbr);
20728
20735
  const children = [];
20729
- items.forEach((item) => {
20736
+ const clearItems = items.filter((item) => {
20730
20737
  if ("index" in item && item.index) {
20731
20738
  children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
20739
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
20740
+ return false;
20741
+ }
20732
20742
  }
20743
+ return true;
20733
20744
  });
20734
- return [...items, ...children];
20745
+ return [...clearItems, ...children];
20735
20746
  }
20736
20747
  getUnderPoint(point3, tolerance = 5) {
20737
20748
  const items = this.itemsIndex.getUnderPoint(point3, tolerance);
20738
20749
  const children = [];
20739
- items.forEach((item) => {
20750
+ const clearItems = items.filter((item) => {
20740
20751
  if ("index" in item && item.index) {
20741
20752
  children.push(...item.index.getUnderPoint(point3, tolerance));
20753
+ if (!item.getMbr().isUnderPoint(point3)) {
20754
+ return false;
20755
+ }
20742
20756
  }
20757
+ return true;
20743
20758
  });
20744
- return [...items, ...children];
20759
+ return [...clearItems, ...children];
20745
20760
  }
20746
20761
  getRectsEnclosedOrCrossed(left, top, right, bottom) {
20747
20762
  const mbr = new Mbr(left, top, right, bottom);
20748
20763
  const items = this.itemsIndex.getRectsEnclosedOrCrossedBy(mbr);
20749
20764
  const children = [];
20750
- items.forEach((item) => {
20751
- items.forEach((item2) => {
20752
- if ("index" in item2 && item2.index) {
20753
- children.push(...item2.index.getEnclosedOrCrossed(left, top, right, bottom));
20765
+ const clearItems = items.filter((item) => {
20766
+ if ("index" in item && item.index) {
20767
+ children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
20768
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
20769
+ return false;
20754
20770
  }
20755
- });
20771
+ }
20772
+ return true;
20756
20773
  });
20757
- return [...items, ...children];
20774
+ return [...clearItems, ...children];
20758
20775
  }
20759
20776
  getItemsEnclosedOrCrossed(left, top, right, bottom) {
20760
20777
  return this.getRectsEnclosedOrCrossed(left, top, right, bottom);
@@ -21405,6 +21422,24 @@ class BaseItem extends Mbr {
21405
21422
  getPathMbr() {
21406
21423
  return this.getMbr().copy();
21407
21424
  }
21425
+ isEnclosedBy(rect) {
21426
+ return this.getMbrWithChildren().isEnclosedBy(rect);
21427
+ }
21428
+ isUnderPoint(point3) {
21429
+ return this.getMbrWithChildren().isUnderPoint(point3);
21430
+ }
21431
+ isNearPoint(point3, distance) {
21432
+ return distance > this.getMbrWithChildren().getDistanceToPoint(point3);
21433
+ }
21434
+ isEnclosedOrCrossedBy(rect) {
21435
+ return this.getMbrWithChildren().isEnclosedOrCrossedBy(rect);
21436
+ }
21437
+ getMbrWithChildren() {
21438
+ if (!this.index) {
21439
+ return this.getMbr();
21440
+ }
21441
+ return this.getMbr().combine(this.index.list().map((item) => item.getMbr()));
21442
+ }
21408
21443
  getPath() {
21409
21444
  return new Path(this.getMbr().getLines());
21410
21445
  }
package/dist/esm/index.js CHANGED
@@ -18873,6 +18873,9 @@ class Comment {
18873
18873
  getItemToFollow() {
18874
18874
  return this.itemToFollow;
18875
18875
  }
18876
+ getMbrWithChildren() {
18877
+ return this.getMbr();
18878
+ }
18876
18879
  setItemToFollow(itemId) {
18877
18880
  this.emit({
18878
18881
  class: "Comment",
@@ -20570,9 +20573,9 @@ class SpatialIndex {
20570
20573
  return;
20571
20574
  }
20572
20575
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
20573
- this.Mbr = item.getMbr().copy();
20576
+ this.Mbr = item.getMbrWithChildren().copy();
20574
20577
  } else {
20575
- this.Mbr.combine([item.getMbr()]);
20578
+ this.Mbr.combine([item.getMbrWithChildren()]);
20576
20579
  }
20577
20580
  item.subject.subscribe(this.change);
20578
20581
  this.subject.publish(this.items);
@@ -20580,9 +20583,9 @@ class SpatialIndex {
20580
20583
  change = (item) => {
20581
20584
  this.itemsIndex.change(item);
20582
20585
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
20583
- this.Mbr = item.getMbr().copy();
20586
+ this.Mbr = item.getMbrWithChildren().copy();
20584
20587
  } else {
20585
- this.Mbr.combine([item.getMbr()]);
20588
+ this.Mbr.combine([item.getMbrWithChildren()]);
20586
20589
  }
20587
20590
  this.subject.publish(this.items);
20588
20591
  };
@@ -20593,7 +20596,7 @@ class SpatialIndex {
20593
20596
  this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
20594
20597
  this.itemsIndex.remove(item);
20595
20598
  this.Mbr = new Mbr;
20596
- this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbr()]));
20599
+ this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbrWithChildren()]));
20597
20600
  this.subject.publish(this.items);
20598
20601
  }
20599
20602
  copy() {
@@ -20708,46 +20711,60 @@ class SpatialIndex {
20708
20711
  const mbr = new Mbr(left, top, right, bottom);
20709
20712
  const items = this.itemsIndex.getEnclosed(mbr);
20710
20713
  const children = [];
20711
- items.forEach((item) => {
20714
+ const clearItems = items.filter((item) => {
20712
20715
  if ("index" in item && item.index) {
20713
20716
  children.push(...item.index.getEnclosed(left, top, right, bottom));
20717
+ if (!item.getMbr().isEnclosedBy(mbr)) {
20718
+ return false;
20719
+ }
20714
20720
  }
20721
+ return true;
20715
20722
  });
20716
- return [...items, ...children];
20723
+ return [...clearItems, ...children];
20717
20724
  }
20718
20725
  getEnclosedOrCrossed(left, top, right, bottom) {
20719
20726
  const mbr = new Mbr(left, top, right, bottom);
20720
20727
  const items = this.itemsIndex.getEnclosedOrCrossedBy(mbr);
20721
20728
  const children = [];
20722
- items.forEach((item) => {
20729
+ const clearItems = items.filter((item) => {
20723
20730
  if ("index" in item && item.index) {
20724
20731
  children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
20732
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
20733
+ return false;
20734
+ }
20725
20735
  }
20736
+ return true;
20726
20737
  });
20727
- return [...items, ...children];
20738
+ return [...clearItems, ...children];
20728
20739
  }
20729
20740
  getUnderPoint(point3, tolerance = 5) {
20730
20741
  const items = this.itemsIndex.getUnderPoint(point3, tolerance);
20731
20742
  const children = [];
20732
- items.forEach((item) => {
20743
+ const clearItems = items.filter((item) => {
20733
20744
  if ("index" in item && item.index) {
20734
20745
  children.push(...item.index.getUnderPoint(point3, tolerance));
20746
+ if (!item.getMbr().isUnderPoint(point3)) {
20747
+ return false;
20748
+ }
20735
20749
  }
20750
+ return true;
20736
20751
  });
20737
- return [...items, ...children];
20752
+ return [...clearItems, ...children];
20738
20753
  }
20739
20754
  getRectsEnclosedOrCrossed(left, top, right, bottom) {
20740
20755
  const mbr = new Mbr(left, top, right, bottom);
20741
20756
  const items = this.itemsIndex.getRectsEnclosedOrCrossedBy(mbr);
20742
20757
  const children = [];
20743
- items.forEach((item) => {
20744
- items.forEach((item2) => {
20745
- if ("index" in item2 && item2.index) {
20746
- children.push(...item2.index.getEnclosedOrCrossed(left, top, right, bottom));
20758
+ const clearItems = items.filter((item) => {
20759
+ if ("index" in item && item.index) {
20760
+ children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
20761
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
20762
+ return false;
20747
20763
  }
20748
- });
20764
+ }
20765
+ return true;
20749
20766
  });
20750
- return [...items, ...children];
20767
+ return [...clearItems, ...children];
20751
20768
  }
20752
20769
  getItemsEnclosedOrCrossed(left, top, right, bottom) {
20753
20770
  return this.getRectsEnclosedOrCrossed(left, top, right, bottom);
@@ -21398,6 +21415,24 @@ class BaseItem extends Mbr {
21398
21415
  getPathMbr() {
21399
21416
  return this.getMbr().copy();
21400
21417
  }
21418
+ isEnclosedBy(rect) {
21419
+ return this.getMbrWithChildren().isEnclosedBy(rect);
21420
+ }
21421
+ isUnderPoint(point3) {
21422
+ return this.getMbrWithChildren().isUnderPoint(point3);
21423
+ }
21424
+ isNearPoint(point3, distance) {
21425
+ return distance > this.getMbrWithChildren().getDistanceToPoint(point3);
21426
+ }
21427
+ isEnclosedOrCrossedBy(rect) {
21428
+ return this.getMbrWithChildren().isEnclosedOrCrossedBy(rect);
21429
+ }
21430
+ getMbrWithChildren() {
21431
+ if (!this.index) {
21432
+ return this.getMbr();
21433
+ }
21434
+ return this.getMbr().combine(this.index.list().map((item) => item.getMbr()));
21435
+ }
21401
21436
  getPath() {
21402
21437
  return new Path(this.getMbr().getLines());
21403
21438
  }
package/dist/esm/node.js CHANGED
@@ -21407,6 +21407,9 @@ class Comment {
21407
21407
  getItemToFollow() {
21408
21408
  return this.itemToFollow;
21409
21409
  }
21410
+ getMbrWithChildren() {
21411
+ return this.getMbr();
21412
+ }
21410
21413
  setItemToFollow(itemId) {
21411
21414
  this.emit({
21412
21415
  class: "Comment",
@@ -23037,9 +23040,9 @@ class SpatialIndex {
23037
23040
  return;
23038
23041
  }
23039
23042
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
23040
- this.Mbr = item.getMbr().copy();
23043
+ this.Mbr = item.getMbrWithChildren().copy();
23041
23044
  } else {
23042
- this.Mbr.combine([item.getMbr()]);
23045
+ this.Mbr.combine([item.getMbrWithChildren()]);
23043
23046
  }
23044
23047
  item.subject.subscribe(this.change);
23045
23048
  this.subject.publish(this.items);
@@ -23047,9 +23050,9 @@ class SpatialIndex {
23047
23050
  change = (item) => {
23048
23051
  this.itemsIndex.change(item);
23049
23052
  if (this.Mbr.getWidth() === 0 && this.Mbr.getHeight() === 0) {
23050
- this.Mbr = item.getMbr().copy();
23053
+ this.Mbr = item.getMbrWithChildren().copy();
23051
23054
  } else {
23052
- this.Mbr.combine([item.getMbr()]);
23055
+ this.Mbr.combine([item.getMbrWithChildren()]);
23053
23056
  }
23054
23057
  this.subject.publish(this.items);
23055
23058
  };
@@ -23060,7 +23063,7 @@ class SpatialIndex {
23060
23063
  this.itemsArray.splice(this.itemsArray.indexOf(item), 1);
23061
23064
  this.itemsIndex.remove(item);
23062
23065
  this.Mbr = new Mbr;
23063
- this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbr()]));
23066
+ this.itemsArray.forEach((item2) => this.Mbr.combine([item2.getMbrWithChildren()]));
23064
23067
  this.subject.publish(this.items);
23065
23068
  }
23066
23069
  copy() {
@@ -23175,46 +23178,60 @@ class SpatialIndex {
23175
23178
  const mbr = new Mbr(left, top, right, bottom);
23176
23179
  const items = this.itemsIndex.getEnclosed(mbr);
23177
23180
  const children = [];
23178
- items.forEach((item) => {
23181
+ const clearItems = items.filter((item) => {
23179
23182
  if ("index" in item && item.index) {
23180
23183
  children.push(...item.index.getEnclosed(left, top, right, bottom));
23184
+ if (!item.getMbr().isEnclosedBy(mbr)) {
23185
+ return false;
23186
+ }
23181
23187
  }
23188
+ return true;
23182
23189
  });
23183
- return [...items, ...children];
23190
+ return [...clearItems, ...children];
23184
23191
  }
23185
23192
  getEnclosedOrCrossed(left, top, right, bottom) {
23186
23193
  const mbr = new Mbr(left, top, right, bottom);
23187
23194
  const items = this.itemsIndex.getEnclosedOrCrossedBy(mbr);
23188
23195
  const children = [];
23189
- items.forEach((item) => {
23196
+ const clearItems = items.filter((item) => {
23190
23197
  if ("index" in item && item.index) {
23191
23198
  children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
23199
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
23200
+ return false;
23201
+ }
23192
23202
  }
23203
+ return true;
23193
23204
  });
23194
- return [...items, ...children];
23205
+ return [...clearItems, ...children];
23195
23206
  }
23196
23207
  getUnderPoint(point3, tolerance = 5) {
23197
23208
  const items = this.itemsIndex.getUnderPoint(point3, tolerance);
23198
23209
  const children = [];
23199
- items.forEach((item) => {
23210
+ const clearItems = items.filter((item) => {
23200
23211
  if ("index" in item && item.index) {
23201
23212
  children.push(...item.index.getUnderPoint(point3, tolerance));
23213
+ if (!item.getMbr().isUnderPoint(point3)) {
23214
+ return false;
23215
+ }
23202
23216
  }
23217
+ return true;
23203
23218
  });
23204
- return [...items, ...children];
23219
+ return [...clearItems, ...children];
23205
23220
  }
23206
23221
  getRectsEnclosedOrCrossed(left, top, right, bottom) {
23207
23222
  const mbr = new Mbr(left, top, right, bottom);
23208
23223
  const items = this.itemsIndex.getRectsEnclosedOrCrossedBy(mbr);
23209
23224
  const children = [];
23210
- items.forEach((item) => {
23211
- items.forEach((item2) => {
23212
- if ("index" in item2 && item2.index) {
23213
- children.push(...item2.index.getEnclosedOrCrossed(left, top, right, bottom));
23225
+ const clearItems = items.filter((item) => {
23226
+ if ("index" in item && item.index) {
23227
+ children.push(...item.index.getEnclosedOrCrossed(left, top, right, bottom));
23228
+ if (!item.getMbr().isEnclosedOrCrossedBy(mbr)) {
23229
+ return false;
23214
23230
  }
23215
- });
23231
+ }
23232
+ return true;
23216
23233
  });
23217
- return [...items, ...children];
23234
+ return [...clearItems, ...children];
23218
23235
  }
23219
23236
  getItemsEnclosedOrCrossed(left, top, right, bottom) {
23220
23237
  return this.getRectsEnclosedOrCrossed(left, top, right, bottom);
@@ -23865,6 +23882,24 @@ class BaseItem extends Mbr {
23865
23882
  getPathMbr() {
23866
23883
  return this.getMbr().copy();
23867
23884
  }
23885
+ isEnclosedBy(rect) {
23886
+ return this.getMbrWithChildren().isEnclosedBy(rect);
23887
+ }
23888
+ isUnderPoint(point3) {
23889
+ return this.getMbrWithChildren().isUnderPoint(point3);
23890
+ }
23891
+ isNearPoint(point3, distance) {
23892
+ return distance > this.getMbrWithChildren().getDistanceToPoint(point3);
23893
+ }
23894
+ isEnclosedOrCrossedBy(rect) {
23895
+ return this.getMbrWithChildren().isEnclosedOrCrossedBy(rect);
23896
+ }
23897
+ getMbrWithChildren() {
23898
+ if (!this.index) {
23899
+ return this.getMbr();
23900
+ }
23901
+ return this.getMbr().combine(this.index.list().map((item) => item.getMbr()));
23902
+ }
23868
23903
  getPath() {
23869
23904
  return new Path(this.getMbr().getLines());
23870
23905
  }
@@ -13,6 +13,7 @@ import { Subject } from "../../Subject";
13
13
  import { Path, Paths } from "../Path";
14
14
  import { BaseItemOperation } from "./BaseItemOperation";
15
15
  import { SimpleSpatialIndex } from "../../SpatialIndex/SimpleSpatialIndex";
16
+ import { Point } from "../Point";
16
17
  export type BaseItemData = {
17
18
  itemType: string;
18
19
  } & Record<string, any>;
@@ -60,6 +61,11 @@ export declare class BaseItem extends Mbr implements Geometry {
60
61
  addOnRemoveCallback(cb: () => void): void;
61
62
  onRemove(): void;
62
63
  getPathMbr(): Mbr;
64
+ isEnclosedBy(rect: Mbr): boolean;
65
+ isUnderPoint(point: Point): boolean;
66
+ isNearPoint(point: Point, distance: number): boolean;
67
+ isEnclosedOrCrossedBy(rect: Mbr): boolean;
68
+ getMbrWithChildren(): Mbr;
63
69
  getPath(): Path | Paths;
64
70
  render(context: DrawingContext): void;
65
71
  renderHTML(documentFactory: DocumentFactory): HTMLElement;
@@ -52,6 +52,7 @@ export declare class Comment implements Geometry {
52
52
  deserialize(data: CommentData): this;
53
53
  private emit;
54
54
  getItemToFollow(): string | undefined;
55
+ getMbrWithChildren(): Mbr;
55
56
  setItemToFollow(itemId: string | undefined): void;
56
57
  setId(id: string): this;
57
58
  getId(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microboard-temp",
3
- "version": "0.4.52",
3
+ "version": "0.4.53",
4
4
  "description": "A flexible interactive whiteboard library",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",