diff --git a/src/Sets/HalfSpace/distance.jl b/src/Sets/HalfSpace/distance.jl index 642d6e1726..d6df9f2abd 100644 --- a/src/Sets/HalfSpace/distance.jl +++ b/src/Sets/HalfSpace/distance.jl @@ -1,4 +1,6 @@ @commutative function distance(x::AbstractVector, H::HalfSpace; p::Real=2) + @assert length(x) == dim(H) "incompatible dimensions $(length(x)) and $(dim(H))" + if p != 2 throw(ArgumentError("`distance` is only implemented for Euclidean norm")) end diff --git a/src/Sets/Hyperplane/distance.jl b/src/Sets/Hyperplane/distance.jl index 72c6bb1b1e..436e3d3b82 100644 --- a/src/Sets/Hyperplane/distance.jl +++ b/src/Sets/Hyperplane/distance.jl @@ -1,4 +1,6 @@ @commutative function distance(x::AbstractVector, H::Hyperplane; p::Real=2) + @assert length(x) == dim(H) "incompatible dimensions $(length(x)) and $(dim(H))" + if p != 2 throw(ArgumentError("`distance` is only implemented for Euclidean norm")) end diff --git a/src/Sets/Line/distance.jl b/src/Sets/Line/distance.jl index a513e46e66..9227fffb9a 100644 --- a/src/Sets/Line/distance.jl +++ b/src/Sets/Line/distance.jl @@ -1,4 +1,6 @@ @commutative function distance(x::AbstractVector, L::Line; p::Real=2) + @assert length(x) == dim(L) "incompatible dimensions $(length(x)) and $(dim(L))" + d = L.d # direction of the line t = dot(x - L.p, d) / dot(d, d) return distance(x, L.p + t * d; p=p)