-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hex): use axial coordinates by default
Also add isAxial() util function and some more ideas to readme
- Loading branch information
1 parent
2c6687f
commit 775e711
Showing
8 changed files
with
24 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { CubeCoordinates, DefaultHexPrototype, Hex } from '../types' | ||
import { AxialCoordinates, CubeCoordinates, DefaultHexPrototype, Hex } from '../types' | ||
|
||
export const createHex = <T extends DefaultHexPrototype>(prototype: T, coordinates: CubeCoordinates) => | ||
Object.assign(Object.create(prototype), coordinates) as T extends Hex ? T : T & Hex | ||
export const createHex = <T extends DefaultHexPrototype>(prototype: T, { q, r }: AxialCoordinates | CubeCoordinates) => | ||
Object.assign(Object.create(prototype), { q, r }) as T extends Hex ? T : T & Hex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
export * from './isAxial' | ||
export * from './isCartesian' | ||
export * from './isCube' | ||
export * from './isFunction' | ||
export * from './isObject' | ||
export * from './offsetFromZero' | ||
export * from './signedModulo' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { AxialCoordinates } from '../hex' | ||
import { isObject } from './isObject' | ||
|
||
export const isAxial = (value: unknown): value is AxialCoordinates => | ||
isObject<AxialCoordinates>(value) && Number.isFinite(value.q) && Number.isFinite(value.r) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
// todo: this might be a redundant function | ||
export const signedModulo = (dividend: number, divisor: number) => ((dividend % divisor) + divisor) % divisor |