Skip to content

Commit

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

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

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

## quadbinToOffset

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

Converts a Quadbin cell identifier into world coordinates offset values

## quadbinToWorldBounds

```javascript
function quadbinToWorldBounds(quadbin: bigint, 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

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

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

const TILE_SIZE = 512;

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

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

function getQuadbinPolygon(quadbin: bigint, coverage = 1): number[] {
export function getQuadbinPolygon(quadbin: bigint, coverage = 1): number[] {
const [topLeft, bottomRight] = quadbinToWorldBounds(quadbin, coverage);
const [w, n] = worldToLngLat(topLeft);
const [e, s] = worldToLngLat(bottomRight);
Expand Down

0 comments on commit e528abf

Please sign in to comment.