From 0d271879fd7a10f94a606ca0c6f5a929b34fff55 Mon Sep 17 00:00:00 2001 From: Michael Ingold Date: Mon, 20 Jan 2025 15:27:04 -0500 Subject: [PATCH] Implement a parametrization function for `Pyramid` (#1163) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add parametrization for Pyramid * Add tests * Fix tests * Simplify code --------- Co-authored-by: Júlio Hoffimann --- src/geometries/polytopes/pyramid.jl | 10 ++++++++++ test/polytopes.jl | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/geometries/polytopes/pyramid.jl b/src/geometries/polytopes/pyramid.jl index ad7f9c79c..d478658f9 100644 --- a/src/geometries/polytopes/pyramid.jl +++ b/src/geometries/polytopes/pyramid.jl @@ -15,3 +15,13 @@ nvertices(::Type{<:Pyramid}) = 5 Base.isapprox(p₁::Pyramid, p₂::Pyramid; atol=atol(lentype(p₁)), kwargs...) = all(isapprox(v₁, v₂; atol, kwargs...) for (v₁, v₂) in zip(p₁.vertices, p₂.vertices)) + +function (pyramid::Pyramid)(u, v, w) + if (u < 0 || u > 1) || (v < 0 || v > 1) || (w < 0 || w > 1) + throw(DomainError((u, v, w), "pyramid(u, v, w) is not defined for u, v, w outside [0, 1]³.")) + end + a, b, c, d, o = vertices(pyramid) + q = Quadrangle(a, b, c, d) + s = Segment(q(u, v), o) + s(w) +end diff --git a/test/polytopes.jl b/test/polytopes.jl index 3e5da0c4a..4e6138057 100644 --- a/test/polytopes.jl +++ b/test/polytopes.jl @@ -939,6 +939,9 @@ end @test crs(p) <: Cartesian{NoDatum} @test Meshes.lentype(p) == ℳ @test volume(p) ≈ T(1 / 3) * u"m^3" + @test p(T(1), T(1), T(0)) == vertices(p)[3] + @test p(T(0), T(0), T(1)) == vertices(p)[5] + @test_throws DomainError p(T(0), T(0), T(1.5)) m = boundary(p) @test m isa Mesh @test nelements(m) == 5