Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix direction in alternative Line constructor #3567

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading