Skip to content
Merged
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
1 change: 0 additions & 1 deletion docs/src/lib/concrete_binary_operations/intersection.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ intersection(::CartesianProductArray, ::CartesianProductArray)
intersection(::LinearMap, ::LazySet)
intersection(::Union{CartesianProduct,CartesianProductArray}, ::AbstractPolyhedron)
intersection(::LineSegment, ::Line2D)
intersection(::LineSegment, ::LineSegment)
intersection(::AbstractZonotope{N}, ::HalfSpace{N}) where {N}
intersection(::Star, ::HalfSpace)
intersection!(::Star, ::HalfSpace)
Expand Down
80 changes: 64 additions & 16 deletions docs/src/lib/sets/LineSegment.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,95 @@
```@meta
CurrentModule = LazySets
CurrentModule = LazySets.LineSegmentModule
```

# [Line segment (LineSegment)](@id def_LineSegment)

```@docs
LineSegment
dim(::LineSegment)
σ(::AbstractVector, ::LineSegment)
ρ(::AbstractVector, ::LineSegment)
∈(::AbstractVector, ::LineSegment)
center(::LineSegment)
an_element(::LineSegment)
rand(::Type{LineSegment})
center(::LineSegment)
constraints_list(::LineSegment)
dim(::LineSegment)
generators(::LineSegment)
genmat(::LineSegment)
halfspace_left(::LineSegment)
halfspace_right(::LineSegment)
ngens(::LineSegment)
rand(::Type{LineSegment})
vertices_list(::LineSegment)
constraints_list(::LineSegment)
∈(::AbstractVector, ::LineSegment)
σ(::AbstractVector, ::LineSegment)
ρ(::AbstractVector, ::LineSegment)
translate(::LineSegment, ::AbstractVector)
generators(::LineSegment)
ngens(::LineSegment)
genmat(::LineSegment)
intersection(::LineSegment, ::LineSegment)
isdisjoint(::LineSegment, ::LineSegment)
```

```@meta
CurrentModule = LazySets.API
```

Undocumented implementations:
* [`isoperationtype`](@ref isoperationtype(::Type{LazySet}))

```@meta
CurrentModule = LazySets
```

Inherited from [`LazySet`](@ref):
* [`area`](@ref area(::LazySet))
* [`complement`](@ref complement(::LazySet))
* [`concretize`](@ref concretize(::LazySet))
* [`constraints`](@ref constraints(::LazySet))
* [`convex_hull`](@ref convex_hull(::LazySet))
* [`diameter`](@ref diameter(::LazySet, ::Real))
* [`eltype`](@ref eltype(::Type{<:LazySet}))
* [`eltype`](@ref eltype(::LazySet))
* [`high`](@ref high(::LazySet))
* [`isoperation`](@ref isoperation(::LazySet))
* [`low`](@ref low(::LazySet))
* [`norm`](@ref norm(::LazySet, ::Real))
* [`radius`](@ref radius(::LazySet, ::Real))
* [`diameter`](@ref diameter(::LazySet, ::Real))
* [`singleton_list`](@ref singleton_list(::LazySet))
* [`high`](@ref high(::LazySet, ::Int))
* [`low`](@ref low(::LazySet, ::Int))
* [`reflect`](@ref reflect(::LazySet))
* [`singleton_list`](@ref singleton_list(::LazySet))
* [`surface`](@ref surface(::LazySet))
* [`vertices`](@ref vertices(::LazySet))
* [`affine_map`](@ref affine_map(::AbstractMatrix, ::LazySet, ::AbstractVector))
* [`exponential_map`](@ref exponential_map(::AbstractMatrix, ::LazySet))
* [`is_interior_point`](@ref is_interior_point(::AbstractVector, ::LazySet))
* [`sample`](@ref sample(::LazySet, ::Int))
* [`scale`](@ref scale(::Real, ::LazySet))
* [`≈`](@ref ≈(::LazySet, ::LazySet))
* [`==`](@ref ==(::LazySet, ::LazySet))
* [`isequivalent`](@ref isequivalent(::LazySet, ::LazySet))
* [`⊂`](@ref ⊂(::LazySet, ::LazySet))

Inherited from [`ConvexSet`](@ref):
* [`high`](@ref high(::ConvexSet, ::Int))
* [`low`](@ref low(::ConvexSet, ::Int))
* [`linear_combination`](@ref linear_combination(::ConvexSet, ::ConvexSet))

