Skip to content

Commit 34160dc

Browse files
committed
add basic tests for orthogonal_vector paths
1 parent a18eef4 commit 34160dc

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/geometry_primitives.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ end
165165

166166
# derive target type
167167
orthogonal_vector(vertices::Ngon{D, T}) where {D, T} = orthogonal_vector(Vec3{T}, vertices)
168+
function orthogonal_vector(vertices::NTuple{N, VT}) where {N, D, T, VT <: VecTypes{D, T}}
169+
return orthogonal_vector(Vec3{T}, vertices)
170+
end
168171
function orthogonal_vector(vertices::AbstractArray{VT}) where {D, T, VT <: VecTypes{D, T}}
169172
return orthogonal_vector(Vec3{T}, vertices)
170173
end

test/geometrytypes.jl

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,16 @@ end
332332
@test length(fv) == 5
333333
end
334334

335+
@testset "orthogonal_vector" begin
336+
tri = Triangle(Point3d(0,0,0), Point3d(1,0,0), Point3d(0,1,0))
337+
@test GeometryBasics.orthogonal_vector(tri) == Vec3d(0,0,1)
338+
@test GeometryBasics.orthogonal_vector(collect(coordinates(tri))) == Vec3d(0,0,1)
339+
340+
quad = GeometryBasics.Quadrilateral(Point2i(0,0), Point2i(1,0), Point2i(1,1), Point2i(0,1))
341+
@test GeometryBasics.orthogonal_vector(quad) == Vec3i(0,0,2)
342+
@test GeometryBasics.orthogonal_vector(collect(coordinates(quad))) == Vec3i(0,0,2)
343+
end
344+
335345
@testset "Normals" begin
336346
# per face normals
337347
r = Rect3f(Point3f(0), Vec3f(1))
@@ -358,19 +368,19 @@ end
358368
@test values(ns)[1:15] v_ns[1:15]
359369
@test values(ns)[1:15] v_ns[16:30] # repeated via FaceView in ns
360370

361-
# Planar QuadFace with colinear edge
362-
v = [Point{3,Float64}(0.0,0.0,0.0),Point{3,Float64}(1.0,0.0,0.0),Point{3,Float64}(2.0,0.0,0.0),Point{3,Float64}(2.0,1.0,0.0)]
371+
# Planar QuadFace with colinear edge
372+
v = [Point3d(0,0,0),Point3d(1,0,0),Point3d(2,0,0),Point3d(2,1,0)]
363373
f = [QuadFace{Int}(1,2,3,4)]
364374
n = normals(v,f)
365375
@test all(n_i -> n_i [0.0,0.0,1.0], n)
366376

367-
# Planar NgonFace (5-sided) with colinear edge
368-
v = [Point{3,Float64}(0.0,0.0,0.0),Point{3,Float64}(1.0,0.0,0.0),Point{3,Float64}(2.0,0.0,0.0),Point{3,Float64}(2.0,1.0,0.0),Point{3,Float64}(2.0,0.5,0.0)]
377+
# Planar NgonFace (5-sided) with colinear edge
378+
v = [Point3d(0,0,0),Point3d(1,0,0),Point3d(2,0,0),Point3d(2,1,0),Point3d(2,0.5,0)]
369379
f = [NgonFace{5,Int}(1,2,3,4,5)]
370380
n = normals(v,f)
371381
@test all(n_i -> n_i [0.0,0.0,1.0], n)
372382

373-
# Non-planar NgonFace (6 sided), features equal up and down variations resulting in z-dir average face_normal
383+
# Non-planar NgonFace (6 sided), features equal up and down variations resulting in z-dir average face_normal
374384
t = range(0.0,2*pi-(2*pi)/6,6)
375385
v = [Point{3,Float64}(cos(t[i]),sin(t[i]),iseven(i)) for i in eachindex(t)]
376386
f = [NgonFace{6,Int}(1,2,3,4,5,6)]

0 commit comments

Comments
 (0)