Skip to content

Commit

Permalink
feat(types): introduce DoubleOf<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Dec 1, 2023
1 parent b4ef252 commit 0214f62
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/bin/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
SUPPORTED_DATA_FORMATS,
SUPPORTED_FORMATS,
} from '@bin/constants.js'
import { DoubleOf } from '@common/types.js'

export const getPackageVersion = async () => {
try {
Expand Down Expand Up @@ -78,7 +79,7 @@ const sliceBuffer = (buffer: string | Buffer, start?: number, end?: number) => {
}
}

export const evenAndRemainder = (divisor: number, n: number): [number, number] => {
export const evenAndRemainder = (divisor: number, n: number): DoubleOf<number> => {
return [Math.floor(n / divisor), n % divisor]
}

Expand Down
2 changes: 2 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export type ArxQuaternion = {
w: number
}

export type DoubleOf<T> = [T, T]

export type TripleOf<T> = [T, T, T]

export type QuadrupleOf<T> = [T, T, T, T]
Expand Down
4 changes: 2 additions & 2 deletions src/fts/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { any } from '@common/helpers.js'
import { QuadrupleOf, TripleOf } from '@common/types.js'
import { DoubleOf, QuadrupleOf, TripleOf } from '@common/types.js'
import { ArxPolygon, ArxPolygonFlags } from '@fts/Polygon.js'
import { ArxVertex } from '@fts/Vertex.js'
import { COORDS_THAT_ROUND_UP } from '@fts/constants.js'
Expand Down Expand Up @@ -31,7 +31,7 @@ const doCoordsNeedToBeRoundedUp = (coords: TripleOf<number>) => {
return any(([x, y, z]) => a === x && b === y && c === z, COORDS_THAT_ROUND_UP)
}

export const getCellCoords = ([a, b, c]: QuadrupleOf<ArxVertex>): [number, number] => {
export const getCellCoords = ([a, b, c]: QuadrupleOf<ArxVertex>): DoubleOf<number> => {
const x = (a.x + b.x + c.x) / 3
const z = (a.z + b.z + c.z) / 3

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { getCellCoords } from '@fts/helpers.js'

export type { TripleOf, QuadrupleOf, Optional, Expand, RecursiveExpand } from '@common/types.js'
export type { DoubleOf, TripleOf, QuadrupleOf, Optional, Expand, RecursiveExpand } from '@common/types.js'

export { MAP_WIDTH_IN_CELLS, MAP_DEPTH_IN_CELLS } from '@common/constants.js'

0 comments on commit 0214f62

Please sign in to comment.