Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
- jsdoc
- removed unused method of point
- Point.isEqual renamed to Point.equals
- removed empty file
- type-check script added
  • Loading branch information
krutoo committed May 2, 2022
1 parent 3a94d17 commit e1634f2
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"build:before": "rm -rf dist",
"build:main": "tsc --project tsconfig.build.json",
"build": "npm run build:before && npm run build:main",
"type-check": "tsc -p . --noEmit",
"prepare": "husky install"
},
"devDependencies": {
Expand Down
Empty file removed src/dungeon/__index.ts
Empty file.
6 changes: 3 additions & 3 deletions src/dungeon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Dungeon {
private _options!: Required<DungeonOptions>;

/**
* @param [options={}] Options of dungeon.
* @param [options] Building options.
* @param [options.roomsAmount=7] Amount of rooms.
* @param [options.roomMinSize=5] Minimum room size.
* @param [options.roomMaxSize=10] Maximum room size.
Expand Down Expand Up @@ -149,8 +149,8 @@ export class Dungeon {

/**
* Calls callback for each tile in dungeon area.
* @param {Function} callback Callback that was called for each tile.
* @return {Dungeon} Instance.
* @param callback Callback that was called for each tile.
* @return Instance.
*/
forEachTile(callback: (x: number, n: number, isFloor: boolean) => void) {
const { width, height } = this;
Expand Down
8 changes: 4 additions & 4 deletions src/explorer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ interface PositionChecker {
}

export const createExplorer = (isTransparent: PositionChecker) => {
return (
return function explore(
centerX: number,
centerY: number,
radius: number,
handleExplored?: (x: number, y: number) => void,
) => {
) {
if (!Number.isFinite(centerX + centerY + radius)) {
throw TypeError('First three arguments (centerX, centerY, radius) must be finite numbers');
}

const checkedPoints = new Set();
const visiblePoints = [];
const visiblePoints: Array<{ x: number; y: number }> = [];
const hasExploredHandler = typeof handleExplored === 'function';
const squareRadius = radius ** 2;
const center = new Point(centerX, centerY);

// checking square area bounds
// define square area bounds
const minX = center.x - radius;
const maxX = center.x + radius;
const minY = center.y - radius;
Expand Down
4 changes: 2 additions & 2 deletions src/pathfinder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ export const createPathfinder = (
visitedNodes.push(currentNode);

// if current node is target then create path and break
if (Point.isEqual(currentNode, finish)) {
if (Point.equals(currentNode, finish)) {
resultPath = currentNode.createPathToRoot();
break;
}

const neighbors = getNeighbors(currentNode);

for (const neighbor of neighbors) {
const likeNeighbor = (p: Point) => Point.isEqual(p, neighbor);
const likeNeighbor = (p: Point) => Point.equals(p, neighbor);

// ignore neighbor node if it is already visited
if (visitedNodes.some(likeNeighbor)) {
Expand Down
11 changes: 1 addition & 10 deletions src/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,11 @@ export class Point {
this.y = y;
}

/**
* Returns a distance to a point.
* @param point Target point.
* @return Distance.
*/
getDistanceTo(point: Point) {
return Math.sqrt((point.x - this.x) ** 2 + (point.y - this.y) ** 2);
}

clone() {
return new Point(this.x, this.y);
}

static isEqual(a: Point, b: Point): boolean {
static equals(a: Point, b: Point): boolean {
return a && b && a.x === b.x && a.y === b.y;
}
}

0 comments on commit e1634f2

Please sign in to comment.