Skip to content

Commit 9869425

Browse files
authored
Merge pull request #3788 from JuliaReach/schillic/distance_line
Fix `distance` of point and `Line`
2 parents 6958ed2 + 778cc09 commit 9869425

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/Sets/Line/distance.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
@commutative function distance(x::AbstractVector, L::Line; p::Real=2)
22
@assert length(x) == dim(L) "incompatible dimensions $(length(x)) and $(dim(L))"
33

4+
if p != 2
5+
throw(ArgumentError("`distance` is only implemented for Euclidean norm"))
6+
end
7+
48
d = L.d # direction of the line
59
t = dot(x - L.p, d) / dot(d, d)
610
return distance(x, L.p + t * d; p=p)

test/Sets/Line.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ for N in [Float64, Rational{Int}, Float32]
6363
@test translate(l2, N[0, 1]) == Line(N[0, 2], N[1, 0])
6464

6565
# distance
66-
distance(N[1, 0], l1) == N(1)
67-
distance(l1, N[1, 0]) == N(1)
68-
distance(Singleton(N[1, 0]), l1) == N(1)
69-
distance(l1, Singleton(N[1, 0])) == N(1)
66+
@test distance(N[1, 0], l1) == N(1)
67+
@test distance(l1, N[1, 0]) == N(1)
68+
@test distance(Singleton(N[1, 0]), l1) == N(1)
69+
@test distance(l1, Singleton(N[1, 0])) == N(1)
70+
@test_throws ArgumentError distance(N[1, 0], l1; p=N(1))
7071

7172
# concrete linear map special case: singleton result
7273
l = Line(N[0, 2], N[1, 0])

0 commit comments

Comments
 (0)