Skip to content

Commit

Permalink
add assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Dec 29, 2024
1 parent 7b17d2e commit 8eaf91e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Sets/HalfSpace/distance.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Sets/Hyperplane/distance.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Sets/Line/distance.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 8eaf91e

Please sign in to comment.