Skip to content

Commit

Permalink
Correct issue with what is expected by Meshes.normal
Browse files Browse the repository at this point in the history
  • Loading branch information
VEZY committed May 14, 2024
1 parent 2889d75 commit 151046b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ end
function normals_vertex(mesh::Meshes.SimpleMesh)
vertex_normals = fill(Meshes.Point3(0.0, 0.0, 0.0), Meshes.nvertices(mesh))
for (i, tri) in enumerate(Meshes.topology(mesh).connec)
tri_norm = Meshes.normal(Meshes.Triangle(mesh.vertices[[tri.indices...]]))
tri_norm = Meshes.normal(Meshes.Triangle(mesh.vertices[[tri.indices...]]...))
vertex_normals[tri.indices[1]] = tri_norm
vertex_normals[tri.indices[2]] = tri_norm
vertex_normals[tri.indices[3]] = tri_norm
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ using CairoMakie
# Update the reference plots (do only when you know awhat you are doing!):
# include("makes_references.jl")

@testset "Read OPF" begin
include("test-refmesh.jl")
end

@testset "Read OPF" begin
include("test-read_opf.jl")
end
Expand Down
18 changes: 18 additions & 0 deletions test/test-refmesh.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

panel_dimensions = [100.0, 1000.0]
panel_points = Meshes.Point.([(0.0, 0.0, 0.0), (0.0, panel_dimensions[2], 0.0), (panel_dimensions..., 0.0), (panel_dimensions[1], 0.0, 0.0)])
# connect the points into N-gon
panel_connec = connect.([(1, 2, 3), (3, 4, 1)], Ngon)
# 3D mesh made of N-gon elements
panel_mesh = SimpleMesh(panel_points, panel_connec)

@testset "RefMesh" begin
refmesh = @test_nowarn PlantGeom.RefMesh("Panel", panel_mesh)
@test Meshes.nvertices(refmesh) == 4
@test Meshes.nelements(refmesh) == 2
@test refmesh.material == RGB(220 / 255, 220 / 255, 220 / 255)
@test refmesh.mesh == panel_mesh
@test refmesh.normals == PlantGeom.normals_vertex(refmesh)
@test refmesh.taper == false
@test isnothing(refmesh.texture_coords)
end

0 comments on commit 151046b

Please sign in to comment.