diff --git a/src/Sets/Line/Line.jl b/src/Sets/Line/Line.jl index f3c65b3c0c..3de14f151a 100644 --- a/src/Sets/Line/Line.jl +++ b/src/Sets/Line/Line.jl @@ -38,7 +38,7 @@ arguments, and returns the line through them. See the algorithm section for details. ```jldoctest -julia> Line(from=[-1.0, 2, 3], to=[-4.0, 2, 4]) +julia> Line(from=[-1.0, 2, 3], to=[2.0, 2, 2]) Line{Float64, Vector{Float64}}([-1.0, 2.0, 3.0], [3.0, 0.0, -1.0]) ``` @@ -48,7 +48,7 @@ lines. It takes two inputs, `a` and `b`, and constructs the line such that ```jldoctest julia> Line([2.0, 0], 1.) -Line{Float64, Vector{Float64}}([0.5, 0.0], [0.0, -1.0]) +Line{Float64, Vector{Float64}}([0.5, 0.0], [0.0, 1.0]) ``` ### Algorithm @@ -73,7 +73,7 @@ struct Line{N,VN<:AbstractVector{N}} <: AbstractPolyhedron{N} end function Line(; from::AbstractVector, to::AbstractVector, normalize=false) - d = from - to + d = to - from @assert !iszero(d) "points `$from` and `$to` should be distinct" return Line(from, d; normalize=normalize) end diff --git a/test/Sets/Line.jl b/test/Sets/Line.jl index 42cce2c8e1..2eb5e5e6eb 100644 --- a/test/Sets/Line.jl +++ b/test/Sets/Line.jl @@ -7,6 +7,7 @@ for N in [Float64, Rational{Int}, Float32] # construction l1 = Line(; from=N[0, 1], to=N[1, 1]) # two points on the line l2 = Line(N[0, 1], N[1, 0]) # point and direction + @test l1.p ≈ l2.p && l1.d ≈ l2.d # the lines are the same # construction given a 2d direction and offset ll = Line(N[0, 1], N(1)) # y == 1 @@ -17,9 +18,6 @@ for N in [Float64, Rational{Int}, Float32] @test N[0, 0] ∈ ll && N[1, 1] ∈ ll @test_throws ArgumentError Line(zeros(N, 2), N(0)) - # the lines are the same modulo the sign of the normal vector - @test l1.p ≈ l2.p && l1.d ≈ -l2.d - # direction @test direction(l2) == N[1, 0]