Skip to content

Commit

Permalink
Added tests for edgecrossproduct
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin-Mattheus-Moerman committed Mar 20, 2024
1 parent 893b2a4 commit b2e2850
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b2e2850

Please sign in to comment.