Skip to content

Commit

Permalink
Moved geo package to xylabs
Browse files Browse the repository at this point in the history
  • Loading branch information
arietrouw committed Jan 3, 2025
1 parent 70cebf5 commit dc3d78b
Show file tree
Hide file tree
Showing 25 changed files with 136 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ plugins:
- path: .yarn/plugins/@yarnpkg/plugin-outdated.cjs
spec: "https://mskelton.dev/yarn-outdated/v3"

yarnPath: .yarn/releases/yarn-4.5.3.cjs
yarnPath: .yarn/releases/yarn-4.6.0.cjs
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
"devDependencies": {
"@stylistic/eslint-plugin": "^2.12.1",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^8.18.1",
"@typescript-eslint/parser": "^8.18.1",
"@typescript-eslint/eslint-plugin": "^8.19.0",
"@typescript-eslint/parser": "^8.19.0",
"@xylabs/eslint-config-flat": "^4.2.6",
"@xylabs/forget": "^4.4.25",
"@xylabs/forget": "^4.4.34",
"@xylabs/ts-scripts-yarn3": "^4.2.6",
"@xylabs/tsconfig": "^4.2.6",
"dotenv": "^16.4.7",
Expand All @@ -60,7 +60,7 @@
"typescript": "^5.7.2",
"vitest": "^2.1.8"
},
"packageManager": "yarn@4.5.3",
"packageManager": "yarn@4.6.0",
"publishConfig": {
"access": "public"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/ethers-wrappers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"module": "dist/neutral/index.mjs",
"types": "dist/neutral/index.d.ts",
"dependencies": {
"@xylabs/assert": "^4.4.25",
"@xylabs/eth-address": "^4.4.25",
"@xylabs/assert": "^4.4.34",
"@xylabs/eth-address": "^4.4.34",
"@xyo-network/typechain": "^3.3.2",
"ethers": "^6.13.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"types": "dist/neutral/index.d.ts",
"dependencies": {
"geojson": "^0.5.0",
"mapbox-gl": "^3.9.0"
"mapbox-gl": "^3.9.1"
},
"devDependencies": {
"@xylabs/ts-scripts-yarn3": "^4.2.6",
Expand Down
5 changes: 2 additions & 3 deletions packages/geo/src/GeoJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
boundingBoxToCenter, boundingBoxToPolygon, tileFromQuadkey, tileToBoundingBox,
} from './mercator/index.ts'

class GeoJson {
/** @deprecated use form @xylabs/geo */
export class GeoJson {
private _lngLat?: MapBox.LngLat
private _point?: Point
private _polygon?: Polygon
Expand Down Expand Up @@ -100,5 +101,3 @@ class GeoJson {
return this._zoom
}
}

export { GeoJson }
1 change: 1 addition & 0 deletions packages/geo/src/LayerBase.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type MapBox from 'mapbox-gl'

/** @deprecated use form @xylabs/geo */
export abstract class LayerBase<T extends MapBox.Layer> {
id: string
source: string
Expand Down
1 change: 1 addition & 0 deletions packages/geo/src/mercator/boundingbox/to/boundary.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MercatorBoundary, MercatorBoundingBox } from '../../types.ts'

/** @deprecated use form @xylabs/geo */
export const boundingBoxToBoundary = (box: MercatorBoundingBox): MercatorBoundary => {
return [box.getNorthWest(), box.getNorthEast(), box.getSouthEast(), box.getSouthWest(), box.getNorthWest()]
}
1 change: 1 addition & 0 deletions packages/geo/src/mercator/boundingbox/to/center.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { MercatorBoundingBox } from '../../types.ts'

/** @deprecated use form @xylabs/geo */
export const boundingBoxToCenter = (boundingBox: MercatorBoundingBox, decimal = 6) => {
const west = boundingBox.getWest()
const south = boundingBox.getSouth()
Expand Down
1 change: 1 addition & 0 deletions packages/geo/src/mercator/boundingbox/to/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Polygon } from 'geojson'
import type { MercatorBoundingBox, MercatorLngLat } from '../../types.ts'
import { boundingBoxToBoundary } from './boundary.ts'

/** @deprecated use form @xylabs/geo */
export const boundingBoxToPolygon = (box: MercatorBoundingBox): Polygon => {
const boundry = boundingBoxToBoundary(box)
return {
Expand Down
7 changes: 4 additions & 3 deletions packages/geo/src/mercator/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const d2r = Math.PI / 180
const r2d = 180 / Math.PI
/** @deprecated use form @xylabs/geo */
export const d2r = Math.PI / 180

export { d2r, r2d }
/** @deprecated use form @xylabs/geo */
export const r2d = 180 / Math.PI
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tile/from/point.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const pointToTileFraction = (point: MercatorLngLat, z: number) => {
return [x, y, z]
}

const tileFromPoint = (point: MercatorLngLat, z: number) => {
/** @deprecated use form @xylabs/geo */
export const tileFromPoint = (point: MercatorLngLat, z: number) => {
const tile = pointToTileFraction(point, z)
tile[0] = Math.floor(tile[0])
tile[1] = Math.floor(tile[1])
Expand All @@ -25,5 +26,3 @@ const tileFromPoint = (point: MercatorLngLat, z: number) => {
}
return tile
}

export { tileFromPoint }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tile/from/quadkey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const tileFromQuadkey = (quadkey: string) => {
/** @deprecated use form @xylabs/geo */
export const tileFromQuadkey = (quadkey: string) => {
let x = 0
let y = 0
const z = quadkey.length
Expand All @@ -15,5 +16,3 @@ const tileFromQuadkey = (quadkey: string) => {
}
return [x, y, z]
}

export { tileFromQuadkey }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tile/to/boundingbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ const toLatitude = (y: number, z: number): number => {
return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)))
}

const tileToBoundingBox = (tile: MercatorTile): MercatorBoundingBox => {
/** @deprecated use form @xylabs/geo */
export const tileToBoundingBox = (tile: MercatorTile): MercatorBoundingBox => {
const e = toLongitude(tile[0] + 1, tile[2])
const w = toLongitude(tile[0], tile[2])
const s = toLatitude(tile[1] + 1, tile[2])
const n = toLatitude(tile[1], tile[2])
return new MercatorBoundingBox(new MapBox.LngLat(w, s), new MapBox.LngLat(e, n))
}

export { tileToBoundingBox }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tile/to/children.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { MercatorTile } from '../../types.ts'

const tileToChildren = (tile: MercatorTile) => {
/** @deprecated use form @xylabs/geo */
export const tileToChildren = (tile: MercatorTile) => {
return [
[tile[0] * 2, tile[1] * 2, tile[2] + 1],
[tile[0] * 2 + 1, tile[1] * 2, tile[2] + 1],
[tile[0] * 2 + 1, tile[1] * 2 + 1, tile[2] + 1],
[tile[0] * 2, tile[1] * 2 + 1, tile[2] + 1],
]
}

export { tileToChildren }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tile/to/geoJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type { Polygon, Position } from 'geojson'
import type { MercatorTile } from '../../types.ts'
import { tileToBoundingBox } from './boundingbox.ts'

const tileToGeoJson = (tile: MercatorTile): Polygon => {
/** @deprecated use form @xylabs/geo */
export const tileToGeoJson = (tile: MercatorTile): Polygon => {
const box = tileToBoundingBox(tile)
const poly: Polygon = {
coordinates: [
Expand All @@ -19,5 +20,3 @@ const tileToGeoJson = (tile: MercatorTile): Polygon => {
}
return poly
}

export { tileToGeoJson }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tile/to/parent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { MercatorTile } from '../../types.ts'

const tileToParent = (tile: MercatorTile): MercatorTile => {
/** @deprecated use form @xylabs/geo */
export const tileToParent = (tile: MercatorTile): MercatorTile => {
return [tile[0] >> 1, tile[1] >> 1, tile[2] - 1]
}

export { tileToParent }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tile/to/point.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { MercatorLngLat, MercatorTile } from '../../types.ts'
import { tileToBoundingBox } from './boundingbox.ts'

const tileToPoint = (tile: MercatorTile): MercatorLngLat => {
/** @deprecated use form @xylabs/geo */
export const tileToPoint = (tile: MercatorTile): MercatorLngLat => {
const boundingBox = tileToBoundingBox(tile)
boundingBox.getCenter()
return boundingBox.getCenter()
}

export { tileToPoint }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tile/to/quadkey.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { MercatorTile } from '../../types.ts'

const tileToQuadkey = (tile: MercatorTile): string => {
/** @deprecated use form @xylabs/geo */
export const tileToQuadkey = (tile: MercatorTile): string => {
let index = ''
for (let z = tile[2]; z > 0; z--) {
let b = 0
Expand All @@ -11,5 +12,3 @@ const tileToQuadkey = (tile: MercatorTile): string => {
}
return index
}

export { tileToQuadkey }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tile/to/siblings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type { MercatorTile } from '../../types.ts'
import { tileToChildren } from './children.ts'
import { tileToParent } from './parent.ts'

const tileToSiblings = (tile: MercatorTile): MercatorTile[] => {
/** @deprecated use form @xylabs/geo */
export const tileToSiblings = (tile: MercatorTile): MercatorTile[] => {
return tileToChildren(tileToParent(tile))
}

export { tileToSiblings }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tiles/equal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { MercatorTile } from '../types.ts'

const tilesEqual = (tile1: MercatorTile, tile2: MercatorTile) => {
/** @deprecated use form @xylabs/geo */
export const tilesEqual = (tile1: MercatorTile, tile2: MercatorTile) => {
return tile1[0] === tile2[0] && tile1[1] === tile2[1] && tile1[2] === tile2[2]
}

export { tilesEqual }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tiles/from/boundingbox.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { tileFromPoint } from '../../tile/index.ts'
import type { MercatorBoundingBox, MercatorTile } from '../../types.ts'

const tilesFromBoundingBox = (box: MercatorBoundingBox, zoom: number): MercatorTile[] => {
/** @deprecated use form @xylabs/geo */
export const tilesFromBoundingBox = (box: MercatorBoundingBox, zoom: number): MercatorTile[] => {
const nw = tileFromPoint(box.getNorthWest(), zoom)
const se = tileFromPoint(box.getSouthEast(), zoom)
const size = Math.pow(2, zoom)
Expand Down Expand Up @@ -33,5 +34,3 @@ const tilesFromBoundingBox = (box: MercatorBoundingBox, zoom: number): MercatorT

return result
}

export { tilesFromBoundingBox }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tiles/hasSiblings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { tileToSiblings } from '../tile/index.ts'
import type { MercatorTile } from '../types.ts'
import { tilesHasTile } from './hasTile.ts'

const hasSiblings = (tiles: MercatorTile[], tile: MercatorTile) => {
/** @deprecated use form @xylabs/geo */
export const hasSiblings = (tiles: MercatorTile[], tile: MercatorTile) => {
const siblings = tileToSiblings(tile)
for (const sibling of siblings) {
if (!tilesHasTile(tiles, sibling)) return false
}
return true
}

export { hasSiblings }
5 changes: 2 additions & 3 deletions packages/geo/src/mercator/tiles/hasTile.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import type { MercatorTile } from '../types.ts'
import { tilesEqual } from './equal.ts'

const tilesHasTile = (tiles: MercatorTile[], tile: MercatorTile) => {
/** @deprecated use form @xylabs/geo */
export const tilesHasTile = (tiles: MercatorTile[], tile: MercatorTile) => {
for (const tileToCheck of tiles) {
if (tilesEqual(tileToCheck, tile)) return true
}
return false
}

export { tilesHasTile }
15 changes: 8 additions & 7 deletions packages/geo/src/mercator/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import MapBox from 'mapbox-gl'

type MercatorTile = number[]
type MercatorBoundary = MercatorLngLat[]
class MercatorBoundingBox extends MapBox.LngLatBounds {}
class MercatorLngLat extends MapBox.LngLat {}

export { MercatorBoundingBox, MercatorLngLat }
export type { MercatorBoundary, MercatorTile }
/** @deprecated use form @xylabs/geo */
export type MercatorTile = number[]
/** @deprecated use form @xylabs/geo */
export type MercatorBoundary = MercatorLngLat[]
/** @deprecated use form @xylabs/geo */
export class MercatorBoundingBox extends MapBox.LngLatBounds {}
/** @deprecated use form @xylabs/geo */
export class MercatorLngLat extends MapBox.LngLat {}
Loading

0 comments on commit dc3d78b

Please sign in to comment.