Skip to content

Commit

Permalink
merge constructor docs to struct docs
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Aug 2, 2023
1 parent 8ea0bd2 commit c31680f
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions src/Sets/Line2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand All @@ -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₁)
Expand All @@ -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)
Expand Down

0 comments on commit c31680f

Please sign in to comment.