From 151046b3b0b63599cd270d0dbdb153d162d430c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vezy?= Date: Tue, 14 May 2024 14:02:50 +0200 Subject: [PATCH] Correct issue with what is expected by Meshes.normal --- src/helpers.jl | 2 +- test/runtests.jl | 4 ++++ test/test-refmesh.jl | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/test-refmesh.jl diff --git a/src/helpers.jl b/src/helpers.jl index 8173328..e314dbe 100644 --- a/src/helpers.jl +++ b/src/helpers.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 1c63c3f..c258c30 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 diff --git a/test/test-refmesh.jl b/test/test-refmesh.jl new file mode 100644 index 0000000..dd83ecb --- /dev/null +++ b/test/test-refmesh.jl @@ -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 \ No newline at end of file