midgard-hex-grid 1.0.0 → 1.0.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/README.md +102 -1
- package/demo/demo-minimal.ts +531 -0
- package/demo/demo-theory.ts +1679 -0
- package/demo/index.html +11 -0
- package/demo/minimal.html +11 -0
- package/demo/package-lock.json +1162 -0
- package/demo/package.json +11 -0
- package/demo/vite.config.ts +9 -0
- package/dist/coordinate-layer.d.ts +1 -11
- package/dist/coordinate-layer.d.ts.map +1 -1
- package/dist/coordinate-layer.js +5 -5
- package/dist/coordinate-layer.js.map +1 -1
- package/dist/coordinate-positioner.d.ts +1 -17
- package/dist/coordinate-positioner.d.ts.map +1 -1
- package/dist/coordinate-positioner.js +7 -7
- package/dist/coordinate-positioner.js.map +1 -1
- package/dist/coordinate-range-fill.d.ts +1 -20
- package/dist/coordinate-range-fill.d.ts.map +1 -1
- package/dist/coordinate-range-fill.js +12 -10
- package/dist/coordinate-range-fill.js.map +1 -1
- package/dist/coordinate-range.d.ts +16 -7
- package/dist/coordinate-range.d.ts.map +1 -1
- package/dist/coordinate-range.js +30 -13
- package/dist/coordinate-range.js.map +1 -1
- package/dist/geometry.d.ts +1 -25
- package/dist/geometry.d.ts.map +1 -1
- package/dist/geometry.js +7 -7
- package/dist/geometry.js.map +1 -1
- package/dist/h-g-bounds.d.ts +8 -5
- package/dist/h-g-bounds.d.ts.map +1 -1
- package/dist/h-g-bounds.js +12 -10
- package/dist/h-g-bounds.js.map +1 -1
- package/dist/h-g-hexagon.d.ts +21 -7
- package/dist/h-g-hexagon.d.ts.map +1 -1
- package/dist/h-g-hexagon.js +34 -12
- package/dist/h-g-hexagon.js.map +1 -1
- package/dist/hex-grid.d.ts +5 -1
- package/dist/hex-grid.d.ts.map +1 -1
- package/dist/hex-grid.js +32 -15
- package/dist/hex-grid.js.map +1 -1
- package/dist/neighbours.d.ts +1 -23
- package/dist/neighbours.d.ts.map +1 -1
- package/dist/neighbours.js +7 -7
- package/dist/neighbours.js.map +1 -1
- package/docs/images/minimal-x.png +0 -0
- package/docs/images/minimal-y.png +0 -0
- package/docs/images/theory-x.png +0 -0
- package/docs/images/theory-y.png +0 -0
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ export type LayeredCoordinate = {
|
|
|
16
16
|
* for rendering.
|
|
17
17
|
*/
|
|
18
18
|
export declare class CoordinateLayer {
|
|
19
|
-
private
|
|
19
|
+
#private;
|
|
20
20
|
/**
|
|
21
21
|
* Creates a new coordinate layer.
|
|
22
22
|
*
|
|
@@ -26,16 +26,6 @@ export declare class CoordinateLayer {
|
|
|
26
26
|
* @param coordinates - The coordinates to sort and layer.
|
|
27
27
|
*/
|
|
28
28
|
constructor(coordinates: Coordinate[]);
|
|
29
|
-
/**
|
|
30
|
-
* Sorts the coordinates by y first and x second.
|
|
31
|
-
*
|
|
32
|
-
* Coordinates with the lowest y value come first.
|
|
33
|
-
* Coordinates on the same y row are ordered from
|
|
34
|
-
* the lowest x value to the highest x value.
|
|
35
|
-
*
|
|
36
|
-
* @returns A new array containing the sorted coordinates.
|
|
37
|
-
*/
|
|
38
|
-
sortCoordinates(): Coordinate[];
|
|
39
29
|
/**
|
|
40
30
|
* Creates layered coordinates for rendering a Midgard hex grid.
|
|
41
31
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate-layer.d.ts","sourceRoot":"","sources":["../src/coordinate-layer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;GAGG;AACH,qBAAa,eAAe
|
|
1
|
+
{"version":3,"file":"coordinate-layer.d.ts","sourceRoot":"","sources":["../src/coordinate-layer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;GAGG;AACH,qBAAa,eAAe;;IAG1B;;;;;;;OAOG;IACH,YAAY,WAAW,EAAE,UAAU,EAAE,EAEpC;IAyBD;;;;;;;;;;OAUG;IACH,qBAAqB,IAAI,iBAAiB,EAAE,CAqB3C;CACF"}
|
package/dist/coordinate-layer.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* for rendering.
|
|
4
4
|
*/
|
|
5
5
|
export class CoordinateLayer {
|
|
6
|
-
coordinates;
|
|
6
|
+
#coordinates;
|
|
7
7
|
/**
|
|
8
8
|
* Creates a new coordinate layer.
|
|
9
9
|
*
|
|
@@ -13,7 +13,7 @@ export class CoordinateLayer {
|
|
|
13
13
|
* @param coordinates - The coordinates to sort and layer.
|
|
14
14
|
*/
|
|
15
15
|
constructor(coordinates) {
|
|
16
|
-
this
|
|
16
|
+
this.#coordinates = [...coordinates];
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Sorts the coordinates by y first and x second.
|
|
@@ -24,8 +24,8 @@ export class CoordinateLayer {
|
|
|
24
24
|
*
|
|
25
25
|
* @returns A new array containing the sorted coordinates.
|
|
26
26
|
*/
|
|
27
|
-
sortCoordinates() {
|
|
28
|
-
const sortedCoordinates = [...this
|
|
27
|
+
#sortCoordinates() {
|
|
28
|
+
const sortedCoordinates = [...this.#coordinates];
|
|
29
29
|
sortedCoordinates.sort((firstCoordinate, secondCoordinate) => {
|
|
30
30
|
if (firstCoordinate.y !== secondCoordinate.y) {
|
|
31
31
|
return firstCoordinate.y - secondCoordinate.y;
|
|
@@ -46,7 +46,7 @@ export class CoordinateLayer {
|
|
|
46
46
|
* @returns Sorted coordinates with their calculated z-index.
|
|
47
47
|
*/
|
|
48
48
|
getLayeredCoordinates() {
|
|
49
|
-
const sortedCoordinates = this
|
|
49
|
+
const sortedCoordinates = this.#sortCoordinates();
|
|
50
50
|
const layeredCoordinates = [];
|
|
51
51
|
let previousY;
|
|
52
52
|
let zIndex = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate-layer.js","sourceRoot":"","sources":["../src/coordinate-layer.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,MAAM,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":"coordinate-layer.js","sourceRoot":"","sources":["../src/coordinate-layer.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,MAAM,OAAO,eAAe;IACjB,YAAY,CAAc;IAEnC;;;;;;;OAOG;IACH,YAAY,WAAyB;QACnC,IAAI,CAAC,YAAY,GAAG,CAAC,GAAG,WAAW,CAAC,CAAA;IACtC,CAAC;IAED;;;;;;;;OAQG;IACH,gBAAgB;QACd,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAA;QAEhD,iBAAiB,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,gBAAgB,EAAE,EAAE;YAC3D,IAAI,eAAe,CAAC,CAAC,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC;gBAC7C,OAAO,eAAe,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAA;YAC/C,CAAC;YAED,OAAO,eAAe,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAA;QAC/C,CAAC,CAAC,CAAA;QAEF,OAAO,iBAAiB,CAAA;IAC1B,CAAC;IAED;;;;;;;;;;OAUG;IACH,qBAAqB;QACnB,MAAM,iBAAiB,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAA;QACjD,MAAM,kBAAkB,GAAwB,EAAE,CAAA;QAElD,IAAI,SAA6B,CAAA;QACjC,IAAI,MAAM,GAAG,CAAC,CAAA;QAEd,KAAK,MAAM,UAAU,IAAI,iBAAiB,EAAE,CAAC;YAC3C,IAAI,UAAU,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;gBAC/B,MAAM,IAAI,GAAG,CAAA;gBACb,SAAS,GAAG,UAAU,CAAC,CAAC,CAAA;YAC1B,CAAC;YAED,kBAAkB,CAAC,IAAI,CAAC;gBACtB,CAAC,EAAE,UAAU,CAAC,CAAC;gBACf,CAAC,EAAE,UAAU,CAAC,CAAC;gBACf,MAAM;aACP,CAAC,CAAA;QACJ,CAAC;QAED,OAAO,kBAAkB,CAAA;IAC3B,CAAC;CACF"}
|
|
@@ -8,7 +8,7 @@ import type { GridOrientation } from './orientation.js';
|
|
|
8
8
|
* in a two-dimensional coordinate system such as SVG.
|
|
9
9
|
*/
|
|
10
10
|
export declare class CoordinatePositioner {
|
|
11
|
-
private
|
|
11
|
+
#private;
|
|
12
12
|
/**
|
|
13
13
|
* Creates a new coordinate positioner.
|
|
14
14
|
*
|
|
@@ -29,21 +29,5 @@ export declare class CoordinatePositioner {
|
|
|
29
29
|
* @returns The calculated center point.
|
|
30
30
|
*/
|
|
31
31
|
getCenterPosition(coordinate: Coordinate, dimension: number): Point;
|
|
32
|
-
/**
|
|
33
|
-
* Calculates the center position in an x-dominated grid.
|
|
34
|
-
*
|
|
35
|
-
* @param coordinate - The Midgard coordinate to position.
|
|
36
|
-
* @param width - The complete width of one hexagon.
|
|
37
|
-
* @returns The calculated center point.
|
|
38
|
-
*/
|
|
39
|
-
getXDominatedCenterPosition(coordinate: Coordinate, width: number): Point;
|
|
40
|
-
/**
|
|
41
|
-
* Calculates the center position in a y-dominated grid.
|
|
42
|
-
*
|
|
43
|
-
* @param coordinate - The Midgard coordinate to position.
|
|
44
|
-
* @param height - The complete height of one hexagon.
|
|
45
|
-
* @returns The calculated center point.
|
|
46
|
-
*/
|
|
47
|
-
getYDominatedCenterPosition(coordinate: Coordinate, height: number): Point;
|
|
48
32
|
}
|
|
49
33
|
//# sourceMappingURL=coordinate-positioner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate-positioner.d.ts","sourceRoot":"","sources":["../src/coordinate-positioner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAEvD;;;;;GAKG;AACH,qBAAa,oBAAoB
|
|
1
|
+
{"version":3,"file":"coordinate-positioner.d.ts","sourceRoot":"","sources":["../src/coordinate-positioner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAEvD;;;;;GAKG;AACH,qBAAa,oBAAoB;;IAI/B;;;;OAIG;IACH,YAAY,WAAW,EAAE,eAAe,EAIvC;IAED;;;;;;;;;;;;OAYG;IACI,iBAAiB,CACtB,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,MAAM,GAChB,KAAK,CAgBP;CAwDF"}
|
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
* in a two-dimensional coordinate system such as SVG.
|
|
6
6
|
*/
|
|
7
7
|
export class CoordinatePositioner {
|
|
8
|
-
orientation;
|
|
8
|
+
#orientation;
|
|
9
9
|
/**
|
|
10
10
|
* Creates a new coordinate positioner.
|
|
11
11
|
*
|
|
12
12
|
* @param orientation - The orientation of the hex grid.
|
|
13
13
|
*/
|
|
14
14
|
constructor(orientation) {
|
|
15
|
-
this
|
|
15
|
+
this.#orientation = orientation;
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Calculates the center position of a Midgard coordinate.
|
|
@@ -28,10 +28,10 @@ export class CoordinatePositioner {
|
|
|
28
28
|
* @returns The calculated center point.
|
|
29
29
|
*/
|
|
30
30
|
getCenterPosition(coordinate, dimension) {
|
|
31
|
-
if (this
|
|
32
|
-
return this
|
|
31
|
+
if (this.#orientation === 'x-dominated') {
|
|
32
|
+
return this.#getXDominatedCenterPosition(coordinate, dimension);
|
|
33
33
|
}
|
|
34
|
-
return this
|
|
34
|
+
return this.#getYDominatedCenterPosition(coordinate, dimension);
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Calculates the center position in an x-dominated grid.
|
|
@@ -40,7 +40,7 @@ export class CoordinatePositioner {
|
|
|
40
40
|
* @param width - The complete width of one hexagon.
|
|
41
41
|
* @returns The calculated center point.
|
|
42
42
|
*/
|
|
43
|
-
getXDominatedCenterPosition(coordinate, width) {
|
|
43
|
+
#getXDominatedCenterPosition(coordinate, width) {
|
|
44
44
|
const hexagonHeight = (width * 2) / Math.sqrt(3);
|
|
45
45
|
const xStep = width / 2;
|
|
46
46
|
const yStep = (hexagonHeight * 3) / 4;
|
|
@@ -56,7 +56,7 @@ export class CoordinatePositioner {
|
|
|
56
56
|
* @param height - The complete height of one hexagon.
|
|
57
57
|
* @returns The calculated center point.
|
|
58
58
|
*/
|
|
59
|
-
getYDominatedCenterPosition(coordinate, height) {
|
|
59
|
+
#getYDominatedCenterPosition(coordinate, height) {
|
|
60
60
|
const hexagonWidth = (height * 2) / Math.sqrt(3);
|
|
61
61
|
const xStep = (hexagonWidth * 3) / 4;
|
|
62
62
|
const yStep = height / 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate-positioner.js","sourceRoot":"","sources":["../src/coordinate-positioner.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;
|
|
1
|
+
{"version":3,"file":"coordinate-positioner.js","sourceRoot":"","sources":["../src/coordinate-positioner.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IAEtB,YAAY,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oordinateRange } from './coordinate-range.js';
|
|
|
10
10
|
* around every skeleton coordinate are also included.
|
|
11
11
|
*/
|
|
12
12
|
export declare class CoordinateRangeFiller {
|
|
13
|
-
private
|
|
13
|
+
#private;
|
|
14
14
|
/**
|
|
15
15
|
* Creates a new coordinate range filler.
|
|
16
16
|
*
|
|
17
17
|
* @param range - The coordinate range to fill.
|
|
18
18
|
*/
|
|
19
19
|
constructor(range: CoordinateRange);
|
|
20
|
-
/**
|
|
21
|
-
* Returns the coordinates surrounding one skeleton coordinate.
|
|
22
|
-
*
|
|
23
|
-
* The surrounding coordinates use the orientation
|
|
24
|
-
* of this coordinate range.
|
|
25
|
-
*
|
|
26
|
-
* @param coordinate - The skeleton coordinate.
|
|
27
|
-
* @returns The six neighbouring coordinates.
|
|
28
|
-
*/
|
|
29
|
-
getCoordinatesAround(coordinate: Coordinate): Coordinate[];
|
|
30
|
-
/**
|
|
31
|
-
* Checks whether a coordinate already exists
|
|
32
|
-
* in a list of coordinates.
|
|
33
|
-
*
|
|
34
|
-
* @param coordinates - The coordinates to search.
|
|
35
|
-
* @param coordinate - The coordinate to look for.
|
|
36
|
-
* @returns True if the coordinate already exists.
|
|
37
|
-
*/
|
|
38
|
-
containsCoordinate(coordinates: Coordinate[], coordinate: Coordinate): boolean;
|
|
39
20
|
/**
|
|
40
21
|
* Creates all coordinates belonging to this
|
|
41
22
|
* Midgard coordinate range.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate-range-fill.d.ts","sourceRoot":"","sources":["../src/coordinate-range-fill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAIjD,OAAO,KAAK,EACV,sBAAsB,EACvB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,eAAe,EAChB,MAAM,uBAAuB,CAAA;AAE9B;;;;;;;GAOG;AACH,qBAAa,qBAAqB
|
|
1
|
+
{"version":3,"file":"coordinate-range-fill.d.ts","sourceRoot":"","sources":["../src/coordinate-range-fill.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAIjD,OAAO,KAAK,EACV,sBAAsB,EACvB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,eAAe,EAChB,MAAM,uBAAuB,CAAA;AAE9B;;;;;;;GAOG;AACH,qBAAa,qBAAqB;;IAIhC;;;;OAIG;IACH,YAAY,KAAK,EAAE,eAAe,EAIjC;IA2CD;;;;;;;;;;;;OAYG;IACH,kBAAkB,CAChB,OAAO,GAAE,sBAA2B,GACnC,UAAU,EAAE,CA0Bd;CACF"}
|
|
@@ -9,14 +9,17 @@ import { CoordinateRange } from './coordinate-range.js';
|
|
|
9
9
|
* around every skeleton coordinate are also included.
|
|
10
10
|
*/
|
|
11
11
|
export class CoordinateRangeFiller {
|
|
12
|
-
range;
|
|
12
|
+
#range;
|
|
13
|
+
#neighbourCalculator;
|
|
13
14
|
/**
|
|
14
15
|
* Creates a new coordinate range filler.
|
|
15
16
|
*
|
|
16
17
|
* @param range - The coordinate range to fill.
|
|
17
18
|
*/
|
|
18
19
|
constructor(range) {
|
|
19
|
-
this
|
|
20
|
+
this.#range = range;
|
|
21
|
+
this.#neighbourCalculator =
|
|
22
|
+
new NeighbourCalculator(range.getOrientation());
|
|
20
23
|
}
|
|
21
24
|
/**
|
|
22
25
|
* Returns the coordinates surrounding one skeleton coordinate.
|
|
@@ -27,9 +30,8 @@ export class CoordinateRangeFiller {
|
|
|
27
30
|
* @param coordinate - The skeleton coordinate.
|
|
28
31
|
* @returns The six neighbouring coordinates.
|
|
29
32
|
*/
|
|
30
|
-
getCoordinatesAround(coordinate) {
|
|
31
|
-
|
|
32
|
-
return neighbourCalculator.getNeighbours(coordinate);
|
|
33
|
+
#getCoordinatesAround(coordinate) {
|
|
34
|
+
return this.#neighbourCalculator.getNeighbours(coordinate);
|
|
33
35
|
}
|
|
34
36
|
/**
|
|
35
37
|
* Checks whether a coordinate already exists
|
|
@@ -39,7 +41,7 @@ export class CoordinateRangeFiller {
|
|
|
39
41
|
* @param coordinate - The coordinate to look for.
|
|
40
42
|
* @returns True if the coordinate already exists.
|
|
41
43
|
*/
|
|
42
|
-
containsCoordinate(coordinates, coordinate) {
|
|
44
|
+
#containsCoordinate(coordinates, coordinate) {
|
|
43
45
|
for (const existingCoordinate of coordinates) {
|
|
44
46
|
if (existingCoordinate.x === coordinate.x &&
|
|
45
47
|
existingCoordinate.y === coordinate.y) {
|
|
@@ -62,15 +64,15 @@ export class CoordinateRangeFiller {
|
|
|
62
64
|
* @returns All coordinates belonging to the range.
|
|
63
65
|
*/
|
|
64
66
|
getCoordinateRange(options = {}) {
|
|
65
|
-
const skeleton = this
|
|
66
|
-
if (!this
|
|
67
|
+
const skeleton = this.#range.getSkeleton();
|
|
68
|
+
if (!this.#range.shouldFillAround(options)) {
|
|
67
69
|
return skeleton;
|
|
68
70
|
}
|
|
69
71
|
const coordinates = [...skeleton];
|
|
70
72
|
for (const skeletonCoordinate of skeleton) {
|
|
71
|
-
const surroundingCoordinates = this
|
|
73
|
+
const surroundingCoordinates = this.#getCoordinatesAround(skeletonCoordinate);
|
|
72
74
|
for (const surroundingCoordinate of surroundingCoordinates) {
|
|
73
|
-
if (!this
|
|
75
|
+
if (!this.#containsCoordinate(coordinates, surroundingCoordinate)) {
|
|
74
76
|
coordinates.push(surroundingCoordinate);
|
|
75
77
|
}
|
|
76
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate-range-fill.js","sourceRoot":"","sources":["../src/coordinate-range-fill.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAMrD,OAAO,EACL,eAAe,EAChB,MAAM,uBAAuB,CAAA;AAE9B;;;;;;;GAOG;AACH,MAAM,OAAO,qBAAqB;
|
|
1
|
+
{"version":3,"file":"coordinate-range-fill.js","sourceRoot":"","sources":["../src/coordinate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AqB,CAAC,kBAAkB,CAAC,CAAA;YAEhD,KAAK,MAAM,qBAAqB,IAAI,sBAAsB,EAAE,CAAC;gBAC3D,IACE,CAAC,IAAI,CAAC,mBAAmB,CACvB,WAAW,EACX,qBAAqB,CACtB,EACD,CAAC;oBACD,WAAW,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAA;gBACzC,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAA;IACpB,CAAC;CACF"}
|
|
@@ -24,25 +24,34 @@ export type CoordinateRangeOptions = {
|
|
|
24
24
|
* Represents a rectangular skeleton of a Midgard hex grid area.
|
|
25
25
|
*
|
|
26
26
|
* Every skeleton starts at Midgard coordinate (2, 2).
|
|
27
|
-
* The
|
|
27
|
+
* The dimensions and orientation cannot change after construction.
|
|
28
28
|
*/
|
|
29
29
|
export declare class CoordinateRange {
|
|
30
|
-
|
|
31
|
-
readonly height: number;
|
|
32
|
-
readonly orientation: GridOrientation;
|
|
30
|
+
#private;
|
|
33
31
|
/**
|
|
34
32
|
* Creates a new Midgard coordinate range.
|
|
35
33
|
*
|
|
34
|
+
* Invalid dimensions are rejected before the object is created.
|
|
35
|
+
*
|
|
36
36
|
* @param config - The values describing the coordinate range.
|
|
37
|
+
* @throws RangeError If width or height is not a positive integer.
|
|
37
38
|
*/
|
|
38
39
|
constructor(config: CoordinateRangeConfig);
|
|
40
|
+
/**
|
|
41
|
+
* Returns the orientation of this coordinate range.
|
|
42
|
+
*
|
|
43
|
+
* The orientation is fixed during construction.
|
|
44
|
+
*
|
|
45
|
+
* @returns The coordinate range orientation.
|
|
46
|
+
*/
|
|
47
|
+
getOrientation(): GridOrientation;
|
|
39
48
|
/**
|
|
40
49
|
* Checks whether this coordinate range has valid dimensions.
|
|
41
50
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
51
|
+
* The constructor guarantees valid dimensions.
|
|
52
|
+
* This method is retained for compatibility.
|
|
44
53
|
*
|
|
45
|
-
* @returns True
|
|
54
|
+
* @returns True for every successfully constructed range.
|
|
46
55
|
*/
|
|
47
56
|
isValid(): boolean;
|
|
48
57
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate-range.d.ts","sourceRoot":"","sources":["../src/coordinate-range.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAQvD;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,eAAe,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAED;;;;;GAKG;AACH,qBAAa,eAAe;
|
|
1
|
+
{"version":3,"file":"coordinate-range.d.ts","sourceRoot":"","sources":["../src/coordinate-range.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAQvD;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,eAAe,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAED;;;;;GAKG;AACH,qBAAa,eAAe;;IAQ1B;;;;;;;OAOG;IACH,YAAY,MAAM,EAAE,qBAAqB,EAgBxC;IAED;;;;;;OAMG;IACH,cAAc,IAAI,eAAe,CAIhC;IAED;;;;;;;OAOG;IACH,OAAO,IAAI,OAAO,CASjB;IAED;;;;;;;OAOG;IACH,WAAW,IAAI,UAAU,EAAE,CAS1B;IAED;;;;;;;;;OASG;IACH,gBAAgB,CACd,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAUT;CAEF"}
|
package/dist/coordinate-range.js
CHANGED
|
@@ -5,33 +5,50 @@ import { CoordinateRangeFillAround } from './c-r-fill-around.js';
|
|
|
5
5
|
* Represents a rectangular skeleton of a Midgard hex grid area.
|
|
6
6
|
*
|
|
7
7
|
* Every skeleton starts at Midgard coordinate (2, 2).
|
|
8
|
-
* The
|
|
8
|
+
* The dimensions and orientation cannot change after construction.
|
|
9
9
|
*/
|
|
10
10
|
export class CoordinateRange {
|
|
11
|
-
width;
|
|
12
|
-
height;
|
|
13
|
-
orientation;
|
|
11
|
+
#width;
|
|
12
|
+
#height;
|
|
13
|
+
#orientation;
|
|
14
14
|
/**
|
|
15
15
|
* Creates a new Midgard coordinate range.
|
|
16
16
|
*
|
|
17
|
+
* Invalid dimensions are rejected before the object is created.
|
|
18
|
+
*
|
|
17
19
|
* @param config - The values describing the coordinate range.
|
|
20
|
+
* @throws RangeError If width or height is not a positive integer.
|
|
18
21
|
*/
|
|
19
22
|
constructor(config) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
const validator = new CoordinateRangeValidator();
|
|
24
|
+
if (!validator.isValid(config.width, config.height)) {
|
|
25
|
+
throw new RangeError('Coordinate range width and height must be positive integers.');
|
|
26
|
+
}
|
|
27
|
+
this.#width = config.width;
|
|
28
|
+
this.#height = config.height;
|
|
29
|
+
this.#orientation = config.orientation;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns the orientation of this coordinate range.
|
|
33
|
+
*
|
|
34
|
+
* The orientation is fixed during construction.
|
|
35
|
+
*
|
|
36
|
+
* @returns The coordinate range orientation.
|
|
37
|
+
*/
|
|
38
|
+
getOrientation() {
|
|
39
|
+
return this.#orientation;
|
|
23
40
|
}
|
|
24
41
|
/**
|
|
25
42
|
* Checks whether this coordinate range has valid dimensions.
|
|
26
43
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
44
|
+
* The constructor guarantees valid dimensions.
|
|
45
|
+
* This method is retained for compatibility.
|
|
29
46
|
*
|
|
30
|
-
* @returns True
|
|
47
|
+
* @returns True for every successfully constructed range.
|
|
31
48
|
*/
|
|
32
49
|
isValid() {
|
|
33
50
|
const validator = new CoordinateRangeValidator();
|
|
34
|
-
return validator.isValid(this
|
|
51
|
+
return validator.isValid(this.#width, this.#height);
|
|
35
52
|
}
|
|
36
53
|
/**
|
|
37
54
|
* Creates the skeleton coordinates for this range.
|
|
@@ -43,7 +60,7 @@ export class CoordinateRange {
|
|
|
43
60
|
*/
|
|
44
61
|
getSkeleton() {
|
|
45
62
|
const skeleton = new CoordinateRangeSkeleton();
|
|
46
|
-
return skeleton.create(this
|
|
63
|
+
return skeleton.create(this.#width, this.#height);
|
|
47
64
|
}
|
|
48
65
|
/**
|
|
49
66
|
* Determines whether this range should be filled
|
|
@@ -57,7 +74,7 @@ export class CoordinateRange {
|
|
|
57
74
|
*/
|
|
58
75
|
shouldFillAround(options = {}) {
|
|
59
76
|
const fillAround = new CoordinateRangeFillAround();
|
|
60
|
-
return fillAround.shouldFillAround(this
|
|
77
|
+
return fillAround.shouldFillAround(this.#width, this.#height, options.fillAround);
|
|
61
78
|
}
|
|
62
79
|
}
|
|
63
80
|
//# sourceMappingURL=coordinate-range.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordinate-range.js","sourceRoot":"","sources":["../src/coordinate-range.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAE3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAE9D,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAwBhE;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAEjB,
|
|
1
|
+
{"version":3,"file":"coordinate-range.js","sourceRoot":"","sources":["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M,UAAU,GAAG,IAAI,yBAAyB,EAAE,CAAA;QAElD,OAAO,UAAU,CAAC,gBAAgB,CAChC,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,EACZ,OAAO,CAAC,UAAU,CACnB,CAAA;IAEH,CAAC;CAEF"}
|
package/dist/geometry.d.ts
CHANGED
|
@@ -19,37 +19,13 @@ export type Point = {
|
|
|
19
19
|
* of a hexagon represents its width or height.
|
|
20
20
|
*/
|
|
21
21
|
export declare class HexagonGeometry {
|
|
22
|
-
private
|
|
22
|
+
#private;
|
|
23
23
|
/**
|
|
24
24
|
* Creates a new hexagon geometry calculator.
|
|
25
25
|
*
|
|
26
26
|
* @param orientation - The orientation of the hex grid.
|
|
27
27
|
*/
|
|
28
28
|
constructor(orientation: GridOrientation);
|
|
29
|
-
/**
|
|
30
|
-
* Calculates the six corner points
|
|
31
|
-
* of an x-dominated hexagon.
|
|
32
|
-
*
|
|
33
|
-
* The width represents the complete horizontal width
|
|
34
|
-
* of the hexagon.
|
|
35
|
-
*
|
|
36
|
-
* @param center - The center point of the hexagon.
|
|
37
|
-
* @param width - The complete width of the hexagon.
|
|
38
|
-
* @returns The six corner points of the hexagon.
|
|
39
|
-
*/
|
|
40
|
-
getXDominatedHexagonPoints(center: Point, width: number): Point[];
|
|
41
|
-
/**
|
|
42
|
-
* Calculates the six corner points
|
|
43
|
-
* of a y-dominated hexagon.
|
|
44
|
-
*
|
|
45
|
-
* The height represents the complete vertical height
|
|
46
|
-
* of the hexagon.
|
|
47
|
-
*
|
|
48
|
-
* @param center - The center point of the hexagon.
|
|
49
|
-
* @param height - The complete height of the hexagon.
|
|
50
|
-
* @returns The six corner points of the hexagon.
|
|
51
|
-
*/
|
|
52
|
-
getYDominatedHexagonPoints(center: Point, height: number): Point[];
|
|
53
29
|
/**
|
|
54
30
|
* Calculates the six corner points of a hexagon
|
|
55
31
|
* using this geometry's grid orientation.
|
package/dist/geometry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C,YAAY,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAY3C;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV,CAAA;AAED;;;;;;GAMG;AACH,qBAAa,eAAe
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C,YAAY,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAY3C;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV,CAAA;AAED;;;;;;GAMG;AACH,qBAAa,eAAe;;IAG1B;;;;OAIG;IACH,YAAY,WAAW,EAAE,eAAe,EAEvC;IAgDD;;;;;;;;;;OAUG;IACH,gBAAgB,CACd,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,MAAM,GAChB,KAAK,EAAE,CAYT;IAED;;;;;OAKG;IACH,SAAS,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAIjC;CACF"}
|
package/dist/geometry.js
CHANGED
|
@@ -9,14 +9,14 @@ import { YDominatedHexagonGeometry } from './g-y-dominated.js';
|
|
|
9
9
|
* of a hexagon represents its width or height.
|
|
10
10
|
*/
|
|
11
11
|
export class HexagonGeometry {
|
|
12
|
-
orientation;
|
|
12
|
+
#orientation;
|
|
13
13
|
/**
|
|
14
14
|
* Creates a new hexagon geometry calculator.
|
|
15
15
|
*
|
|
16
16
|
* @param orientation - The orientation of the hex grid.
|
|
17
17
|
*/
|
|
18
18
|
constructor(orientation) {
|
|
19
|
-
this
|
|
19
|
+
this.#orientation = orientation;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Calculates the six corner points
|
|
@@ -29,7 +29,7 @@ export class HexagonGeometry {
|
|
|
29
29
|
* @param width - The complete width of the hexagon.
|
|
30
30
|
* @returns The six corner points of the hexagon.
|
|
31
31
|
*/
|
|
32
|
-
getXDominatedHexagonPoints(center, width) {
|
|
32
|
+
#getXDominatedHexagonPoints(center, width) {
|
|
33
33
|
const geometry = new XDominatedHexagonGeometry();
|
|
34
34
|
return geometry.getHexagonPoints(center, width);
|
|
35
35
|
}
|
|
@@ -44,7 +44,7 @@ export class HexagonGeometry {
|
|
|
44
44
|
* @param height - The complete height of the hexagon.
|
|
45
45
|
* @returns The six corner points of the hexagon.
|
|
46
46
|
*/
|
|
47
|
-
getYDominatedHexagonPoints(center, height) {
|
|
47
|
+
#getYDominatedHexagonPoints(center, height) {
|
|
48
48
|
const geometry = new YDominatedHexagonGeometry();
|
|
49
49
|
return geometry.getHexagonPoints(center, height);
|
|
50
50
|
}
|
|
@@ -60,10 +60,10 @@ export class HexagonGeometry {
|
|
|
60
60
|
* @returns The six corner points of the hexagon.
|
|
61
61
|
*/
|
|
62
62
|
getHexagonPoints(center, dimension) {
|
|
63
|
-
if (this
|
|
64
|
-
return this
|
|
63
|
+
if (this.#orientation === 'x-dominated') {
|
|
64
|
+
return this.#getXDominatedHexagonPoints(center, dimension);
|
|
65
65
|
}
|
|
66
|
-
return this
|
|
66
|
+
return this.#getYDominatedHexagonPoints(center, dimension);
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Calculates the outer bounds of geometric points.
|
package/dist/geometry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.js","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,EACL,yBAAyB,EAC1B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,yBAAyB,EAC1B,MAAM,oBAAoB,CAAA;AAa3B;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;
|
|
1
|
+
{"version":3,"file":"geometry.js","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAEhD,OAAO,EACL,yBAAyB,EAC1B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACL,yBAAyB,EAC1B,MAAM,oBAAoB,CAAA;AAa3B;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;IACjB,YAAY,CAAiB;IAEtC;;;;OAIG;IACH,YAAY,WAA4B;QACtC,IAAI,CAAC,YAAY,GAAG,WAAW,CAAA;IACjC,CAAC;IAED;;;;;;;;;;OAUG;IACH,2BAA2B,CACzB,MAAa,EACb,KAAa;QAEb,MAAM,QAAQ,GAAG,IAAI,yBAAyB,EAAE,CAAA;QAEhD,OAAO,QAAQ,CAAC,gBAAgB,CAC9B,MAAM,EACN,KAAK,CACN,CAAA;IACH,CAAC;IAED;;;;;;;;;;OAUG;IACH,2BAA2B,CACzB,MAAa,EACb,MAAc;QAEd,MAAM,QAAQ,GAAG,IAAI,yBAAyB,EAAE,CAAA;QAEhD,OAAO,QAAQ,CAAC,gBAAgB,CAC9B,MAAM,EACN,MAAM,CACP,CAAA;IACH,CAAC;IAED;;;;;;;;;;OAUG;IACH,gBAAgB,CACd,MAAa,EACb,SAAiB;QAEjB,IAAI,IAAI,CAAC,YAAY,KAAK,aAAa,EAAE,CAAC;YACxC,OAAO,IAAI,CAAC,2BAA2B,CACrC,MAAM,EACN,SAAS,CACV,CAAA;QACH,CAAC;QAED,OAAO,IAAI,CAAC,2BAA2B,CACrC,MAAM,EACN,SAAS,CACV,CAAA;IACH,CAAC;IAED;;;;;OAKG;IACH,SAAS,CAAC,MAAe;QACvB,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAA;QAE/C,OAAO,gBAAgB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IAC3C,CAAC;CACF"}
|
package/dist/h-g-bounds.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import type { Coordinate } from './coordinate.js';
|
|
2
|
-
import type { GridOrientation } from './orientation.js';
|
|
3
2
|
import type { Bounds } from './geometry.js';
|
|
3
|
+
import { HexagonGeometry } from './geometry.js';
|
|
4
|
+
import { CoordinatePositioner } from './coordinate-positioner.js';
|
|
4
5
|
/**
|
|
5
6
|
* Calculates the outer geometric bounds
|
|
6
7
|
* of hexagons in a Midgard grid.
|
|
7
8
|
*/
|
|
8
9
|
export declare class HexGridBoundsCalculator {
|
|
9
|
-
private
|
|
10
|
+
#private;
|
|
10
11
|
/**
|
|
11
|
-
* Creates a new grid bounds calculator
|
|
12
|
+
* Creates a new grid bounds calculator using existing
|
|
13
|
+
* geometric helper objects.
|
|
12
14
|
*
|
|
13
|
-
* @param
|
|
15
|
+
* @param positioner - Calculates hexagon center positions.
|
|
16
|
+
* @param geometry - Calculates hexagon corner points and bounds.
|
|
14
17
|
*/
|
|
15
|
-
constructor(
|
|
18
|
+
constructor(positioner: CoordinatePositioner, geometry: HexagonGeometry);
|
|
16
19
|
/**
|
|
17
20
|
* Calculates the outer geometric bounds of hexagons
|
|
18
21
|
* represented by Midgard coordinates.
|
package/dist/h-g-bounds.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"h-g-bounds.d.ts","sourceRoot":"","sources":["../src/h-g-bounds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"h-g-bounds.d.ts","sourceRoot":"","sources":["../src/h-g-bounds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EACV,MAAM,EAEP,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAEjE;;;GAGG;AACH,qBAAa,uBAAuB;;IAIlC;;;;;;OAMG;IACH,YACE,UAAU,EAAE,oBAAoB,EAChC,QAAQ,EAAE,eAAe,EAI1B;IAED;;;;;;;OAOG;IACH,aAAa,CACX,WAAW,EAAE,UAAU,EAAE,EACzB,IAAI,EAAE,MAAM,GACX,MAAM,CAmBR;CACF"}
|
package/dist/h-g-bounds.js
CHANGED
|
@@ -5,14 +5,18 @@ import { CoordinatePositioner } from './coordinate-positioner.js';
|
|
|
5
5
|
* of hexagons in a Midgard grid.
|
|
6
6
|
*/
|
|
7
7
|
export class HexGridBoundsCalculator {
|
|
8
|
-
|
|
8
|
+
#positioner;
|
|
9
|
+
#geometry;
|
|
9
10
|
/**
|
|
10
|
-
* Creates a new grid bounds calculator
|
|
11
|
+
* Creates a new grid bounds calculator using existing
|
|
12
|
+
* geometric helper objects.
|
|
11
13
|
*
|
|
12
|
-
* @param
|
|
14
|
+
* @param positioner - Calculates hexagon center positions.
|
|
15
|
+
* @param geometry - Calculates hexagon corner points and bounds.
|
|
13
16
|
*/
|
|
14
|
-
constructor(
|
|
15
|
-
this
|
|
17
|
+
constructor(positioner, geometry) {
|
|
18
|
+
this.#positioner = positioner;
|
|
19
|
+
this.#geometry = geometry;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
22
|
* Calculates the outer geometric bounds of hexagons
|
|
@@ -23,15 +27,13 @@ export class HexGridBoundsCalculator {
|
|
|
23
27
|
* @returns The outer bounds of all hexagons.
|
|
24
28
|
*/
|
|
25
29
|
getGridBounds(coordinates, size) {
|
|
26
|
-
const geometry = new HexagonGeometry(this.orientation);
|
|
27
|
-
const positioner = new CoordinatePositioner(this.orientation);
|
|
28
30
|
const points = [];
|
|
29
31
|
for (const coordinate of coordinates) {
|
|
30
|
-
const center = positioner.getCenterPosition(coordinate, size);
|
|
31
|
-
const hexagonPoints = geometry.getHexagonPoints(center, size);
|
|
32
|
+
const center = this.#positioner.getCenterPosition(coordinate, size);
|
|
33
|
+
const hexagonPoints = this.#geometry.getHexagonPoints(center, size);
|
|
32
34
|
points.push(...hexagonPoints);
|
|
33
35
|
}
|
|
34
|
-
return geometry.getBounds(points);
|
|
36
|
+
return this.#geometry.getBounds(points);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
//# sourceMappingURL=h-g-bounds.js.map
|
package/dist/h-g-bounds.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"h-g-bounds.js","sourceRoot":"","sources":["../src/h-g-bounds.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"h-g-bounds.js","sourceRoot":"","sources":["../src/h-g-bounds.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAE/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAEjE;;;GAGG;AACH,MAAM,OAAO,uBAAuB;IACzB,WAAW,CAAsB;IACjC,SAAS,CAAiB;IAEnC;;;;;;OAMG;IACH,YACE,UAAgC,EAChC,QAAyB;QAEzB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAA;QAC7B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAA;IAC3B,CAAC;IAED;;;;;;;OAOG;IACH,aAAa,CACX,WAAyB,EACzB,IAAY;QAEZ,MAAM,MAAM,GAAY,EAAE,CAAA;QAE1B,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACrC,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAC/C,UAAU,EACV,IAAI,CACL,CAAA;YAED,MAAM,aAAa,GACjB,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAC7B,MAAM,EACN,IAAI,CACL,CAAA;YAEH,MAAM,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAA;QAC/B,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;CACF"}
|