Skip to content

Commit

Permalink
fix direction in alternative Line constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jul 11, 2024
1 parent 2db5953 commit 8ad268d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Sets/Line/Line.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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])
```
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions test/Sets/Line.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]

Expand Down

0 comments on commit 8ad268d

Please sign in to comment.