From 12cc7bd9acdbd67b4ebbf3b50ab5ae9aef25abea Mon Sep 17 00:00:00 2001 From: schillic Date: Sun, 1 Dec 2024 22:42:16 +0100 Subject: [PATCH] check dimensionality in Tetrahedron constructor --- src/Sets/Tetrahedron/Tetrahedron.jl | 3 ++- test/Sets/Tetrahedron.jl | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Sets/Tetrahedron/Tetrahedron.jl b/src/Sets/Tetrahedron/Tetrahedron.jl index 6003d217ff..df26f89842 100644 --- a/src/Sets/Tetrahedron/Tetrahedron.jl +++ b/src/Sets/Tetrahedron/Tetrahedron.jl @@ -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 @@ -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 diff --git a/test/Sets/Tetrahedron.jl b/test/Sets/Tetrahedron.jl index af27abd8f8..2362053c62 100644 --- a/test/Sets/Tetrahedron.jl +++ b/test/Sets/Tetrahedron.jl @@ -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)