Skip to content

Commit

Permalink
check dimensionality in Tetrahedron constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Dec 1, 2024
1 parent fd7ca92 commit 12cc7bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Sets/Tetrahedron/Tetrahedron.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Tetrahedron{N, VN<:AbstractVector{N}, VT<:AbstractVector{VN}} <: AbstractPolytope{N}
Type that represents a tetrahedron in vertex representation.
Type that represents a (3-dimensional) tetrahedron in vertex representation.
### Fields
Expand Down Expand Up @@ -35,6 +35,7 @@ struct Tetrahedron{N,VN<:AbstractVector{N},VT<:AbstractVector{VN}} <: AbstractPo

function Tetrahedron(vertices::VT) where {N,VN<:AbstractVector{N},VT<:AbstractVector{VN}}
@assert length(vertices) == 4 "a tetrahedron requires four vertices"
@assert all(v -> length(v) == 3, vertices) "a tetrahedron requires 3D vertices"
return new{N,VN,VT}(vertices)
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/Sets/Tetrahedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ for N in [Float64, Float32, Rational{Int}]
T = Tetrahedron(vertices)
@test eltype(T) == N
@test dim(T) == 3
@test_throws AssertionError Tetrahedron([vertices[1]])
@test_throws AssertionError Tetrahedron([N[1], N[2], N[3], N[4]])

vmat = reduce(hcat, vertices)
Tmat = Tetrahedron(vmat)
Expand Down

0 comments on commit 12cc7bd

Please sign in to comment.