@cosmos.gl/graph 2.2.0 → 2.2.1

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.d.ts CHANGED
@@ -238,24 +238,40 @@ export declare class Graph {
238
238
  * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
239
239
  * @returns A Float32Array containing the indices of points inside a rectangular area.
240
240
  */
241
+ getPointsInRect(selection: [[number, number], [number, number]]): Float32Array;
242
+ /**
243
+ * Get points indices inside a rectangular area.
244
+ * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
245
+ * The `left` and `right` coordinates should be from 0 to the width of the canvas.
246
+ * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
247
+ * @returns A Float32Array containing the indices of points inside a rectangular area.
248
+ * @deprecated Use `getPointsInRect` instead. This method will be removed in a future version.
249
+ */
241
250
  getPointsInRange(selection: [[number, number], [number, number]]): Float32Array;
242
251
  /**
243
- * Get points indices inside a lasso (polygon) area.
244
- * @param lassoPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the lasso polygon.
252
+ * Get points indices inside a polygon area.
253
+ * @param polygonPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the polygon.
245
254
  * The coordinates should be from 0 to the width/height of the canvas.
246
- * @returns A Float32Array containing the indices of points inside the lasso area.
255
+ * @returns A Float32Array containing the indices of points inside the polygon area.
247
256
  */
248
- getPointsInLasso(lassoPath: [number, number][]): Float32Array;
257
+ getPointsInPolygon(polygonPath: [number, number][]): Float32Array;
249
258
  /** Select points inside a rectangular area.
250
259
  * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
251
260
  * The `left` and `right` coordinates should be from 0 to the width of the canvas.
252
261
  * The `top` and `bottom` coordinates should be from 0 to the height of the canvas. */
262
+ selectPointsInRect(selection: [[number, number], [number, number]] | null): void;
263
+ /** Select points inside a rectangular area.
264
+ * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
265
+ * The `left` and `right` coordinates should be from 0 to the width of the canvas.
266
+ * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
267
+ * @deprecated Use `selectPointsInRect` instead. This method will be removed in a future version.
268
+ */
253
269
  selectPointsInRange(selection: [[number, number], [number, number]] | null): void;
254
- /** Select points inside a lasso (polygon) area.
255
- * @param lassoPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the lasso polygon.
270
+ /** Select points inside a polygon area.
271
+ * @param polygonPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the polygon.
256
272
  * The coordinates should be from 0 to the width/height of the canvas.
257
273
  * Set to null to clear selection. */
258
- selectPointsInLasso(lassoPath: [number, number][] | null): void;
274
+ selectPointsInPolygon(polygonPath: [number, number][] | null): void;
259
275
  /**
260
276
  * Select a point by index. If you want the adjacent points to get selected too, provide `true` as the second argument.
261
277
  * @param index The index of the point in the array of points.
package/dist/index.js CHANGED
@@ -10468,15 +10468,15 @@ precision highp float;
10468
10468
  #endif
10469
10469
 
10470
10470
  uniform sampler2D positionsTexture;
10471
- uniform sampler2D lassoPathTexture;
10472
- uniform int lassoPathLength;
10471
+ uniform sampler2D polygonPathTexture;
10472
+ uniform int polygonPathLength;
10473
10473
  uniform float spaceSize;
10474
10474
  uniform vec2 screenSize;
10475
10475
  uniform mat3 transformationMatrix;
10476
10476
 
10477
10477
  varying vec2 textureCoords;
10478
10478
 
10479
- vec2 getLassoPoint(sampler2D pathTexture, int index, int pathLength) {
10479
+ vec2 getPolygonPoint(sampler2D pathTexture, int index, int pathLength) {
10480
10480
  if (index >= pathLength) return vec2(0.0);
10481
10481
 
10482
10482
 
@@ -10498,8 +10498,8 @@ bool pointInPolygon(vec2 point, sampler2D pathTexture, int pathLength) {
10498
10498
 
10499
10499
  int j = int(mod(float(i + 1), float(pathLength)));
10500
10500
 
10501
- vec2 pi = getLassoPoint(pathTexture, i, pathLength);
10502
- vec2 pj = getLassoPoint(pathTexture, j, pathLength);
10501
+ vec2 pi = getPolygonPoint(pathTexture, i, pathLength);
10502
+ vec2 pj = getPolygonPoint(pathTexture, j, pathLength);
10503
10503
 
10504
10504
  if (((pi.y > point.y) != (pj.y > point.y)) &&
10505
10505
  (point.x < (pj.x - pi.x) * (point.y - pi.y) / (pj.y - pi.y) + pi.x)) {
@@ -10522,7 +10522,7 @@ void main() {
10522
10522
  gl_FragColor = vec4(0.0, 0.0, pointPosition.rg);
10523
10523
 
10524
10524
 
10525
- if (pointInPolygon(screenPos, lassoPathTexture, lassoPathLength)) {
10525
+ if (pointInPolygon(screenPos, polygonPathTexture, polygonPathLength)) {
10526
10526
  gl_FragColor.r = 1.0;
10527
10527
  }
10528
10528
  }`, zg = `precision mediump float;
@@ -10786,7 +10786,7 @@ void main() {
10786
10786
  }`;
10787
10787
  class Vg extends dn {
10788
10788
  constructor() {
10789
- super(...arguments), this.lassoPathLength = 0;
10789
+ super(...arguments), this.polygonPathLength = 0;
10790
10790
  }
10791
10791
  updatePositions() {
10792
10792
  const { reglInstance: e, store: n, data: r, config: { rescalePositions: i, enableSimulation: o } } = this, { pointsTextureSize: u } = n;
@@ -10939,7 +10939,7 @@ class Vg extends dn {
10939
10939
  scalePointsOnZoom: () => n.scalePointsOnZoom,
10940
10940
  maxPointSize: () => r.maxPointSize
10941
10941
  }
10942
- })), this.findPointsOnLassoSelectionCommand || (this.findPointsOnLassoSelectionCommand = e({
10942
+ })), this.findPointsOnPolygonSelectionCommand || (this.findPointsOnPolygonSelectionCommand = e({
10943
10943
  frag: Lg,
10944
10944
  vert: bt,
10945
10945
  framebuffer: () => this.selectedFbo,
@@ -10953,8 +10953,8 @@ class Vg extends dn {
10953
10953
  spaceSize: () => r.adjustedSpaceSize,
10954
10954
  screenSize: () => r.screenSize,
10955
10955
  transformationMatrix: () => r.transform,
10956
- lassoPathTexture: () => this.lassoPathTexture,
10957
- lassoPathLength: () => this.lassoPathLength
10956
+ polygonPathTexture: () => this.polygonPathTexture,
10957
+ polygonPathLength: () => this.polygonPathLength
10958
10958
  }
10959
10959
  })), this.clearHoveredFboCommand || (this.clearHoveredFboCommand = e({
10960
10960
  frag: $n,
@@ -11164,14 +11164,14 @@ class Vg extends dn {
11164
11164
  var e;
11165
11165
  (e = this.findPointsOnAreaSelectionCommand) == null || e.call(this);
11166
11166
  }
11167
- findPointsOnLassoSelection() {
11167
+ findPointsOnPolygonSelection() {
11168
11168
  var e;
11169
- (e = this.findPointsOnLassoSelectionCommand) == null || e.call(this);
11169
+ (e = this.findPointsOnPolygonSelectionCommand) == null || e.call(this);
11170
11170
  }
11171
- updateLassoPath(e) {
11171
+ updatePolygonPath(e) {
11172
11172
  const { reglInstance: n } = this;
11173
- if (this.lassoPathLength = e.length, e.length === 0) {
11174
- this.lassoPathTexture = void 0, this.lassoPathFbo = void 0;
11173
+ if (this.polygonPathLength = e.length, e.length === 0) {
11174
+ this.polygonPathTexture = void 0, this.polygonPathFbo = void 0;
11175
11175
  return;
11176
11176
  }
11177
11177
  const r = Math.ceil(Math.sqrt(e.length)), i = new Float32Array(r * r * 4);
@@ -11179,13 +11179,13 @@ class Vg extends dn {
11179
11179
  const [s, f] = u;
11180
11180
  i[o * 4] = s, i[o * 4 + 1] = f, i[o * 4 + 2] = 0, i[o * 4 + 3] = 0;
11181
11181
  }
11182
- this.lassoPathTexture || (this.lassoPathTexture = n.texture()), this.lassoPathTexture({
11182
+ this.polygonPathTexture || (this.polygonPathTexture = n.texture()), this.polygonPathTexture({
11183
11183
  data: i,
11184
11184
  width: r,
11185
11185
  height: r,
11186
11186
  type: "float"
11187
- }), this.lassoPathFbo || (this.lassoPathFbo = n.framebuffer()), this.lassoPathFbo({
11188
- color: this.lassoPathTexture,
11187
+ }), this.polygonPathFbo || (this.polygonPathFbo = n.framebuffer()), this.polygonPathFbo({
11188
+ color: this.polygonPathTexture,
11189
11189
  depth: !1,
11190
11190
  stencil: !1
11191
11191
  });
@@ -12851,28 +12851,39 @@ class Wy {
12851
12851
  * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
12852
12852
  * @returns A Float32Array containing the indices of points inside a rectangular area.
12853
12853
  */
12854
- getPointsInRange(e) {
12854
+ getPointsInRect(e) {
12855
12855
  if (this._isDestroyed || !this.reglInstance || !this.points) return new Float32Array();
12856
12856
  const n = this.store.screenSize[1];
12857
12857
  return this.store.selectedArea = [[e[0][0], n - e[1][1]], [e[1][0], n - e[0][1]]], this.points.findPointsOnAreaSelection(), tn(this.reglInstance, this.points.selectedFbo).map((i, o) => o % 4 === 0 && i !== 0 ? o / 4 : -1).filter((i) => i !== -1);
12858
12858
  }
12859
12859
  /**
12860
- * Get points indices inside a lasso (polygon) area.
12861
- * @param lassoPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the lasso polygon.
12860
+ * Get points indices inside a rectangular area.
12861
+ * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
12862
+ * The `left` and `right` coordinates should be from 0 to the width of the canvas.
12863
+ * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
12864
+ * @returns A Float32Array containing the indices of points inside a rectangular area.
12865
+ * @deprecated Use `getPointsInRect` instead. This method will be removed in a future version.
12866
+ */
12867
+ getPointsInRange(e) {
12868
+ return this.getPointsInRect(e);
12869
+ }
12870
+ /**
12871
+ * Get points indices inside a polygon area.
12872
+ * @param polygonPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the polygon.
12862
12873
  * The coordinates should be from 0 to the width/height of the canvas.
12863
- * @returns A Float32Array containing the indices of points inside the lasso area.
12874
+ * @returns A Float32Array containing the indices of points inside the polygon area.
12864
12875
  */
12865
- getPointsInLasso(e) {
12876
+ getPointsInPolygon(e) {
12866
12877
  if (this._isDestroyed || !this.reglInstance || !this.points) return new Float32Array();
12867
12878
  if (e.length < 3) return new Float32Array();
12868
12879
  const n = this.store.screenSize[1], r = e.map(([o, u]) => [o, n - u]);
12869
- return this.points.updateLassoPath(r), this.points.findPointsOnLassoSelection(), tn(this.reglInstance, this.points.selectedFbo).map((o, u) => u % 4 === 0 && o !== 0 ? u / 4 : -1).filter((o) => o !== -1);
12880
+ return this.points.updatePolygonPath(r), this.points.findPointsOnPolygonSelection(), tn(this.reglInstance, this.points.selectedFbo).map((o, u) => u % 4 === 0 && o !== 0 ? u / 4 : -1).filter((o) => o !== -1);
12870
12881
  }
12871
12882
  /** Select points inside a rectangular area.
12872
12883
  * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
12873
12884
  * The `left` and `right` coordinates should be from 0 to the width of the canvas.
12874
12885
  * The `top` and `bottom` coordinates should be from 0 to the height of the canvas. */
12875
- selectPointsInRange(e) {
12886
+ selectPointsInRect(e) {
12876
12887
  if (!(this._isDestroyed || !this.reglInstance || !this.points)) {
12877
12888
  if (e) {
12878
12889
  const n = this.store.screenSize[1];
@@ -12884,19 +12895,28 @@ class Wy {
12884
12895
  this.points.updateGreyoutStatus();
12885
12896
  }
12886
12897
  }
12887
- /** Select points inside a lasso (polygon) area.
12888
- * @param lassoPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the lasso polygon.
12898
+ /** Select points inside a rectangular area.
12899
+ * @param selection - Array of two corner points `[[left, top], [right, bottom]]`.
12900
+ * The `left` and `right` coordinates should be from 0 to the width of the canvas.
12901
+ * The `top` and `bottom` coordinates should be from 0 to the height of the canvas.
12902
+ * @deprecated Use `selectPointsInRect` instead. This method will be removed in a future version.
12903
+ */
12904
+ selectPointsInRange(e) {
12905
+ return this.selectPointsInRect(e);
12906
+ }
12907
+ /** Select points inside a polygon area.
12908
+ * @param polygonPath - Array of points `[[x1, y1], [x2, y2], ..., [xn, yn]]` that defines the polygon.
12889
12909
  * The coordinates should be from 0 to the width/height of the canvas.
12890
12910
  * Set to null to clear selection. */
12891
- selectPointsInLasso(e) {
12911
+ selectPointsInPolygon(e) {
12892
12912
  if (!(this._isDestroyed || !this.reglInstance || !this.points)) {
12893
12913
  if (e) {
12894
12914
  if (e.length < 3) {
12895
- console.warn("Lasso path requires at least 3 points to form a polygon.");
12915
+ console.warn("Polygon path requires at least 3 points to form a polygon.");
12896
12916
  return;
12897
12917
  }
12898
12918
  const n = this.store.screenSize[1], r = e.map(([o, u]) => [o, n - u]);
12899
- this.points.updateLassoPath(r), this.points.findPointsOnLassoSelection();
12919
+ this.points.updatePolygonPath(r), this.points.findPointsOnPolygonSelection();
12900
12920
  const i = tn(this.reglInstance, this.points.selectedFbo);
12901
12921
  this.store.selectedIndices = i.map((o, u) => u % 4 === 0 && o !== 0 ? u / 4 : -1).filter((o) => o !== -1);
12902
12922
  } else