|
352 | 352 |
|
353 | 353 | t = (Point3f(0), Point3f(1,0,1), Point3f(0,1,0))
|
354 | 354 | @test GeometryBasics.orthogonal_vector(t) == Vec3f(-1,0,1)
|
355 |
| - @test GeometryBasics.orthogonal_vector(Vec3i, t) == Vec3i(-1,0,1)# |
| 355 | + @test GeometryBasics.orthogonal_vector(Vec3i, t) == Vec3i(-1,0,1) |
| 356 | + |
| 357 | + t = Point2f[(0,0), (1,0), (2,1), (1,2), (0,2), (-1, 1)] |
| 358 | + @test GeometryBasics.orthogonal_vector(Vec3f, t) == Vec3f(0,0,8) |
| 359 | + |
| 360 | + # Makie uses this syntax |
| 361 | + @test GeometryBasics.orthogonal_vector(Point3f(0), Point3f(1,0,1), Point3f(0,1,0)) == Vec3f(-1,0,1) |
| 362 | + @test GeometryBasics.orthogonal_vector((1,2,3), (2,3,1), (3,1,2)) == Vec3f(-3.0) |
356 | 363 |
|
357 | 364 | # Maybe the ::Any fallback is too generic...?
|
358 | 365 | struct TestType
|
|
361 | 368 | GeometryBasics.coordinates(x::TestType) = x.data
|
362 | 369 | x = TestType([Point3f(1,1,1), Point3f(0,0,0), Point3f(0.5,0,0)])
|
363 | 370 | @test GeometryBasics.orthogonal_vector(x) == Vec3f(0, -0.5, 0.5)
|
| 371 | + |
| 372 | + @testset "Float Precision" begin |
| 373 | + # Collection of risky triangles |
| 374 | + tris = [ |
| 375 | + # with 0s that remove terms from cross(a-b, c-b) |
| 376 | + (Point3f(-10.180012, 9.928894, 63.42825), Point3f(-10.180012, 9.92804, 63.424137), Point3f(-10.181978, 9.92804, 63.42825)), |
| 377 | + (Point3f(-11.75692, 6.245064, 86.05223), Point3f(-11.758429, 6.245064, 86.048584), Point3f(-11.758429, 6.2428894, 86.05223)), |
| 378 | + (Point3f(52.430557, 13.611008, 7.657501), Point3f(52.43055, 13.611008, 7.6574783), Point3f(52.43055, 13.611008, 7.657501)), |
| 379 | + (Point3f(52.430557, 13.611008, 7.657501), Point3f(52.43055, 13.611008, 7.657501), Point3f(52.45581, 13.61525, 8.18364)), |
| 380 | + # tiny shift |
| 381 | + (Point3f(1, 1 + 1e-4, 1), Point3f(1 + 1e-4, 1 + 1e-4, 1 - 1e-4), Point3f(1 - 1e-4, 1, 1 + 1e-4)) |
| 382 | + ] |
| 383 | + |
| 384 | + for tri in tris |
| 385 | + a, b, c = tri |
| 386 | + n64 = Vec3f(cross(Point3d(b) - Point3d(a), Point3d(c) - Point3d(a))) |
| 387 | + # fast paths |
| 388 | + n_fast = GeometryBasics.orthogonal_vector(Vec3f, Triangle(a, b, c)) |
| 389 | + @test n64 ≈ n_fast |
| 390 | + @test n_fast == GeometryBasics.orthogonal_vector(Vec3f, (a, b, c)) |
| 391 | + @test n_fast == GeometryBasics.orthogonal_vector(Vec3f, GeometryBasics.SVector(a, b, c)) # hit by points[face] |
| 392 | + n_slow = GeometryBasics.orthogonal_vector(Vec3f, TestType([a, b, c])) |
| 393 | + @test n_slow ≈ n64 |
| 394 | + @test n_slow == GeometryBasics.orthogonal_vector(Vec3f, [a, b, c]) |
| 395 | + end |
| 396 | + end |
364 | 397 | end
|
365 | 398 |
|
366 | 399 | @testset "Normals" begin
|
|
0 commit comments