Clamping
Meshes adds methods to Julia's built-in clamp function. The additional methods clamp points to the edges of a box in any number of dimensions. The target points and boxes must have the same number of dimensions and the same numeric type.
Base.clamp — Method
clamp(point, box)Clamp the coordinates of a Point to the edges of a Box.
For each dimension, coordinates outside of the box are moved to the nearest edge of the box. The point and box must have an equal number of dimensions.
Base.clamp — Method
clamp(pset, box)Clamp each point in a PointSet to the edges of a Box, returning a new set of points.
# set of 2D points to clamp
points = PointSet(rand(Point, 100, crs=Cartesian2D))
# 2D box defining the clamping boundaries
box = Box((0.25, 0.25), (0.75, 0.75))
# clamp point coordinates to the box edges
clamped = clamp(points, box)
fig = Mke.Figure(size=(800, 400))
viz(fig[1, 1], box, axis=(; title="unclamped"))
viz!(fig[1, 1], points, color=:black, pointsize=6)
viz(fig[1, 2], box, axis=(; title="clamped"))
viz!(fig[1, 2], clamped, color=:black, pointsize=6)
Mke.linkaxes!(fig.content...)
fig