15
15
# Constructors & typealiases
16
16
17
17
const 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}
21
21
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}
25
25
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}
29
29
30
30
Rect () = Rect {2,Float32} ()
31
31
32
- TRect {T} () where {T} = Rect {2,T} ()
32
+ RectT {T} () where {T} = Rect {2,T} ()
33
33
34
34
Rect {N} () where {N} = Rect {N,Float32} ()
35
35
@@ -48,7 +48,7 @@ function Rect(v1::Vec{N,T1}, v2::Vec{N,T2}) where {N,T1,T2}
48
48
return Rect {N,T} (Vec {N,T} (v1), Vec {N,T} (v2))
49
49
end
50
50
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}
52
52
return if T <: Integer
53
53
Rect {N,T} (round .(T, v1), round .(T, v2))
54
54
else
@@ -84,75 +84,75 @@ width == Vec(1,2)
84
84
return Expr (:call , :Rect , v1, v2)
85
85
end
86
86
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... ))
89
89
#=
90
90
From different args
91
91
=#
92
92
function (Rect)(args:: Vararg{Number,4} )
93
93
args_prom = promote (args... )
94
- return Rect2D {typeof(args_prom[1])} (args_prom... )
94
+ return Rect2 {typeof(args_prom[1])} (args_prom... )
95
95
end
96
96
97
- function (Rect2D )(args:: Vararg{Number,4} )
97
+ function (Rect2 )(args:: Vararg{Number,4} )
98
98
args_prom = promote (args... )
99
- return Rect2D {typeof(args_prom[1])} (args_prom... )
99
+ return Rect2 {typeof(args_prom[1])} (args_prom... )
100
100
end
101
101
102
102
function (Rect{2 ,T})(args:: Vararg{Number,4} ) where {T}
103
103
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))
105
105
end
106
106
107
- function TRect {T} (args:: Vararg{Number,4} ) where {T}
107
+ function RectT {T} (args:: Vararg{Number,4} ) where {T}
108
108
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))
110
110
end
111
111
112
- function FRect3D (x:: Rect2D {T} ) where {T}
112
+ function Rect3f (x:: Rect2 {T} ) where {T}
113
113
return Rect {3,T} (Vec {3,T} (minimum (x)... , 0 ), Vec {3,T} (widths (x)... , 0.0 ))
114
114
end
115
115
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))
118
118
end
119
119
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))
122
122
end
123
123
124
124
function Rect {N,T} (a:: GeometryPrimitive ) where {N,T}
125
125
return Rect {N,T} (Vec {N,T} (minimum (a)), Vec {N,T} (widths (a)))
126
126
end
127
127
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)
130
130
end
131
131
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... )
134
134
end
135
135
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)
138
138
end
139
139
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... )
142
142
end
143
143
144
144
# 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)
147
147
end
148
148
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 ))
151
151
end
152
152
153
- function FRect3D (x:: Tuple {Tuple{<: Number ,<: Number ,<: Number },
153
+ function Rect3f (x:: Tuple {Tuple{<: Number ,<: Number ,<: Number },
154
154
Tuple{<: Number ,<: Number ,<: Number }})
155
- return FRect3D (Vec3f (x[1 ]. .. ), Vec3f (x[2 ]. .. ))
155
+ return Rect3f (Vec3f (x[1 ]. .. ), Vec3f (x[2 ]. .. ))
156
156
end
157
157
158
158
origin (prim:: Rect ) = prim. origin
@@ -165,7 +165,7 @@ width(prim::Rect) = prim.widths[1]
165
165
height (prim:: Rect ) = prim. widths[2 ]
166
166
167
167
volume (prim:: HyperRectangle ) = prod (prim. widths)
168
- area (prim:: Rect2D ) = volume (prim)
168
+ area (prim:: Rect2 ) = volume (prim)
169
169
170
170
"""
171
171
split(rectangle, axis, value)
@@ -279,7 +279,7 @@ function Base.:(*)(rect::Rect, scaling::Union{Number,StaticVector})
279
279
end
280
280
281
281
# 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 }
283
283
rect = I[1 ]
284
284
mini = minimum (rect)
285
285
wh = widths (rect)
@@ -515,33 +515,33 @@ centered(R::Type{Rect{N}}) where {N} = R(Vec{N,Float32}(-0.5), Vec{N,Float32}(1)
515
515
centered (R:: Type{Rect} ) where {N} = R (Vec {2,Float32} (- 0.5 ), Vec {2,Float32} (1 ))
516
516
517
517
# #
518
- # Rect2D decomposition
518
+ # Rect2 decomposition
519
519
520
- function faces (rect:: Rect2D , nvertices= (2 , 2 ))
520
+ function faces (rect:: Rect2 , nvertices= (2 , 2 ))
521
521
w, h = nvertices
522
522
idx = LinearIndices (nvertices)
523
523
quad (i, j) = QuadFace {Int} (idx[i, j], idx[i + 1 , j], idx[i + 1 , j + 1 ], idx[i, j + 1 ])
524
524
return ivec ((quad (i, j) for i in 1 : (w - 1 ), j in 1 : (h - 1 )))
525
525
end
526
526
527
- function coordinates (rect:: Rect2D , nvertices= (2 , 2 ))
527
+ function coordinates (rect:: Rect2 , nvertices= (2 , 2 ))
528
528
mini, maxi = extrema (rect)
529
529
xrange, yrange = LinRange .(mini, maxi, nvertices)
530
530
return ivec (((x, y) for x in xrange, y in yrange))
531
531
end
532
532
533
- function texturecoordinates (rect:: Rect2D , nvertices= (2 , 2 ))
533
+ function texturecoordinates (rect:: Rect2 , nvertices= (2 , 2 ))
534
534
xrange, yrange = LinRange .((0 , 1 ), (1 , 0 ), nvertices)
535
535
return ivec (((x, y) for x in xrange, y in yrange))
536
536
end
537
537
538
- function normals (rect:: Rect2D , nvertices= (2 , 2 ))
538
+ function normals (rect:: Rect2 , nvertices= (2 , 2 ))
539
539
return Iterators. repeated ((0 , 0 , 1 ), prod (nvertices))
540
540
end
541
541
542
542
# #
543
- # Rect3D decomposition
544
- function coordinates (rect:: Rect3D )
543
+ # Rect3 decomposition
544
+ function coordinates (rect:: Rect3 )
545
545
# TODO use n
546
546
w = widths (rect)
547
547
o = origin (rect)
@@ -552,11 +552,11 @@ function coordinates(rect::Rect3D)
552
552
return ((x .* w .+ o) for x in points)
553
553
end
554
554
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 ))
557
557
end
558
558
559
- function faces (rect:: Rect3D )
559
+ function faces (rect:: Rect3 )
560
560
return QuadFace{Int}[(1 , 2 , 3 , 4 ), (5 , 6 , 7 , 8 ), (9 , 10 , 11 , 12 ), (13 , 14 , 15 , 16 ),
561
561
(17 , 18 , 19 , 20 ), (21 , 22 , 23 , 24 ),]
562
562
end
0 commit comments