@trackunit/geo-json-utils 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +8 -10
- package/index.esm.js +8 -10
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -363,32 +363,30 @@ const getPointCoordinateFromGeoJsonPoint = (point) => {
|
|
|
363
363
|
* @returns {GeoJsonPoint} The extreme point in the given direction
|
|
364
364
|
*/
|
|
365
365
|
const getExtremeGeoJsonPointFromPolygon = ({ polygon, direction, }) => {
|
|
366
|
-
var _a, _b, _c;
|
|
367
366
|
const polygonParsed = geoJsonPolygonSchema.safeParse(polygon);
|
|
368
367
|
if (!polygonParsed.success) {
|
|
369
368
|
return null;
|
|
370
369
|
}
|
|
371
|
-
const firstPoint =
|
|
370
|
+
const firstPoint = polygonParsed.data.coordinates[0]?.[0];
|
|
372
371
|
if (!firstPoint) {
|
|
373
372
|
// Should never happen since the schema checks for it
|
|
374
373
|
return null;
|
|
375
374
|
}
|
|
376
|
-
const extremePosition =
|
|
377
|
-
var _a, _b, _c, _d;
|
|
375
|
+
const extremePosition = polygonParsed.data.coordinates[0]?.reduce((extremePoint, currentPoint) => {
|
|
378
376
|
switch (direction) {
|
|
379
377
|
case "top":
|
|
380
|
-
return currentPoint[1] > (
|
|
378
|
+
return currentPoint[1] > (extremePoint?.[1] ?? -Infinity) ? currentPoint : (extremePoint ?? currentPoint);
|
|
381
379
|
case "right":
|
|
382
|
-
return currentPoint[0] > (
|
|
380
|
+
return currentPoint[0] > (extremePoint?.[0] ?? -Infinity) ? currentPoint : (extremePoint ?? currentPoint);
|
|
383
381
|
case "bottom":
|
|
384
|
-
return currentPoint[1] < (
|
|
382
|
+
return currentPoint[1] < (extremePoint?.[1] ?? Infinity) ? currentPoint : (extremePoint ?? currentPoint);
|
|
385
383
|
case "left":
|
|
386
|
-
return currentPoint[0] < (
|
|
384
|
+
return currentPoint[0] < (extremePoint?.[0] ?? Infinity) ? currentPoint : (extremePoint ?? currentPoint);
|
|
387
385
|
default: {
|
|
388
386
|
throw new Error(`${direction} is not known`);
|
|
389
387
|
}
|
|
390
388
|
}
|
|
391
|
-
},
|
|
389
|
+
}, polygonParsed.data.coordinates[0]?.[0]);
|
|
392
390
|
return extremePosition
|
|
393
391
|
? {
|
|
394
392
|
type: "Point",
|
|
@@ -595,7 +593,7 @@ const tuGeoJsonRectangularBoxPolygonSchema = zod.z
|
|
|
595
593
|
.superRefine((data, ctx) => {
|
|
596
594
|
const coordinates = data.coordinates[0];
|
|
597
595
|
// Validate polygon has exactly 5 points
|
|
598
|
-
if (
|
|
596
|
+
if (coordinates?.length !== 5) {
|
|
599
597
|
ctx.addIssue({
|
|
600
598
|
code: zod.z.ZodIssueCode.custom,
|
|
601
599
|
message: "Polygon must have exactly 5 coordinates to form a closed box.",
|
package/index.esm.js
CHANGED
|
@@ -361,32 +361,30 @@ const getPointCoordinateFromGeoJsonPoint = (point) => {
|
|
|
361
361
|
* @returns {GeoJsonPoint} The extreme point in the given direction
|
|
362
362
|
*/
|
|
363
363
|
const getExtremeGeoJsonPointFromPolygon = ({ polygon, direction, }) => {
|
|
364
|
-
var _a, _b, _c;
|
|
365
364
|
const polygonParsed = geoJsonPolygonSchema.safeParse(polygon);
|
|
366
365
|
if (!polygonParsed.success) {
|
|
367
366
|
return null;
|
|
368
367
|
}
|
|
369
|
-
const firstPoint =
|
|
368
|
+
const firstPoint = polygonParsed.data.coordinates[0]?.[0];
|
|
370
369
|
if (!firstPoint) {
|
|
371
370
|
// Should never happen since the schema checks for it
|
|
372
371
|
return null;
|
|
373
372
|
}
|
|
374
|
-
const extremePosition =
|
|
375
|
-
var _a, _b, _c, _d;
|
|
373
|
+
const extremePosition = polygonParsed.data.coordinates[0]?.reduce((extremePoint, currentPoint) => {
|
|
376
374
|
switch (direction) {
|
|
377
375
|
case "top":
|
|
378
|
-
return currentPoint[1] > (
|
|
376
|
+
return currentPoint[1] > (extremePoint?.[1] ?? -Infinity) ? currentPoint : (extremePoint ?? currentPoint);
|
|
379
377
|
case "right":
|
|
380
|
-
return currentPoint[0] > (
|
|
378
|
+
return currentPoint[0] > (extremePoint?.[0] ?? -Infinity) ? currentPoint : (extremePoint ?? currentPoint);
|
|
381
379
|
case "bottom":
|
|
382
|
-
return currentPoint[1] < (
|
|
380
|
+
return currentPoint[1] < (extremePoint?.[1] ?? Infinity) ? currentPoint : (extremePoint ?? currentPoint);
|
|
383
381
|
case "left":
|
|
384
|
-
return currentPoint[0] < (
|
|
382
|
+
return currentPoint[0] < (extremePoint?.[0] ?? Infinity) ? currentPoint : (extremePoint ?? currentPoint);
|
|
385
383
|
default: {
|
|
386
384
|
throw new Error(`${direction} is not known`);
|
|
387
385
|
}
|
|
388
386
|
}
|
|
389
|
-
},
|
|
387
|
+
}, polygonParsed.data.coordinates[0]?.[0]);
|
|
390
388
|
return extremePosition
|
|
391
389
|
? {
|
|
392
390
|
type: "Point",
|
|
@@ -593,7 +591,7 @@ const tuGeoJsonRectangularBoxPolygonSchema = z
|
|
|
593
591
|
.superRefine((data, ctx) => {
|
|
594
592
|
const coordinates = data.coordinates[0];
|
|
595
593
|
// Validate polygon has exactly 5 points
|
|
596
|
-
if (
|
|
594
|
+
if (coordinates?.length !== 5) {
|
|
597
595
|
ctx.addIssue({
|
|
598
596
|
code: z.ZodIssueCode.custom,
|
|
599
597
|
message: "Polygon must have exactly 5 coordinates to form a closed box.",
|