Skip to content

Commit

Permalink
Implement a parametrization function for Pyramid (#1163)
Browse files Browse the repository at this point in the history
* Add parametrization for Pyramid

* Add tests

* Fix tests

* Simplify code

---------

Co-authored-by: Júlio Hoffimann <julio.hoffimann@gmail.com>
  • Loading branch information
mikeingold and juliohm authored Jan 20, 2025
1 parent 58d5b28 commit 0d27187
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/geometries/polytopes/pyramid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions test/polytopes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0d27187

Please sign in to comment.