121
121
@test constructor (Vec2 (1 ,2 ),3 ,4.0 ) == expected_rect (constructor, Point (1 ,2 ), Vec (3 ,4.0 ))
122
122
@test constructor ((1 ,2 ),Point2 (3 ,4 )) == expected_rect (constructor, Point (1 ,2 ), Vec (3 ,4 ))
123
123
@test constructor (1.0 ,2 ,Vec2 (3 ,4 )) == expected_rect (constructor, Point (1 ,2 ), Vec (3 ,4 ))
124
+ @test_throws ArgumentError constructor (1 ,2 ,3 )
124
125
end
125
126
end
126
127
end
135
136
@test constructor (Vec3 (1 ,2 ,3 ),4 ,5 ,6 ) == expected_rect (constructor, Point3 (1 ,2 ,3 ), Vec (4 ,5 ,6 ))
136
137
@test constructor ((1 ,2 ,3 ),Point3 (4 ,5 ,6 )) == expected_rect (constructor, Point (1 ,2 ,3 ), Vec (4 ,5 ,6 ))
137
138
@test constructor (Vec3 (1 ,2 ,3 ),4 ,5 ,6 ) == expected_rect (constructor, Point (1 ,2 ,3 ), Vec (4 ,5 ,6 ))
139
+ @test_throws ArgumentError constructor (1 ,2 ,3 )
138
140
end
139
141
end
140
142
end
152
154
@test Rect2 (((1 , 2 ), 3 , 4 )) == Rect2f ((1 ,2 ), 3 , 4 )
153
155
@test Rect ((1 , 2 , 3 , 4 )) == Rect2f (1 , 2 , 3 , 4 )
154
156
@test Rect2 ((x = 1 , y = 2 ), (width = 3 , height = 4 )) == Rect2f (1 , 2 , 3 , 4 )
157
+
158
+ for constructor in [Rect, RectT, Rect2, Rect{2 }, RectT{Float32},
159
+ Rect2f, Rect{2 , Float16}, Rect2{Float16}, RectT{Float64, 2 }]
160
+ @test centered (constructor) == constructor (Point2d (- 0.5 ), Vec2d (1 ))
161
+ end
162
+ for constructor in [Rect3, Rect{3 }, Rect3d, Rect{3 , Float16}, Rect3{Float64}, RectT{Float32, 3 }]
163
+ @test centered (constructor) == constructor (Point3d (- 0.5 ), Vec3d (1 ))
164
+ end
155
165
end
156
166
157
167
# TODO : test/check for Rect(::GeometryPrimitive) for all primitives
306
316
@test widths (split1) == widths (split2)
307
317
@test origin (split1) == Vec (0 , 0 )
308
318
@test origin (split2) == Vec (0 , 1 )
309
- @test in (split1, rect1)
310
- @test ! in (rect1, split1)
319
+ @test in (split1, rect1) && in (split2, rect1)
320
+ @test ! (in (rect1, split1) || in (rect1, split2))
321
+
322
+ rect1 = Rect (Vec (0.0 , 0.0 , - 1.0 ), Vec (1.0 , 2.0 , 1.0 ))
323
+ split1, split2 = GeometryBasics. split (rect1, 1 , 0.75 )
324
+ @test widths (split1) == Vec (0.75 , 2 , 1 )
325
+ @test widths (split2) == Vec (0.25 , 2 , 1 )
326
+ @test origin (split1) == Vec (0 , 0 , - 1 )
327
+ @test origin (split2) == Vec (0.75 , 0 , - 1 )
328
+ @test in (split1, rect1) && in (split2, rect1)
329
+ @test ! (in (rect1, split1) || in (rect1, split2))
311
330
312
331
prim = Rect (0.0 , 0.0 , 1.0 , 1.0 )
313
332
@test length (prim) == 2
@@ -338,19 +357,33 @@ end
338
357
v = Vec (1.0 , 2.0 )
339
358
@test update (b, v) isa GeometryBasics. HyperRectangle{2 ,Float64}
340
359
341
- p = Vec (5.0 , 4.0 )
342
- rect = Rect (0.0 , 0.0 , 1.0 , 1.0 )
343
- @test min_dist_dim (rect, p, 1 ) == 4.0
344
- @test min_dist_dim (rect, p, 2 ) == 3.0
345
- @test max_dist_dim (rect, p, 1 ) == 5.0
346
- @test max_dist_dim (rect, p, 2 ) == 4.0
347
-
348
- rect1 = Rect (0.0 , 0.0 , 1.0 , 1.0 )
349
- rect2 = Rect (3.0 , 1.0 , 4.0 , 2.0 )
350
- @test min_dist_dim (rect1, rect2, 1 ) == 2.0
351
- @test min_dist_dim (rect1, rect2, 2 ) == 0.0
352
- @test max_dist_dim (rect1, rect2, 1 ) == 7.0
353
- @test max_dist_dim (rect1, rect2, 2 ) == 3.0
360
+ @testset " euclidean distances" begin
361
+ p = Vec (5.0 , 4.0 )
362
+ rect = Rect (0.0 , 0.0 , 1.0 , 1.0 )
363
+ @test min_dist_dim (rect, p, 1 ) == 4.0
364
+ @test min_dist_dim (rect, p, 2 ) == 3.0
365
+ @test max_dist_dim (rect, p, 1 ) == 5.0
366
+ @test max_dist_dim (rect, p, 2 ) == 4.0
367
+ @test minmax_dist_dim (rect, p, 1 ) == (4.0 , 5.0 )
368
+
369
+ rect1 = Rect (0.0 , 0.0 , 1.0 , 1.0 )
370
+ rect2 = Rect (3.0 , 1.0 , 4.0 , 2.0 )
371
+ @test min_dist_dim (rect1, rect2, 1 ) == 2.0
372
+ @test min_dist_dim (rect1, rect2, 2 ) == 0.0
373
+ @test max_dist_dim (rect1, rect2, 1 ) == 7.0
374
+ @test max_dist_dim (rect1, rect2, 2 ) == 3.0
375
+ @test minmax_dist_dim (rect1, rect2, 1 ) == (2.0 , 7.0 )
376
+
377
+ r = Rect2f (- 1 , - 1 , 2 , 3 )
378
+ p = Point2f (1 , 2 ) + Point2f (3 , 4 )
379
+ @test min_euclidean (r, p) == 5f0
380
+ @test max_euclidean (r, p) ≈ sqrt (5 * 5 + 7 * 7 )
381
+
382
+ r2 = Rect2f (0 , 0 , 2 , 3 )
383
+ @test min_euclidean (r, r2) == 0f0
384
+ @test max_euclidean (r, r2) == 5f0
385
+ @test minmax_euclidean (r, r2) == (0f0 , 5f0 )
386
+ end
354
387
355
388
@test ! before (rect1, rect2)
356
389
rect1 = Rect (0.0 , 0.0 , 1.0 , 1.0 )
397
430
rect2 = Rect (Vec (1 , 2 , 3 , 4 ), Vec (5 , 6 , 7 , 8 ))
398
431
@test rect1 == rect2
399
432
400
- @test_throws ArgumentError Rect (1 , 2 , 3 )
401
- end
433
+ @testset " Matrix Multiplications" begin
434
+ r = Rect2f (- 1 , - 2 , 4 , 3 )
435
+
436
+ # TODO : this seems quite dangerous: We pad points with ones which makes
437
+ # sense for translations if we go to D+1, but is nonsense if we
438
+ # go higher dimensions than that.
439
+ M = rand (Mat4f)
440
+ ps = Point2f[M * Point (p... , 1 , 1 ) for p in coordinates (r)]
441
+ @test Rect2f (ps) == M * r
442
+
443
+ M = Mat2f (0.5 , - 0.3 , 0.7 , 1.5 )
444
+ ps = Point2f[M * p for p in coordinates (r)]
445
+ @test Rect2f (ps) == M * r
446
+
447
+ r = Rect3f (- 1 , - 2 , - 3 , 2 , 4 , 1 )
448
+ M = rand (Mat4f)
449
+ ps = Point3f[M * Point (p... , 1 ) for p in coordinates (r)]
450
+ @test Rect3f (ps) == M * r
451
+ end
452
+
453
+ # TODO : this is effectively 0-indexed... should it be?
454
+ M = reshape (collect (11 : 100 ), 10 , 9 )[1 : 9 , :]
455
+ r = Rect2i (2 , 4 , 2 , 4 )
456
+ @test M[r] == [53 63 73 83 ; 54 64 74 84 ]
457
+
458
+ end
0 commit comments