Handle possible nested arrays when calculating Squaremap/Pl3xmap bounds from points
This commit is contained in:
parent
7bea15be32
commit
e2a89c28d0
12
src/util.ts
12
src/util.ts
@ -263,11 +263,14 @@ export const getBounds = (x: number[], y: number[], z: number[]): LiveAtlasBound
|
|||||||
|
|
||||||
export const getBoundsFromPoints = (points: Coordinate[]): LiveAtlasBounds => {
|
export const getBoundsFromPoints = (points: Coordinate[]): LiveAtlasBounds => {
|
||||||
const bounds = {
|
const bounds = {
|
||||||
max: {...points[0]},
|
max: {x: -Infinity, y: -Infinity, z: -Infinity},
|
||||||
min: {...points[0]},
|
min: {x: Infinity, y: Infinity, z: Infinity},
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const point of points) {
|
const handlePoint = (point: any) => {
|
||||||
|
if(Array.isArray(point)) {
|
||||||
|
point.map(handlePoint);
|
||||||
|
} else {
|
||||||
bounds.max.x = Math.max(point.x, bounds.max.x);
|
bounds.max.x = Math.max(point.x, bounds.max.x);
|
||||||
bounds.max.y = Math.max(point.y, bounds.max.y);
|
bounds.max.y = Math.max(point.y, bounds.max.y);
|
||||||
bounds.max.z = Math.max(point.z, bounds.max.z);
|
bounds.max.z = Math.max(point.z, bounds.max.z);
|
||||||
@ -275,6 +278,9 @@ export const getBoundsFromPoints = (points: Coordinate[]): LiveAtlasBounds => {
|
|||||||
bounds.min.y = Math.min(point.y, bounds.min.y);
|
bounds.min.y = Math.min(point.y, bounds.min.y);
|
||||||
bounds.min.z = Math.min(point.z, bounds.min.z);
|
bounds.min.z = Math.min(point.z, bounds.min.z);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
points.map(handlePoint);
|
||||||
|
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user