Skip to content

Commit 34795e3

Browse files
committed
add basic docs for bounding boxes
1 parent b951535 commit 34795e3

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ makedocs(format=Documenter.HTML(prettyurls=get(ENV, "CI", "false") == "true"),
1313
"polygons.md",
1414
"meshes.md",
1515
"decomposition.md",
16+
"boundingboxes.md",
1617
"static_array_types.md",
17-
"api.md"
18+
"api.md",
1819
],
1920
modules=[GeometryBasics])
2021

docs/src/boundingboxes.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Bounding Boxes
2+
3+
You can generate an axis aligned bounding box for any `AbstractGeometry` by calling `Rect(geom)`.
4+
Depending on the object this will either rely on `coordinates(geom)` or a specialized method.
5+
You can also create a bounding box of set dimension or type by adding the related parameters.
6+
7+
8+
```@repl
9+
using GeometryBasics
10+
11+
s = Circle(Point2f(0), 1f0)
12+
Rect(s) # specialized, exact bounding box
13+
Rect3(s)
14+
Rect3d(s)
15+
RectT{Float64}(s)
16+
Rect(GeometryBasics.mesh(s)) # using generated coordinates in mesh
17+
```
18+
19+
## Extending
20+
21+
If you want to add a specialized bounding box method you should implement `Rect{N, T}(geom) = ...`.
22+
All other methods funnel into that one, defaulting to the same `N, T` that the given `AbstractGeometry{N, T}` has.
23+
GeometryBasics allows the user given dimension `N` to be smaller or equal to that of the geometry.
24+
This is checked with `GeometryBasics.bbox_dim_check(user_dim, geom_dim)` which you may reuse.
25+
26+
```@example
27+
function Rect{N, T}(a::HyperSphere{N2}) where {N, N2, T}
28+
bbox_dim_check(N, N2)
29+
return Rect{N, T}(minimum(a), widths(a))
30+
end
31+
```

src/boundingboxes.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ function Rect{N, T}(a::Pyramid) where {N, T}
6060
return Rect{N, T}(m .- Vec{3,T}(w / T(2), w / T(2), 0), Vec{3,T}(w, w, h))
6161
end
6262

63-
function Rect{N, T}(a::HyperSphere) where {N, T}
64-
mini, maxi = extrema(a)
65-
return Rect{N, T}(mini, maxi .- mini)
63+
function Rect{N, T}(a::HyperSphere{N2}) where {N, N2, T}
64+
bbox_dim_check(N, N2)
65+
return Rect{N, T}(minimum(a), widths(a))
6666
end
6767

6868
# TODO: exact implementation that doesn't rely on coordinates

0 commit comments

Comments
 (0)