diff --git a/index.ts b/index.ts index 0000d6a..3c851e0 100644 --- a/index.ts +++ b/index.ts @@ -12,6 +12,7 @@ import { shuffle, SampleType, generateSample, + isValidEPSG3857Lat, } from "./src/utils"; import { Command } from "commander"; import { redis } from "./src/Redis/Redis"; @@ -113,6 +114,9 @@ new Promise(async (resolve, reject) => { // Query B case testPoint = data[Math.floor(Math.random() * data.length)]; + while( !isValidEPSG3857Lat(testPoint.lat) ){ + testPoint = data[Math.floor(Math.random() * data.length)]; + } lng = testPoint.lng; lat = testPoint.lat; distance = Math.random() * 100; @@ -135,6 +139,9 @@ new Promise(async (resolve, reject) => { // Query C case testPoint = data[Math.floor(Math.random() * data.length)]; + while( !isValidEPSG3857Lat(testPoint.lat) ){ + testPoint = data[Math.floor(Math.random() * data.length)]; + } lng = testPoint.lng; lat = testPoint.lat; distance = Math.random() * 100; diff --git a/src/Redis/Locations.ts b/src/Redis/Locations.ts index 28871ff..ebca784 100644 --- a/src/Redis/Locations.ts +++ b/src/Redis/Locations.ts @@ -1,4 +1,4 @@ -import { Entity, Schema } from 'redis-om'; +import { Schema } from 'redis-om'; export type Location = { diff --git a/src/utils.ts b/src/utils.ts index 6c1bb3b..ebf8a69 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -11,6 +11,11 @@ export function randomLat() { return Math.random() * 180 - 90; } +export function isValidEPSG3857Lat(lat: number): boolean { + const latLimit = 85.05112878; + return Math.abs(lat) < latLimit; +} + export type Longitude = number; export type Latitude = number;