Merge branch 'master' of github.com:revarbat/BOSL2 into revarbat_dev

This commit is contained in:
Garth Minette 2020-07-26 18:14:04 -07:00
commit bda538defa
3 changed files with 27 additions and 8 deletions

View file

@ -28,7 +28,6 @@ function point2d(p, fill=0) = [for (i=[0:1]) (p[i]==undef)? fill : p[i]];
// every vector has the same length.
// Arguments:
// points = A list of 2D or 3D points/vectors.
// fill = Value to fill missing values in vectors with.
function path2d(points) =
assert(is_path(points,dim=undef,fast=true),"Input to path2d is not a path")
let (result = points * concat(ident(2), repeat([0,0], len(points[0])-2)))

View file

@ -1380,15 +1380,18 @@ function find_noncollinear_points(points) =
// Usage:
// pointlist_bounds(pts);
// Description:
// Finds the bounds containing all the 2D or 3D points in `pts`.
// Returns `[[MINX, MINY, MINZ], [MAXX, MAXY, MAXZ]]`
// Finds the bounds containing all the points in `pts` which can be a list of points in any dimension.
// Returns a list of two items: a list of the minimums and a list of the maximums. For example, with
// 3d points `[[MINX, MINY, MINZ], [MAXX, MAXY, MAXZ]]`
// Arguments:
// pts = List of points.
function pointlist_bounds(pts) = [
[for (a=[0:2]) min([ for (x=pts) point3d(x)[a] ]) ],
[for (a=[0:2]) max([ for (x=pts) point3d(x)[a] ]) ]
];
function pointlist_bounds(pts) =
assert(is_matrix(pts))
let(ptsT = transpose(pts))
[
[for(row=ptsT) min(row)],
[for(row=ptsT) max(row)]
];
// Function: closest_point()
// Usage:

View file

@ -613,6 +613,23 @@ module test_pointlist_bounds() {
[23,57,-42]
];
assert(pointlist_bounds(pts) == [[-63,-32,-42], [84,97,42]]);
pts2d = [
[-53,12],
[-63,36],
[84,-5],
[63,42],
[23,-42]
];
assert(pointlist_bounds(pts2d) == [[-63,-42],[84,42]]);
pts5d = [
[-53,27,12,-53,12],
[-63,97,36,-63,36],
[84,-32,-5,84,-5],
[63,-24,42,63,42],
[23,57,-42,23,-42]
];
assert(pointlist_bounds(pts5d) == [[-63,-32,-42,-63,-42],[84,97,42,84,42]]);
assert(pointlist_bounds([[3,4,5,6]]), [[3,4,5,6],[3,4,5,6]]);
}
test_pointlist_bounds();