Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 44x 44x 6x 44x 44x 5x 44x 44x 44x 61x 44x 42x 44x 44x 4x 4x | import { NUM_SUBPIXEL_BITS, TILE_SIZE } from "consts";
import type { DistanceUnitType } from "shared/lib/entities/entitiesTypes";
export const tileToSubpx = (x: number) =>
Math.floor(x * (1 << (3 + NUM_SUBPIXEL_BITS)));
export const tileToPx = (x: number) => Math.floor(x * TILE_SIZE);
export const pxToSubpx = (x: number) =>
Math.floor(x * (1 << NUM_SUBPIXEL_BITS));
export const pxToSubpxVel = (x: number) => Math.floor(x * (1 << 4));
export const pxToSubpxVelPrecise = (x: number) =>
Math.floor(x * ((1 << 4) << 8));
export const subpxShiftForUnits = (units: DistanceUnitType) => {
return units === "tiles" ? NUM_SUBPIXEL_BITS + 3 : NUM_SUBPIXEL_BITS;
};
export const pxShiftForUnits = (units: DistanceUnitType) => {
return units === "tiles" ? 3 : 0;
};
export const subpxSnapMaskForUnits = (units: DistanceUnitType) => {
const bitsToClear =
units === "tiles"
? NUM_SUBPIXEL_BITS + 3 // 3 extra bits for 8px tiles
: NUM_SUBPIXEL_BITS;
return ~((1 << bitsToClear) - 1) & 0xffff;
};
export const unitsValueToSubpx = (x: number, units: DistanceUnitType) => {
if (units === "tiles") {
return tileToSubpx(x);
}
return pxToSubpx(x);
};
|