Add isInteger coordinate utils
This commit is contained in:
@@ -4,7 +4,8 @@ import {
|
|||||||
findCoordsOfDigit,
|
findCoordsOfDigit,
|
||||||
getAdjacent,
|
getAdjacent,
|
||||||
inBounds,
|
inBounds,
|
||||||
isCoordinateEqual
|
isCoordinateEqual,
|
||||||
|
isInteger
|
||||||
} from './coordinates.ts';
|
} from './coordinates.ts';
|
||||||
|
|
||||||
describe('coordinates utils', () => {
|
describe('coordinates utils', () => {
|
||||||
@@ -101,4 +102,14 @@ describe('coordinates utils', () => {
|
|||||||
expect(actualSevenRegex[0]).toEqual([1, 2]);
|
expect(actualSevenRegex[0]).toEqual([1, 2]);
|
||||||
expect(actualSevenRegex[1]).toEqual([2, 3]);
|
expect(actualSevenRegex[1]).toEqual([2, 3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('isInteger', () => {
|
||||||
|
expect(isInteger([1, 2])).toBeTrue();
|
||||||
|
expect(isInteger([1, 2, 3])).toBeTrue();
|
||||||
|
expect(isInteger([0, 0])).toBeTrue();
|
||||||
|
expect(isInteger([0, 10.001])).toBeFalse();
|
||||||
|
expect(isInteger([472.2948292, 10.001])).toBeFalse();
|
||||||
|
expect(isInteger([-472.2948292, 10.001])).toBeFalse();
|
||||||
|
expect(isInteger([-472.2948292, -10.001])).toBeFalse();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,6 +36,14 @@ export function isCoordinateEqual(
|
|||||||
return b[0] === a[0] && b[1] === a[1];
|
return b[0] === a[0] && b[1] === a[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a xy-coordinate has integer coefficients.
|
||||||
|
* @param coordinate Coordinate
|
||||||
|
*/
|
||||||
|
export function isInteger(coordinate: Readonly<Coordinate | CoordinateSide>) {
|
||||||
|
return coordinate[0] % 1 === 0 && coordinate[1] % 1 === 0;
|
||||||
|
}
|
||||||
|
|
||||||
export type DirectNeighbours = 'top' | 'left' | 'right' | 'down';
|
export type DirectNeighbours = 'top' | 'left' | 'right' | 'down';
|
||||||
|
|
||||||
export type DiagonalNeighbours =
|
export type DiagonalNeighbours =
|
||||||
|
|||||||
Reference in New Issue
Block a user