Handle possible nested arrays when calculating Squaremap/Pl3xmap bounds from points
This commit is contained in:
parent
7bea15be32
commit
e2a89c28d0
24
src/util.ts
24
src/util.ts
@ -263,19 +263,25 @@ 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) => {
|
||||||
bounds.max.x = Math.max(point.x, bounds.max.x);
|
if(Array.isArray(point)) {
|
||||||
bounds.max.y = Math.max(point.y, bounds.max.y);
|
point.map(handlePoint);
|
||||||
bounds.max.z = Math.max(point.z, bounds.max.z);
|
} else {
|
||||||
bounds.min.x = Math.min(point.x, bounds.min.x);
|
bounds.max.x = Math.max(point.x, bounds.max.x);
|
||||||
bounds.min.y = Math.min(point.y, bounds.min.y);
|
bounds.max.y = Math.max(point.y, bounds.max.y);
|
||||||
bounds.min.z = Math.min(point.z, bounds.min.z);
|
bounds.max.z = Math.max(point.z, bounds.max.z);
|
||||||
|
bounds.min.x = Math.min(point.x, bounds.min.x);
|
||||||
|
bounds.min.y = Math.min(point.y, bounds.min.y);
|
||||||
|
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