Skip to content

Commit e2dd42d

Browse files
committed
Rename FRect2D to Rect2f, etc.
1 parent 68c95df commit e2dd42d

File tree

8 files changed

+96
-85
lines changed

8 files changed

+96
-85
lines changed

docs/src/decomposition.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ This can be done for any arbitrary primitive, by overloading the following inter
99

1010
```julia
1111

12-
function GeometryBasics.coordinates(rect::Rect2D, nvertices=(2,2))
12+
function GeometryBasics.coordinates(rect::Rect2, nvertices=(2,2))
1313
mini, maxi = extrema(rect)
1414
xrange, yrange = LinRange.(mini, maxi, nvertices)
1515
return ivec(((x,y) for x in xrange, y in yrange))
1616
end
1717

18-
function GeometryBasics.faces(rect::Rect2D, nvertices=(2, 2))
18+
function GeometryBasics.faces(rect::Rect2, nvertices=(2, 2))
1919
w, h = nvertices
2020
idx = LinearIndices(nvertices)
2121
quad(i, j) = QuadFace{Int}(idx[i, j], idx[i+1, j], idx[i+1, j+1], idx[i, j+1])
@@ -29,7 +29,7 @@ can also return any `AbstractArray`.
2929
With these methods defined, this constructor will magically work:
3030

3131
```julia
32-
rect = Rect2D(0.0, 0.0, 1.0, 1.0)
32+
rect = Rect2(0.0, 0.0, 1.0, 1.0)
3333
m = GeometryBasics.mesh(rect)
3434
```
3535
If you want to set the `nvertices` argument, you need to wrap your primitive in a `Tesselation`

src/GeometryBasics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export uv_mesh, normal_mesh, uv_normal_mesh
6363
export height, origin, radius, width, widths, xwidth, yheight
6464
export HyperSphere, Circle, Sphere
6565
export Cylinder, Cylinder2, Cylinder3, Pyramid, extremity
66-
export HyperRectangle, Rect, Rect2D, Rect3D, IRect, IRect2D, IRect3D, FRect, FRect2D, FRect3D
66+
export HyperRectangle, Rect, Rect2, Rect3, Recti, Rect2i, Rect3i, Rectf, Rect2f, Rect3f
6767
export before, during, isinside, isoutside, meets, overlaps, intersects, finishes
6868
export centered, direction, area, volume, update
6969
export max_dist_dim, max_euclidean, max_euclideansq, min_dist_dim, min_euclidean

src/deprecated.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ for i in 1:4
1717
@deprecate_binding $oldname $newname
1818
end
1919
end
20+
21+
# Rect types
22+
@deprecate_binding Rect2D Rect2
23+
@deprecate_binding Rect3D Rect3
24+
@deprecate_binding FRect Rectf
25+
@deprecate_binding FRect2D Rect2f
26+
@deprecate_binding FRect3D Rect3f
27+
@deprecate_binding IRect Recti
28+
@deprecate_binding IRect2D Rect2i
29+
@deprecate_binding IRect3D Rect3i
30+
@deprecate_binding TRect RectT

src/interfaces.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ length(coordinates(m1)) != length(coordinates(m2))
5050
```
5151
For grid based tesselation, you can also use a tuple:
5252
```julia
53-
rect = Rect2D(0, 0, 1, 1)
53+
rect = Rect2(0, 0, 1, 1)
5454
Tesselation(rect, (5, 5))
5555
"""
5656
struct Tesselation{Dim,T,Primitive,NGrid}

src/precompile.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function _precompile_()
2222
@warnpcfail precompile(Tuple{typeof(decompose),Type{Point{2, Float32}},HyperRectangle{2, Float32}}) # time: 0.026609203
2323
@warnpcfail precompile(Tuple{Type{HyperRectangle{3, Float32}},HyperRectangle{2, Float32}}) # time: 0.023717888
2424
@warnpcfail precompile(Tuple{typeof(+),HyperRectangle{3, Float32},Point{3, Float32}}) # time: 0.006633118
25-
@warnpcfail precompile(Tuple{Type{Rect2D{T} where T},Float32,Float32,Float32,Float32}) # time: 0.001636267
25+
@warnpcfail precompile(Tuple{Type{Rect2{T} where T},Float32,Float32,Float32,Float32}) # time: 0.001636267
2626
@warnpcfail precompile(Tuple{typeof(*),HyperRectangle{2, Float32},Float32}) # time: 0.001057589
2727

2828
if Base.VERSION >= v"1.6.0-DEV.1083"

src/primitives/rectangles.jl

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ end
1515
# Constructors & typealiases
1616

1717
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}
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

3030
Rect() = Rect{2,Float32}()
3131

32-
TRect{T}() where {T} = Rect{2,T}()
32+
RectT{T}() where {T} = Rect{2,T}()
3333

3434
Rect{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))
4949
end
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)
8585
end
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
#=
9090
From different args
9191
=#
9292
function (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...)
9595
end
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...)
100100
end
101101

102102
function (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))
105105
end
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))
110110
end
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))
114114
end
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))
118118
end
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))
122122
end
123123

124124
function Rect{N,T}(a::GeometryPrimitive) where {N,T}
125125
return Rect{N,T}(Vec{N,T}(minimum(a)), Vec{N,T}(widths(a)))
126126
end
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)
130130
end
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...)
134134
end
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)
138138
end
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...)
142142
end
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)
147147
end
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))
151151
end
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]...))
156156
end
157157

158158
origin(prim::Rect) = prim.origin
@@ -165,7 +165,7 @@ width(prim::Rect) = prim.widths[1]
165165
height(prim::Rect) = prim.widths[2]
166166

167167
volume(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})
279279
end
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)
515515
centered(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)))
525525
end
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))
531531
end
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))
536536
end
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))
540540
end
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)
553553
end
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))
557557
end
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),]
562562
end

test/geometrytypes.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ using Test, GeometryBasics
7777
@test m isa GLNormalMesh
7878

7979
muv = uv_mesh(s)
80-
@test Rect(Point.(texturecoordinates(muv))) == FRect2D(Vec2f(0), Vec2f(1.0))
80+
@test Rect(Point.(texturecoordinates(muv))) == Rect2f(Vec2f(0), Vec2f(1.0))
8181
end
8282
end
8383

@@ -134,7 +134,7 @@ end
134134
(0.0, -1.0, 0.0), (0.0, -1.0, 0.0), (0.0, -1.0, 0.0),
135135
(0.0, -1.0, 0.0),]
136136
n32 = map(Vec{3,Float32}, n64)
137-
r = triangle_mesh(centered(Rect3D))
137+
r = triangle_mesh(centered(Rect3))
138138
# @test normals(coordinates(r), GeometryBasics.faces(r)) == n32
139139
# @test normals(coordinates(r), GeometryBasics.faces(r)) == n64
140140
end
@@ -164,31 +164,31 @@ end
164164
end
165165

166166
@testset "Rectangles" begin
167-
rect = FRect2D(0, 7, 20, 3)
168-
@test (rect + 4) == FRect2D(4, 11, 20, 3)
169-
@test (rect + Vec(2, -2)) == FRect2D(2, 5, 20, 3)
167+
rect = Rect2f(0, 7, 20, 3)
168+
@test (rect + 4) == Rect2f(4, 11, 20, 3)
169+
@test (rect + Vec(2, -2)) == Rect2f(2, 5, 20, 3)
170170

171-
@test (rect - 4) == FRect2D(-4, 3, 20, 3)
172-
@test (rect - Vec(2, -2)) == FRect2D(-2, 9, 20, 3)
171+
@test (rect - 4) == Rect2f(-4, 3, 20, 3)
172+
@test (rect - Vec(2, -2)) == Rect2f(-2, 9, 20, 3)
173173

174174
base = Vec3f(1, 2, 3)
175175
wxyz = Vec3f(-2, 4, 2)
176-
rect = FRect3D(base, wxyz)
177-
@test (rect + 4) == FRect3D(base .+ 4, wxyz)
178-
@test (rect + Vec(2, -2, 3)) == FRect3D(base .+ Vec(2, -2, 3), wxyz)
176+
rect = Rect3f(base, wxyz)
177+
@test (rect + 4) == Rect3f(base .+ 4, wxyz)
178+
@test (rect + Vec(2, -2, 3)) == Rect3f(base .+ Vec(2, -2, 3), wxyz)
179179

180-
@test (rect - 4) == FRect3D(base .- 4, wxyz)
181-
@test (rect - Vec(2, -2, 7)) == FRect3D(base .- Vec(2, -2, 7), wxyz)
180+
@test (rect - 4) == Rect3f(base .- 4, wxyz)
181+
@test (rect - Vec(2, -2, 7)) == Rect3f(base .- Vec(2, -2, 7), wxyz)
182182

183-
rect = FRect2D(0, 7, 20, 3)
184-
@test (rect * 4) == FRect2D(0, 7 * 4, 20 * 4, 3 * 4)
185-
@test (rect * Vec(2, -2)) == FRect2D(0, -7 * 2, 20 * 2, -3 * 2)
183+
rect = Rect2f(0, 7, 20, 3)
184+
@test (rect * 4) == Rect2f(0, 7 * 4, 20 * 4, 3 * 4)
185+
@test (rect * Vec(2, -2)) == Rect2f(0, -7 * 2, 20 * 2, -3 * 2)
186186

187187
base = Vec3f(1, 2, 3)
188188
wxyz = Vec3f(-2, 4, 2)
189-
rect = FRect3D(base, wxyz)
190-
@test (rect * 4) == FRect3D(base .* 4, wxyz .* 4)
191-
@test (rect * Vec(2, -2, 3)) == FRect3D(base .* Vec(2, -2, 3), wxyz .* Vec(2, -2, 3))
189+
rect = Rect3f(base, wxyz)
190+
@test (rect * 4) == Rect3f(base .* 4, wxyz .* 4)
191+
@test (rect * Vec(2, -2, 3)) == Rect3f(base .* Vec(2, -2, 3), wxyz .* Vec(2, -2, 3))
192192

193193
rect1 = Rect(Vec(0.0, 0.0), Vec(1.0, 2.0))
194194
rect2 = Rect(0.0, 0.0, 1.0, 2.0)
@@ -208,8 +208,8 @@ end
208208
@test width(prim) == 1.0
209209
@test height(prim) == 1.0
210210

211-
b1 = Rect2D(0.0, 0.0, 2.0, 2.0)
212-
b2 = Rect2D(0, 0, 2, 2)
211+
b1 = Rect2(0.0, 0.0, 2.0, 2.0)
212+
b2 = Rect2(0, 0, 2, 2)
213213
@test isequal(b1, b2)
214214

215215
pt = Point(1.0, 1.0)

0 commit comments

Comments
 (0)