Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgaya committed Oct 4, 2024
1 parent e528abf commit 944e71a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,31 +82,31 @@ function geometryToCells(geometry: GeoJSONGeometry, resolution: bigint): bigint
## cellToBoundary

```javascript
function cellToBoundary(quadbin: bigint): Polygon
function cellToBoundary(quadbin: Quadbin): Polygon
```

Converts a Quadbin cell identifier into a geographical boundary represented as a polygon

## quadbinToOffset
## cellToOffset

```javascript
function quadbinToOffset(quadbin: bigint): [number, number, number]
function cellToOffset(quadbin: Quadbin): [number, number, number]
```

Converts a Quadbin cell identifier into world coordinates offset values

## quadbinToWorldBounds
## cellToWorldBounds

```javascript
function quadbinToWorldBounds(quadbin: bigint, coverage: number): [number[], number[]]
function cellToWorldBounds(quadbin: Quadbin, coverage: number): [number[], number[]]
```

Computes the world bounds (in Web Mercator coordinates) for a given Quadbin cell, taking into account the cell's coverage area

## getQuadbinPolygon
## getCellPolygon

```javascript
function getQuadbinPolygon(quadbin: bigint, coverage = 1): number[]
function getCellPolygon(quadbin: Quadbin, coverage = 1): number[]
```

Generates the geographical polygon (in longitude and latitude) that represents the boundaries of a Quadbin cell, optionally taking into account coverage
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ type Tile = {x: number; y: number; z: number};

const TILE_SIZE = 512;

export function quadbinToOffset(quadbin: bigint): [number, number, number] {
export function cellToOffset(quadbin: Quadbin): [number, number, number] {
const {x, y, z} = cellToTile(quadbin);
const scale = TILE_SIZE / (1 << z);
return [x * scale, TILE_SIZE - y * scale, scale];
}

export function quadbinToWorldBounds(quadbin: bigint, coverage: number): [number[], number[]] {
const [xOffset, yOffset, scale] = quadbinToOffset(quadbin);
export function cellToWorldBounds(quadbin: Quadbin, coverage: number): [number[], number[]] {
const [xOffset, yOffset, scale] = cellToOffset(quadbin);
return [
[xOffset, yOffset],
[xOffset + coverage * scale, yOffset - coverage * scale]
];
}

export function getQuadbinPolygon(quadbin: bigint, coverage = 1): number[] {
const [topLeft, bottomRight] = quadbinToWorldBounds(quadbin, coverage);
export function getCellPolygon(quadbin: Quadbin, coverage = 1): number[] {
const [topLeft, bottomRight] = cellToWorldBounds(quadbin, coverage);
const [w, n] = worldToLngLat(topLeft);
const [e, s] = worldToLngLat(bottomRight);
return [e, n, e, s, w, s, w, n, e, n];
Expand Down Expand Up @@ -115,8 +115,8 @@ export function geometryToCells(geometry, resolution: bigint): Quadbin[] {
}).map(([x, y, z]) => tileToCell({x, y, z}));
}

export function cellToBoundary(cell: bigint): Polygon {
const bbox = getQuadbinPolygon(cell);
export function cellToBoundary(cell: Quadbin): Polygon {
const bbox = getCellPolygon(cell);
const boundary = [
[bbox[0], bbox[1]],
[bbox[2], bbox[3]],
Expand Down

0 comments on commit 944e71a

Please sign in to comment.