wgge 1.0.16 → 1.0.18
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/core/model/vector/Vector2.js +24 -0
- package/package.json +1 -1
|
@@ -144,6 +144,30 @@ export default class Vector2 extends ObjectModel {
|
|
|
144
144
|
return neighbors;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
isNeighborPosition(position, size = 1, includeCenter = false) {
|
|
148
|
+
const distX = Math.abs(this.x - position.x);
|
|
149
|
+
const distY = Math.abs(this.y - position.y);
|
|
150
|
+
if (distX === 0 && distY === 0) {
|
|
151
|
+
return includeCenter;
|
|
152
|
+
}
|
|
153
|
+
return Math.max(distX, distY) <= size;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
getDirectNeighborPositions(position, includeCenter = false) {
|
|
157
|
+
const positions = [];
|
|
158
|
+
if (includeCenter) positions.push(position);
|
|
159
|
+
positions.push(new Vector2(position.x - 1, position.y));
|
|
160
|
+
positions.push(new Vector2(position.x, position.y - 1));
|
|
161
|
+
positions.push(new Vector2(position.x + 1, position.y));
|
|
162
|
+
positions.push(new Vector2(position.x, position.y + 1));
|
|
163
|
+
return positions;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
isDirectNeighborPosition(position, includeCenter = false) {
|
|
167
|
+
if (!this.isNeighborPosition(position, 1, includeCenter)) return false;
|
|
168
|
+
return (this.x === position.x || this.y === position.y);
|
|
169
|
+
}
|
|
170
|
+
|
|
147
171
|
getClosest(positions) {
|
|
148
172
|
if ((!positions) || positions.length === 0) return null;
|
|
149
173
|
if (positions.length === 1) return positions[0];
|