diff --git a/src/Sets/Line2D.jl b/src/Sets/Line2D.jl index eaa29574d2..7f1a15e027 100644 --- a/src/Sets/Line2D.jl +++ b/src/Sets/Line2D.jl @@ -24,37 +24,15 @@ The line ``y = -x + 1``: julia> Line2D([1., 1.], 1.) Line2D{Float64, Vector{Float64}}([1.0, 1.0], 1.0) ``` -""" -struct Line2D{N,VN<:AbstractVector{N}} <: AbstractPolyhedron{N} - a::VN - b::N - - # default constructor with length constraint - function Line2D(a::VN, b::N) where {N,VN<:AbstractVector{N}} - @assert length(a) == 2 "a Line2D must be two-dimensional" - @assert !iszero(a) "a line needs a non-zero normal vector" - return new{N,VN}(a, b) - end -end - -isoperationtype(::Type{<:Line2D}) = false - -# constructor from a HalfSpace -Line2D(c::HalfSpace) = Line2D(c.a, c.b) - -""" - Line2D(p::AbstractVector, q::AbstractVector) - -Constructor of a 2D line from two points. - -### Input -- `p` -- point in 2D -- `q` -- another point in 2D +The alternative constructor takes two 2D points (`AbstractVector`s) `p` and `q` +and creates a canonical line from `p` to `q`. See the algorithm section below +for details. -### Output - -The line which passes through `p` and `q`. +```jldoctest +julia> Line2D([1., 1.], [2., 2]) +Line2D{Float64, Vector{Float64}}([-1.0, 1.0], 0.0) +``` ### Algorithm @@ -67,6 +45,18 @@ through these points is The particular case ``x₂ = x₁`` defines a line parallel to the ``y``-axis (vertical line). """ +struct Line2D{N,VN<:AbstractVector{N}} <: AbstractPolyhedron{N} + a::VN + b::N + + # default constructor with length constraint + function Line2D(a::VN, b::N) where {N,VN<:AbstractVector{N}} + @assert length(a) == 2 "a Line2D must be two-dimensional" + @assert !iszero(a) "a line needs a non-zero normal vector" + return new{N,VN}(a, b) + end +end + function Line2D(p::AbstractVector, q::AbstractVector) @assert length(p) == length(q) == 2 "a Line2D must be two-dimensional" @@ -78,7 +68,7 @@ function Line2D(p::AbstractVector, q::AbstractVector) @assert y₁ != y₂ "a line needs two distinct points" a = [one(N), zero(N)] b = x₁ - return LazySets.Line2D(a, b) + return Line2D(a, b) end k = (y₁ - y₂) / (x₂ - x₁) @@ -87,6 +77,11 @@ function Line2D(p::AbstractVector, q::AbstractVector) return Line2D(a, b) end +isoperationtype(::Type{<:Line2D}) = false + +# constructor from a HalfSpace +Line2D(c::HalfSpace) = Line2D(c.a, c.b) + """ constraints_list(L::Line2D)