@dcl/ecs 7.2.4-5334700418.commit-a2ab16b → 7.2.4-5336980665.commit-96b8298
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/runtime/helpers/coordinates.d.ts +12 -0
- package/dist/runtime/helpers/coordinates.js +32 -0
- package/dist/runtime/helpers/index.d.ts +1 -0
- package/dist/runtime/helpers/index.js +1 -0
- package/dist-cjs/runtime/helpers/coordinates.d.ts +12 -0
- package/dist-cjs/runtime/helpers/coordinates.js +37 -0
- package/dist-cjs/runtime/helpers/index.d.ts +1 -0
- package/dist-cjs/runtime/helpers/index.js +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Coords = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if the given parcels array are connected
|
|
7
|
+
*/
|
|
8
|
+
export declare function areConnected(parcels: Coords[]): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if the given coords are equal
|
|
11
|
+
*/
|
|
12
|
+
export declare function isEqual(p1: Coords, p2: Coords): boolean;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if the given parcels array are connected
|
|
3
|
+
*/
|
|
4
|
+
export function areConnected(parcels) {
|
|
5
|
+
if (parcels.length === 0) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const visited = visitParcel(parcels[0], parcels);
|
|
9
|
+
return visited.length === parcels.length;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Returns true if the given coords are equal
|
|
13
|
+
*/
|
|
14
|
+
export function isEqual(p1, p2) {
|
|
15
|
+
return p1.x === p2.x && p1.y === p2.y;
|
|
16
|
+
}
|
|
17
|
+
function visitParcel(parcel, allParcels, visited = []) {
|
|
18
|
+
const isVisited = visited.some((visitedParcel) => isEqual(visitedParcel, parcel));
|
|
19
|
+
if (!isVisited) {
|
|
20
|
+
visited.push(parcel);
|
|
21
|
+
const neighbours = getNeighbours(parcel.x, parcel.y, allParcels);
|
|
22
|
+
neighbours.forEach((neighbours) => visitParcel(neighbours, allParcels, visited));
|
|
23
|
+
}
|
|
24
|
+
return visited;
|
|
25
|
+
}
|
|
26
|
+
function getIsNeighbourMatcher(x, y) {
|
|
27
|
+
return (coords) => (coords.x === x && (coords.y + 1 === y || coords.y - 1 === y)) ||
|
|
28
|
+
(coords.y === y && (coords.x + 1 === x || coords.x - 1 === x));
|
|
29
|
+
}
|
|
30
|
+
function getNeighbours(x, y, parcels) {
|
|
31
|
+
return parcels.filter(getIsNeighbourMatcher(x, y));
|
|
32
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Coords = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Returns true if the given parcels array are connected
|
|
7
|
+
*/
|
|
8
|
+
export declare function areConnected(parcels: Coords[]): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Returns true if the given coords are equal
|
|
11
|
+
*/
|
|
12
|
+
export declare function isEqual(p1: Coords, p2: Coords): boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEqual = exports.areConnected = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Returns true if the given parcels array are connected
|
|
6
|
+
*/
|
|
7
|
+
function areConnected(parcels) {
|
|
8
|
+
if (parcels.length === 0) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
const visited = visitParcel(parcels[0], parcels);
|
|
12
|
+
return visited.length === parcels.length;
|
|
13
|
+
}
|
|
14
|
+
exports.areConnected = areConnected;
|
|
15
|
+
/**
|
|
16
|
+
* Returns true if the given coords are equal
|
|
17
|
+
*/
|
|
18
|
+
function isEqual(p1, p2) {
|
|
19
|
+
return p1.x === p2.x && p1.y === p2.y;
|
|
20
|
+
}
|
|
21
|
+
exports.isEqual = isEqual;
|
|
22
|
+
function visitParcel(parcel, allParcels, visited = []) {
|
|
23
|
+
const isVisited = visited.some((visitedParcel) => isEqual(visitedParcel, parcel));
|
|
24
|
+
if (!isVisited) {
|
|
25
|
+
visited.push(parcel);
|
|
26
|
+
const neighbours = getNeighbours(parcel.x, parcel.y, allParcels);
|
|
27
|
+
neighbours.forEach((neighbours) => visitParcel(neighbours, allParcels, visited));
|
|
28
|
+
}
|
|
29
|
+
return visited;
|
|
30
|
+
}
|
|
31
|
+
function getIsNeighbourMatcher(x, y) {
|
|
32
|
+
return (coords) => (coords.x === x && (coords.y + 1 === y || coords.y - 1 === y)) ||
|
|
33
|
+
(coords.y === y && (coords.x + 1 === x || coords.x - 1 === x));
|
|
34
|
+
}
|
|
35
|
+
function getNeighbours(x, y, parcels) {
|
|
36
|
+
return parcels.filter(getIsNeighbourMatcher(x, y));
|
|
37
|
+
}
|
|
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./coordinates"), exports);
|
|
17
18
|
__exportStar(require("./tree"), exports);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl/ecs",
|
|
3
3
|
"description": "Decentraland ECS",
|
|
4
|
-
"version": "7.2.4-
|
|
4
|
+
"version": "7.2.4-5336980665.commit-96b8298",
|
|
5
5
|
"author": "DCL",
|
|
6
6
|
"bugs": "https://github.com/decentraland/ecs/issues",
|
|
7
7
|
"files": [
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
},
|
|
34
34
|
"types": "./dist/index.d.ts",
|
|
35
35
|
"typings": "./dist/index.d.ts",
|
|
36
|
-
"commit": "
|
|
36
|
+
"commit": "96b82981ea239874b2094af37ec0d30613a7f6e8"
|
|
37
37
|
}
|