From b2e28506831f2bdec70bb75378817e3c7392e36f Mon Sep 17 00:00:00 2001 From: Kevin-Mattheus-Moerman Date: Wed, 20 Mar 2024 14:41:16 +0000 Subject: [PATCH] Added tests for edgecrossproduct --- src/functions.jl | 3 +-- test/runtests.jl | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/functions.jl b/src/functions.jl index d0ad973..0d8ae5d 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -826,7 +826,7 @@ function cube(r=1.0) # Create vertices s = r/sqrt(3.0) - V=Vector{GeometryBasics.Point{3, Float64}}(undef,8) + V = Vector{GeometryBasics.Point{3, Float64}}(undef,8) V[1 ] = GeometryBasics.Point{3, Float64}( -s, -s, -s) V[2 ] = GeometryBasics.Point{3, Float64}( -s, s, -s) V[3 ] = GeometryBasics.Point{3, Float64}( s, s, -s) @@ -944,7 +944,6 @@ function togeometrybasics_mesh(VM,FM) return GeometryBasics.Mesh(V,F) end - function edgecrossproduct(F,V) C = Vector{GeometryBasics.Vec{3, Float64}}(undef,length(F)) # Allocate array cross-product vectors n = length(F[1]) # Number of nodes per face diff --git a/test/runtests.jl b/test/runtests.jl index b49fbb5..d6e177d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -251,6 +251,50 @@ end end end +@testset "edgecrossproduct" verbose = true begin + @testset "Single triangle" begin + F = [TriangleFace{Int64}(1, 2, 3)] + V = Vector{GeometryBasics.Point{3, Float64}}(undef,3) + V[1] = GeometryBasics.Point{3, Float64}(0.0, 0.0, 0.0) + V[2] = GeometryBasics.Point{3, Float64}(1.0, 0.0, 0.0) + V[3] = GeometryBasics.Point{3, Float64}(1.0, 1.0, 0.0) + C = edgecrossproduct(F,V) + @test C == [Vec3{Float64}(0.0,0.0,0.5)] + end + @testset "Single quad" begin + F = [QuadFace{Int64}(1, 2, 3, 4)] + V = Vector{GeometryBasics.Point{3, Float64}}(undef,4) + V[1] = GeometryBasics.Point{3, Float64}(0.0, 0.0, 0.0) + V[2] = GeometryBasics.Point{3, Float64}(1.0, 0.0, 0.0) + V[3] = GeometryBasics.Point{3, Float64}(1.0, 1.0, 0.0) + V[4] = GeometryBasics.Point{3, Float64}(0.0, 1.0, 0.0) + C = edgecrossproduct(F,V) + @test C == [Vec3{Float64}(0.0,0.0,1.0)] + end + @testset "Triangles" begin + F = [TriangleFace{Int64}(1, 2, 3),TriangleFace{Int64}(1, 4, 3)] + V = Vector{GeometryBasics.Point{3, Float64}}(undef,4) + V[1] = GeometryBasics.Point{3, Float64}(0.0, 0.0, 0.0) + V[2] = GeometryBasics.Point{3, Float64}(1.0, 0.0, 0.0) + V[3] = GeometryBasics.Point{3, Float64}(1.0, 1.0, 0.0) + V[4] = GeometryBasics.Point{3, Float64}(0.0, 1.0, 0.0) + C = edgecrossproduct(F,V) + @test C == [Vec3{Float64}(0.0,0.0,0.5),Vec3{Float64}(0.0,0.0,-0.5)] + end + @testset "Quads" begin + F = [QuadFace{Int64}(1, 2, 3, 4),QuadFace{Int64}(6, 5, 4, 3)] + V = Vector{GeometryBasics.Point{3, Float64}}(undef,6) + V[1] = GeometryBasics.Point{3, Float64}(0.0, 0.0, 0.0) + V[2] = GeometryBasics.Point{3, Float64}(1.0, 0.0, 0.0) + V[3] = GeometryBasics.Point{3, Float64}(1.0, 1.0, 0.0) + V[4] = GeometryBasics.Point{3, Float64}(0.0, 1.0, 0.0) + V[5] = GeometryBasics.Point{3, Float64}(2.0, 0.0, 0.0) + V[6] = GeometryBasics.Point{3, Float64}(2.0, 1.0, 0.0) + C = edgecrossproduct(F,V) + @test C == [Vec3{Float64}(0.0,0.0,1.0),Vec3{Float64}(0.0,0.0,-1.0)] + end +end + @testset "elements2indices" verbose = true begin @testset "Tri. faces" begin F = Vector{TriangleFace{Int64}}(undef, 3)