Skip to content

Commit 358d4d1

Browse files
committed
explicitly test Rect getters/utility functions
1 parent e33ff0c commit 358d4d1

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

test/geometrytypes.jl

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ end
164164
end
165165
end
166166

167-
# TODO: test/check for Rect(::GeometryPrimitive) for all primitives
168167
@testset "Boundingbox-like" begin
169168
for constructor in [Rect, Rect{2}, Rect{2, Float32}, Rect3f]
170169
@test constructor(Circle(Point2f(0), 1f0)) == constructor(Point2f(-1, -1), Vec2f(2, 2))
@@ -183,19 +182,46 @@ end
183182
end
184183
end
185184

186-
# TODO: origin, minimum, maximum, width, height, widths, area, volume with empty constructed Rects
187-
188-
a = Rect(Vec(0, 0), Vec(1, 1))
189-
pt_expa = Point{2,Int}[(0, 0), (1, 0), (1, 1), (0, 1)]
185+
# TODO: These don't really make sense...
186+
r = Rect2f()
187+
@test origin(r) == Vec(Inf, Inf)
188+
@test minimum(r) == Vec(Inf, Inf)
189+
@test isnan(maximum(r))
190+
@test width(r) == -Inf
191+
@test height(r) == -Inf
192+
@test widths(r) == Vec(-Inf, -Inf)
193+
@test area(r) == Inf
194+
@test volume(r) == Inf
195+
196+
a = Rect(Vec(0, 1), Vec(2, 3))
197+
pt_expa = Point{2,Int}[(0, 1), (2, 1), (2, 4), (0, 4)]
190198
@test decompose(Point{2,Int}, a) == pt_expa
191199
mesh = normal_mesh(a)
192200
@test decompose(Point2f, mesh) == pt_expa
193201

194-
b = Rect(Vec(1, 1, 1), Vec(1, 1, 1))
195-
pt_expb = Point{3,Int64}[[1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 2, 2],
196-
[2, 1, 1], [2, 1, 2], [2, 2, 1], [2, 2, 2]]
202+
@test origin(a) == Vec(0,1)
203+
@test minimum(a) == Vec(0,1)
204+
@test maximum(a) == Vec(2,4)
205+
@test width(a) == 2
206+
@test height(a) == 3
207+
@test widths(a) == Vec(2,3)
208+
@test area(a) == 2*3
209+
@test volume(a) == 2*3
210+
211+
b = Rect(Vec(1, 2, 3), Vec(4, 5, 6))
212+
pt_expb = Point{3, Int64}[[1, 2, 3], [1, 2, 9], [1, 7, 3], [1, 7, 9],
213+
[5, 2, 3], [5, 2, 9], [5, 7, 3], [5, 7, 9]]
197214
@test decompose(Point{3,Int}, b) == pt_expb
198215

216+
@test origin(b) == Vec(1,2,3)
217+
@test minimum(b) == Vec(1,2,3)
218+
@test maximum(b) == Vec(5,7,9)
219+
@test width(b) == 4
220+
@test height(b) == 5
221+
@test widths(b) == Vec(4,5,6)
222+
@test_throws MethodError area(b)
223+
@test volume(b) == 4*5*6
224+
199225
mesh = normal_mesh(b)
200226
@test faces(mesh) == GLTriangleFace[
201227
(1, 2, 4), (1, 4, 3), (7, 8, 6), (7, 6, 5), (5, 6, 2), (5, 2, 1),

test/polygons.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
p2 = Polygon(OffsetArray(exterior, 0), interiors)
1616
@test p2 == p1
1717

18-
# TODO: promote polygon type automatically
18+
# TODO: promote polygon type automatically when creating MultiPolygon
1919
polygon = Polygon(Point2f.(points))
2020
mp = MultiPolygon([polygon, p1, p2])
2121
@test mp.polygons == [polygon, p1, p2]

0 commit comments

Comments
 (0)