1515# Constructors & typealiases
1616
1717const Rect{N,T} = HyperRectangle{N,T}
18- const Rect2D {T} = Rect{2 ,T}
19- const Rect3D {T} = Rect{3 ,T}
20- const TRect {T} = Rect{N,T} where {N}
18+ const Rect2 {T} = Rect{2 ,T}
19+ const Rect3 {T} = Rect{3 ,T}
20+ const RectT {T} = Rect{N,T} where {N}
2121
22- const FRect {N} = Rect{N,Float32}
23- const FRect2D = Rect2D {Float32}
24- const FRect3D = Rect3D {Float32}
22+ const Rectf {N} = Rect{N,Float32}
23+ const Rect2f = Rect2 {Float32}
24+ const Rect3f = Rect3 {Float32}
2525
26- const IRect {N} = HyperRectangle{N,Int}
27- const IRect2D = Rect2D {Int}
28- const IRect3D = Rect3D {Int}
26+ const Recti {N} = HyperRectangle{N,Int}
27+ const Rect2i = Rect2 {Int}
28+ const Rect3i = Rect3 {Int}
2929
3030Rect () = Rect {2,Float32} ()
3131
32- TRect {T} () where {T} = Rect {2,T} ()
32+ RectT {T} () where {T} = Rect {2,T} ()
3333
3434Rect {N} () where {N} = Rect {N,Float32} ()
3535
@@ -48,7 +48,7 @@ function Rect(v1::Vec{N,T1}, v2::Vec{N,T2}) where {N,T1,T2}
4848 return Rect {N,T} (Vec {N,T} (v1), Vec {N,T} (v2))
4949end
5050
51- function TRect {T} (v1:: VecTypes{N,T1} , v2:: VecTypes{N,T2} ) where {N,T,T1,T2}
51+ function RectT {T} (v1:: VecTypes{N,T1} , v2:: VecTypes{N,T2} ) where {N,T,T1,T2}
5252 return if T <: Integer
5353 Rect {N,T} (round .(T, v1), round .(T, v2))
5454 else
@@ -84,75 +84,75 @@ width == Vec(1,2)
8484 return Expr (:call , :Rect , v1, v2)
8585end
8686
87- Rect3D (a:: Vararg{Number,6} ) = Rect3D (Vec {3} (a[1 ], a[2 ], a[3 ]), Vec {3} (a[4 ], a[5 ], a[6 ]))
88- Rect3D (args:: Vararg{Number,4} ) = Rect3D (Rect {2} (args... ))
87+ Rect3 (a:: Vararg{Number,6} ) = Rect3 (Vec {3} (a[1 ], a[2 ], a[3 ]), Vec {3} (a[4 ], a[5 ], a[6 ]))
88+ Rect3 (args:: Vararg{Number,4} ) = Rect3 (Rect {2} (args... ))
8989#=
9090From different args
9191=#
9292function (Rect)(args:: Vararg{Number,4} )
9393 args_prom = promote (args... )
94- return Rect2D {typeof(args_prom[1])} (args_prom... )
94+ return Rect2 {typeof(args_prom[1])} (args_prom... )
9595end
9696
97- function (Rect2D )(args:: Vararg{Number,4} )
97+ function (Rect2 )(args:: Vararg{Number,4} )
9898 args_prom = promote (args... )
99- return Rect2D {typeof(args_prom[1])} (args_prom... )
99+ return Rect2 {typeof(args_prom[1])} (args_prom... )
100100end
101101
102102function (Rect{2 ,T})(args:: Vararg{Number,4} ) where {T}
103103 x, y, w, h = T <: Integer ? round .(T, args) : args
104- return Rect2D {T} (Vec {2,T} (x, y), Vec {2,T} (w, h))
104+ return Rect2 {T} (Vec {2,T} (x, y), Vec {2,T} (w, h))
105105end
106106
107- function TRect {T} (args:: Vararg{Number,4} ) where {T}
107+ function RectT {T} (args:: Vararg{Number,4} ) where {T}
108108 x, y, w, h = T <: Integer ? round .(T, args) : args
109- return Rect2D {T} (Vec {2,T} (x, y), Vec {2,T} (w, h))
109+ return Rect2 {T} (Vec {2,T} (x, y), Vec {2,T} (w, h))
110110end
111111
112- function FRect3D (x:: Rect2D {T} ) where {T}
112+ function Rect3f (x:: Rect2 {T} ) where {T}
113113 return Rect {3,T} (Vec {3,T} (minimum (x)... , 0 ), Vec {3,T} (widths (x)... , 0.0 ))
114114end
115115
116- function Rect2D {T} (a:: Rect2D ) where {T}
117- return Rect2D {T} (minimum (a), widths (a))
116+ function Rect2 {T} (a:: Rect2 ) where {T}
117+ return Rect2 {T} (minimum (a), widths (a))
118118end
119119
120- function TRect {T} (a:: Rect2D ) where {T}
121- return Rect2D {T} (minimum (a), widths (a))
120+ function RectT {T} (a:: Rect2 ) where {T}
121+ return Rect2 {T} (minimum (a), widths (a))
122122end
123123
124124function Rect {N,T} (a:: GeometryPrimitive ) where {N,T}
125125 return Rect {N,T} (Vec {N,T} (minimum (a)), Vec {N,T} (widths (a)))
126126end
127127
128- function Rect2D (xy:: VecTypes{2} , w:: Number , h:: Number )
129- return Rect2D (xy... , w, h)
128+ function Rect2 (xy:: VecTypes{2} , w:: Number , h:: Number )
129+ return Rect2 (xy... , w, h)
130130end
131131
132- function Rect2D (x:: Number , y:: Number , wh:: VecTypes{2} )
133- return Rect2D (x, y, wh... )
132+ function Rect2 (x:: Number , y:: Number , wh:: VecTypes{2} )
133+ return Rect2 (x, y, wh... )
134134end
135135
136- function TRect {T} (xy:: VecTypes{2} , w:: Number , h:: Number ) where {T}
137- return Rect2D {T} (xy... , w, h)
136+ function RectT {T} (xy:: VecTypes{2} , w:: Number , h:: Number ) where {T}
137+ return Rect2 {T} (xy... , w, h)
138138end
139139
140- function TRect {T} (x:: Number , y:: Number , wh:: VecTypes{2} ) where {T}
141- return Rect2D {T} (x, y, wh... )
140+ function RectT {T} (x:: Number , y:: Number , wh:: VecTypes{2} ) where {T}
141+ return Rect2 {T} (x, y, wh... )
142142end
143143
144144# TODO These are kinda silly
145- function Rect2D (xy:: NamedTuple{(:x, :y)} , wh:: NamedTuple{(:width, :height)} )
146- return Rect2D (xy. x, xy. y, wh. width, wh. height)
145+ function Rect2 (xy:: NamedTuple{(:x, :y)} , wh:: NamedTuple{(:width, :height)} )
146+ return Rect2 (xy. x, xy. y, wh. width, wh. height)
147147end
148148
149- function FRect3D (x:: Tuple{Tuple{<:Number,<:Number},Tuple{<:Number,<:Number}} )
150- return FRect3D (Vec3f (x[1 ]. .. , 0 ), Vec3f (x[2 ]. .. , 0 ))
149+ function Rect3f (x:: Tuple{Tuple{<:Number,<:Number},Tuple{<:Number,<:Number}} )
150+ return Rect3f (Vec3f (x[1 ]. .. , 0 ), Vec3f (x[2 ]. .. , 0 ))
151151end
152152
153- function FRect3D (x:: Tuple {Tuple{<: Number ,<: Number ,<: Number },
153+ function Rect3f (x:: Tuple {Tuple{<: Number ,<: Number ,<: Number },
154154 Tuple{<: Number ,<: Number ,<: Number }})
155- return FRect3D (Vec3f (x[1 ]. .. ), Vec3f (x[2 ]. .. ))
155+ return Rect3f (Vec3f (x[1 ]. .. ), Vec3f (x[2 ]. .. ))
156156end
157157
158158origin (prim:: Rect ) = prim. origin
@@ -165,7 +165,7 @@ width(prim::Rect) = prim.widths[1]
165165height (prim:: Rect ) = prim. widths[2 ]
166166
167167volume (prim:: HyperRectangle ) = prod (prim. widths)
168- area (prim:: Rect2D ) = volume (prim)
168+ area (prim:: Rect2 ) = volume (prim)
169169
170170"""
171171 split(rectangle, axis, value)
@@ -279,7 +279,7 @@ function Base.:(*)(rect::Rect, scaling::Union{Number,StaticVector})
279279end
280280
281281# Enables rectangular indexing into a matrix
282- function Base. to_indices (A:: AbstractMatrix{T} , I:: Tuple{Rect2D {IT}} ) where {T,IT<: Integer }
282+ function Base. to_indices (A:: AbstractMatrix{T} , I:: Tuple{Rect2 {IT}} ) where {T,IT<: Integer }
283283 rect = I[1 ]
284284 mini = minimum (rect)
285285 wh = widths (rect)
@@ -515,33 +515,33 @@ centered(R::Type{Rect{N}}) where {N} = R(Vec{N,Float32}(-0.5), Vec{N,Float32}(1)
515515centered (R:: Type{Rect} ) where {N} = R (Vec {2,Float32} (- 0.5 ), Vec {2,Float32} (1 ))
516516
517517# #
518- # Rect2D decomposition
518+ # Rect2 decomposition
519519
520- function faces (rect:: Rect2D , nvertices= (2 , 2 ))
520+ function faces (rect:: Rect2 , nvertices= (2 , 2 ))
521521 w, h = nvertices
522522 idx = LinearIndices (nvertices)
523523 quad (i, j) = QuadFace {Int} (idx[i, j], idx[i + 1 , j], idx[i + 1 , j + 1 ], idx[i, j + 1 ])
524524 return ivec ((quad (i, j) for i in 1 : (w - 1 ), j in 1 : (h - 1 )))
525525end
526526
527- function coordinates (rect:: Rect2D , nvertices= (2 , 2 ))
527+ function coordinates (rect:: Rect2 , nvertices= (2 , 2 ))
528528 mini, maxi = extrema (rect)
529529 xrange, yrange = LinRange .(mini, maxi, nvertices)
530530 return ivec (((x, y) for x in xrange, y in yrange))
531531end
532532
533- function texturecoordinates (rect:: Rect2D , nvertices= (2 , 2 ))
533+ function texturecoordinates (rect:: Rect2 , nvertices= (2 , 2 ))
534534 xrange, yrange = LinRange .((0 , 1 ), (1 , 0 ), nvertices)
535535 return ivec (((x, y) for x in xrange, y in yrange))
536536end
537537
538- function normals (rect:: Rect2D , nvertices= (2 , 2 ))
538+ function normals (rect:: Rect2 , nvertices= (2 , 2 ))
539539 return Iterators. repeated ((0 , 0 , 1 ), prod (nvertices))
540540end
541541
542542# #
543- # Rect3D decomposition
544- function coordinates (rect:: Rect3D )
543+ # Rect3 decomposition
544+ function coordinates (rect:: Rect3 )
545545 # TODO use n
546546 w = widths (rect)
547547 o = origin (rect)
@@ -552,11 +552,11 @@ function coordinates(rect::Rect3D)
552552 return ((x .* w .+ o) for x in points)
553553end
554554
555- function texturecoordinates (rect:: Rect3D )
556- return coordinates (Rect3D (0 , 0 , 0 , 1 , 1 , 1 ))
555+ function texturecoordinates (rect:: Rect3 )
556+ return coordinates (Rect3 (0 , 0 , 0 , 1 , 1 , 1 ))
557557end
558558
559- function faces (rect:: Rect3D )
559+ function faces (rect:: Rect3 )
560560 return QuadFace{Int}[(1 , 2 , 3 , 4 ), (5 , 6 , 7 , 8 ), (9 , 10 , 11 , 12 ), (13 , 14 , 15 , 16 ),
561561 (17 , 18 , 19 , 20 ), (21 , 22 , 23 , 24 ),]
562562end
0 commit comments