Skip to content

Commit

Permalink
fix: move (internal) util to fix circular dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
flauwekeul committed Apr 22, 2021
1 parent f886f14 commit be57fee
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/grid/functions/distance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { HexCoordinates, HexPrototype } from '../../hex'
import { assertCubeCoordinates } from '../../utils'
import { assertCubeCoordinates, HexCoordinates, HexPrototype } from '../../hex'

export function distance(
hexPrototype: Pick<HexPrototype, 'offset' | 'isPointy'>,
Expand Down
3 changes: 1 addition & 2 deletions src/grid/traversers/ring.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Hex, HexCoordinates } from '../../hex'
import { assertCubeCoordinates } from '../../utils'
import { assertCubeCoordinates, Hex, HexCoordinates } from '../../hex'
import { distance } from '../functions'
import { Rotation, Traverser } from '../types'

Expand Down
15 changes: 15 additions & 0 deletions src/hex/functions/assertCubeCoordinates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { isOffset } from '../../utils/isOffset'
import { CubeCoordinates, HexCoordinates, HexPrototype } from '../types'
import { offsetToCube } from './offsetToCube'

/**
* Util for converting offset/axial/cube coordinates to cube coordinates. It's not placed in /src/utils because that causes circular dependencies.
* @private
*/
export function assertCubeCoordinates(
coordinates: HexCoordinates,
hexPrototype: Pick<HexPrototype, 'offset' | 'isPointy'>,
): CubeCoordinates {
const { q, r, s = -q - r } = isOffset(coordinates) ? offsetToCube(coordinates, hexPrototype) : coordinates
return { q, r, s }
}
1 change: 1 addition & 0 deletions src/hex/functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './assertCubeCoordinates'
export * from './center'
export * from './cloneHex'
export * from './corners'
Expand Down
10 changes: 0 additions & 10 deletions src/utils/assertCubeCoordinates.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './assertCubeCoordinates'
export * from './isAxial'
export * from './isFunction'
export * from './isObject'
Expand Down

0 comments on commit be57fee

Please sign in to comment.