Bounding boxes denote the exten of geometries. It follows that bounding boxes are only defined for geometries that are located in space and have finite extent. Thus, vectors, lines, directions, rays, etc. does not have bounding boxes, while e.g. spheres, circles, segments, etc has. Since the extent of geometries cannot always be given exact (e.g. for circles), bounding boxes are defined in regular floating point precision. Bounding boxes can be compared for equality and be tested for whether they overlap. Adding bounding boxes together will give the bounding box containing both.

bbox(..., default_dim = 2)

is_bbox(x)

as_bbox(x)

is_overlapping(x, y)

x %overlaps% y

Arguments

...

Either a vector of geometries or a range of numeric vectors (4 for 2D bounding boxes and 6 for 3D) interpreted in the order xmin, ymin, zmin, xmax, ymax, zmax.

default_dim

The dimensionality when constructing an empty vector

x, y

vectors of bounding boxes or geometries

Value

An euclid_bbox vector

See also

Other non-geometry vectors: affine_transformation, exact_numeric()

Examples

# Construction
bbox(10, -2, 15, 0)
#> <2D bounding boxes [1]>
#> [1] <<10, -2>, <15, 0>>

seg <- segment(point(sample(10, 4), sample(10, 4)),
               point(sample(10, 4), sample(10, 4)))

boxes <- bbox(seg)
boxes
#> <2D bounding boxes [4]>
#> [1] <<2, 5>, <9, 10>> <<5, 4>, <6, 4>>  <<4, 1>, <7, 5>>  <<7, 3>, <8, 6>> 

plot(seg)
euclid_plot(boxes, fg = "firebrick")


# Comparison
boxes[1] == boxes
#> [1]  TRUE FALSE FALSE FALSE

boxes[1:2] %overlaps% boxes[3:4]
#> [1]  TRUE FALSE

# Addition
boxes[1] + boxes[2]
#> <2D bounding boxes [1]>
#> [1] <<2, 4>, <9, 10>>

cumsum(boxes)
#> <2D bounding boxes [4]>
#> [1] <<2, 5>, <9, 10>> <<2, 4>, <9, 10>> <<2, 1>, <9, 10>> <<2, 1>, <9, 10>>

plot(sum(boxes), bg = "grey", fg = NA)
euclid_plot(boxes)


# Conversion
as.matrix(boxes)
#>      [,1] [,2] [,3] [,4]
#> [1,]    2    5    9   10
#> [2,]    5    4    6    4
#> [3,]    4    1    7    5
#> [4,]    7    3    8    6