@mborecki/geo2d 0.4.0 → 0.5.0
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Vec2 } from '@mb-puzzle/vec2';
|
|
2
2
|
|
|
3
3
|
export class Grid {
|
|
4
|
-
|
|
4
|
+
size: Vec2;
|
|
5
5
|
constructor(size: Vec2) {
|
|
6
6
|
if (size.x <= 0 || size.y <= 0) {
|
|
7
7
|
throw new Error(`Invalid grid size: width and height must be positive (got ${size.x}x${size.y})`);
|
|
@@ -73,7 +73,7 @@ export class Grid {
|
|
|
73
73
|
new Vec2(0, 1),
|
|
74
74
|
]
|
|
75
75
|
|
|
76
|
-
return dirs.map(d =>
|
|
76
|
+
return dirs.map(d => Vec2.add(d,v))
|
|
77
77
|
.filter(v => Grid.isInGrid(v, size));
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -44,7 +44,7 @@ export class Vec2 {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
get size() {
|
|
47
|
-
return Math.sqrt(this.x*this.x + this.y*this.y);
|
|
47
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
*[Symbol.iterator]() {
|
|
@@ -99,4 +99,8 @@ export class Vec2 {
|
|
|
99
99
|
|
|
100
100
|
throw new Error('Wrong Vec2 source');
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
static add(v1: Vec2, v2: Vec2) {
|
|
104
|
+
return new Vec2(v1.x + v2.x, v1.y + v2.y);
|
|
105
|
+
}
|
|
102
106
|
}
|