Inherited from [`AbstractPolyhedron`](@ref):
* [`is_polyhedral`](@ref is_polyhedral(::AbstractPolyhedron))

Inherited from [`AbstractPolytope`](@ref):
* [`isbounded`](@ref isbounded(::AbstractPolytope))
* [`isboundedtype`](@ref isboundedtype(::Type{AbstractPolytope}))
* [`isconvextype`](@ref isconvextype(::Type{AbstractPolytope}))
* [`volume`](@ref volume(::AbstractPolytope))

Inherited from [`AbstractCentrallySymmetricPolytope`](@ref):
* [`center`](@ref center(::AbstractCentrallySymmetricPolytope, ::Int))
* [`extrema`](@ref extrema(::AbstractCentrallySymmetricPolytope))
* [`extrema`](@ref extrema(::AbstractCentrallySymmetricPolytope, ::Int))
* [`isempty`](@ref isempty(::AbstractCentrallySymmetricPolytope))
* [`isuniversal`](@ref isuniversal(::AbstractCentrallySymmetricPolytope))

Inherited from [`AbstractZonotope`](@ref):
* [`linear_map`](@ref linear_map(::AbstractMatrix, ::AbstractZonotope))
* [`order`](@ref order(::AbstractZonotope))
* [`reflect`](@ref reflect(::AbstractZonotope))
* [`togrep`](@ref togrep(::AbstractZonotope))
* [`linear_map`](@ref linear_map(::AbstractMatrix, ::AbstractZonotope))
* [`cartesian_product`](@ref cartesian_product(::AbstractZonotope, ::AbstractZonotope))
* [`minkowski_difference`](@ref minkowski_difference(::AbstractZonotope, ::AbstractZonotope))
* [`minkowski_sum`](@ref minkowski_sum(::AbstractZonotope, ::AbstractZonotope))
58 changes: 0 additions & 58 deletions src/ConcreteOperations/intersection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,64 +138,6 @@ intersection.
end
end

"""
intersection(LS1::LineSegment, LS2::LineSegment)

Compute the intersection of two line segments.

### Input

- `LS1` -- line segment
- `LS2` -- line segment

### Output

A singleton, line segment, or the empty set depending on the result of the
intersection.

### Notes

- If the line segments cross, or are parallel and have one point in common,
that point is returned.

- If the line segments are parallel and have a line segment in common, that
segment is returned.

- Otherwise, if there is no intersection, an empty set is returned.
"""
function intersection(LS1::LineSegment, LS2::LineSegment)

# cast each segment as a line
L1 = Line2D(LS1.p, LS1.q)
L2 = Line2D(LS2.p, LS2.q)

# find intersection between the lines
m = intersection(L1, L2)
N = promote_type(eltype(LS1), eltype(LS2))
if m == L1
# determine which segment is in both
p1 = max(min(LS1.p[1], LS1.q[1]), min(LS2.p[1], LS2.q[1]))
p2 = max(min(LS1.p[2], LS1.q[2]), min(LS2.p[2], LS2.q[2]))
q1 = min(max(LS1.p[1], LS1.q[1]), max(LS2.p[1], LS2.q[1]))
q2 = min(max(LS1.p[2], LS1.q[2]), max(LS2.p[2], LS2.q[2]))
if _isapprox(p1, q1) && _isapprox(p2, q2)
return Singleton([p1, p2]) # edges have a point in common

elseif _leq(p1, q1) && _leq(p2, q2)
return LineSegment([p1, p2], [q1, q2])

else
return EmptySet{N}(2) # no intersection
end

elseif m isa Singleton && m.element ∈ LS1 && m.element ∈ LS2
return m # the intersection point between the lines is in the segments

else
return EmptySet{N}(2) # no intersection
end
end

"""
intersection(H1::AbstractHyperrectangle, H2::AbstractHyperrectangle)

Expand Down
5 changes: 4 additions & 1 deletion src/LazySets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,13 @@ include("Sets/Hyperplane.jl")
include("Sets/Hyperrectangle.jl")
include("Sets/Line2D.jl")
include("Sets/Line.jl")
include("Sets/LineSegment.jl")
include("Sets/Polygon.jl")
include("Sets/RotatedHyperrectangle.jl")
include("Sets/Singleton.jl")

include("Sets/LineSegment/LineSegmentModule.jl")
@reexport using ..LineSegmentModule: LineSegment

include("Sets/SimpleSparsePolynomialZonotope.jl")
include("Sets/SparsePolynomialZonotope.jl")
include("Sets/VPolygon.jl")
Expand Down
Loading