Skip to content

Commit

Permalink
Implement a parametrization function for Frustum (#1164)
Browse files Browse the repository at this point in the history
* Implement parametrization function for Frustum

* Add tests

* Fix coords

* Add a test_throws

* Update name
  • Loading branch information
mikeingold authored Jan 20, 2025
1 parent 0d27187 commit 961f51d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/geometries/primitives/frustum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ axis(f::Frustum) = axis(boundary(f))

Base.isapprox(f₁::Frustum, f₂::Frustum; atol=atol(lentype(f₁)), kwargs...) =
isapprox(boundary(f₁), boundary(f₂); atol, kwargs...)

function (frustum::Frustum)(r, φ, h)
if (r < 0 || r > 1) ||< 0 || φ > 1) || (h < 0 || h > 1)
throw(DomainError((r, φ, h), "frustum(r, φ, h) is not defined for r, φ, h outside [0, 1]³."))
end
a = bottom(frustum)(r, φ)
b = top(frustum)(r, φ)
Segment(a, b)(h)
end
5 changes: 5 additions & 0 deletions test/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,11 @@ end
@test crs(f) <: Cartesian{NoDatum}
@test Meshes.lentype(f) ==
@test boundary(f) == FrustumSurface(db, dt)
@test f(T(0), T(0), T(0)) == center(db)
@test norm(f(T(1), T(0), T(0)) - f(T(0), T(0), T(0))) radius(db)
@test f(T(0), T(0), T(1)) == center(dt)
@test norm(f(T(1), T(0), T(1)) - f(T(0), T(0), T(1))) radius(dt)
@test_throws DomainError f(T(0), T(0), T(1.5))

@test_throws AssertionError Frustum(db, db)

Expand Down

0 comments on commit 961f51d

Please sign in to comment.