1
- function Rect (geometry:: AbstractArray{<:Point{N,T}} ) where {N,T}
2
- return Rect {N,T} (geometry)
1
+ # Boundingbox-like Rect constructors
2
+
3
+ Rect (p:: AbstractGeometry{N, T} ) where {N, T} = Rect {N, T} (p)
4
+ RectT {T} (p:: AbstractGeometry{N} ) where {N, T} = Rect {N, T} (p)
5
+ Rect {N} (p:: AbstractGeometry{_N, T} ) where {N, _N, T} = Rect {N, T} (p)
6
+
7
+ Rect (p:: AbstractArray{<: VecTypes{N, T}} ) where {N, T} = Rect {N, T} (p)
8
+ RectT {T} (p:: AbstractArray{<: VecTypes{N}} ) where {N, T} = Rect {N, T} (p)
9
+ Rect {N} (p:: AbstractArray{<: VecTypes{_N, T}} ) where {N, _N, T} = Rect {N, T} (p)
10
+
11
+ # compat: bounding boxes also defined Rect{T} constructors
12
+ # This is not really compatible with Rect{N}...
13
+ # How do you even deprecate this?
14
+ # @deprecate Rect{T}(x::AbstractGeometry) where {T <: Number} RectT{T}(x) where {T}
15
+ # @deprecate Rect{T}(x::AbstractArray) where {T <: Number} RectT{T}(x) where {T}
16
+
17
+ # Implementations
18
+ # Specialize fully typed Rect constructors
19
+ Rect {N, T} (p:: AbstractGeometry ) where {N, T} = Rect {N, T} (coordinates (p))
20
+
21
+ function bbox_dim_check (trg, src:: Integer )
22
+ @assert trg isa Integer " Rect{$trg , $T1 } is invalid. This may have happened due to calling Rect{$N1 }(obj) to get a bounding box."
23
+ if trg < src
24
+ throw (ArgumentError (" Cannot construct a $trg dimensional bounding box from $src dimensional Points. ($trg must be ≥ $src )" ))
25
+ end
3
26
end
4
27
5
28
"""
6
- Rect(points::AbstractArray{<: Point })
29
+ Rect(points::AbstractArray{<: VecTypes })
7
30
8
31
Construct a bounding box containing all the given points.
9
32
"""
10
- function Rect {N1,T1} (geometry:: AbstractArray{PT} ) where {N1,T1,PT<: Point }
11
- N2, T2 = length (PT), eltype (PT)
12
- @assert N1 >= N2
33
+ function Rect {N1, T1} (points:: AbstractArray{<: VecTypes{N2, T2}} ) where {N1, T1, N2, T2}
34
+ bbox_dim_check (N1, N2)
13
35
vmin = Point {N2,T2} (typemax (T2))
14
36
vmax = Point {N2,T2} (typemin (T2))
15
- for p in geometry
37
+ for p in points
16
38
vmin, vmax = _minmax (p, vmin, vmax)
17
39
end
18
40
o = vmin
@@ -25,29 +47,25 @@ function Rect{N1,T1}(geometry::AbstractArray{PT}) where {N1,T1,PT<:Point}
25
47
end
26
48
end
27
49
50
+
28
51
"""
29
52
Rect(primitive::GeometryPrimitive)
30
53
31
54
Construct a bounding box for the given primitive.
32
55
"""
33
- function Rect (primitive:: GeometryPrimitive{N,T} ) where {N,T}
34
- return Rect {N,T} (primitive)
35
- end
36
-
37
- function Rect {T} (primitive:: GeometryPrimitive{N,T} ) where {N,T}
38
- return Rect {N,T} (primitive)
39
- end
40
-
41
- function Rect {T} (a:: Pyramid ) where {T}
42
- w, h = a. width / T (2 ), a. length
56
+ function Rect {N, T} (a:: Pyramid ) where {N, T}
57
+ bbox_dim_check (N, 3 )
58
+ w, h = a. width, a. length
43
59
m = Vec {3,T} (a. middle)
44
- return Rect {T} (m .- Vec {3,T} (w, w, 0 ), m .+ Vec {3,T} (w, w, h))
60
+ return Rect {N, T} (m .- Vec {3,T} (w / T ( 2 ) , w / T ( 2 ) , 0 ), Vec {3,T} (w, w, h))
45
61
end
46
62
47
- function Rect {T} (a:: Sphere ) where {T}
63
+ function Rect {N, T} (a:: HyperSphere ) where {N, T}
48
64
mini, maxi = extrema (a)
49
- return Rect {T} (mini, maxi .- mini)
65
+ return Rect {N, T} (mini, maxi .- mini)
50
66
end
51
67
52
- Rect {T} (a) where {T} = Rect {T} (coordinates (a))
53
- Rect {N,T} (a) where {N,T} = Rect {N,T} (coordinates (a))
68
+ # TODO : exact implementation that doesn't rely on coordinates
69
+ # function Rect{N, T}(a::Cylinder) where {N, T}
70
+ # return Rect{N, T}(...)
71
+ # end
0 commit comments