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

Bugfix: wrong variable name #795

Merged
merged 2 commits into from
Oct 14, 2018
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
2 changes: 1 addition & 1 deletion src/Intersection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function ρ(d::AbstractVector{N},
end

# symmetric method
function ρ(::AbstractVector{N},
function ρ(d::AbstractVector{N},
cap::Intersection{N,
<:Union{HalfSpace{N}, Hyperplane{N}, Line{N}},
<:LazySet{N}};
Expand Down
24 changes: 17 additions & 7 deletions test/unit_Intersection.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Optim

for N in [Float64, Rational{Int}, Float32]
B = BallInf(ones(N, 2), N(3))
H = Hyperrectangle(ones(N, 2), ones(N, 2))
Expand Down Expand Up @@ -58,23 +60,31 @@ end
# Tests for Float64 only
# ======================

# Half-space - Ball1 intersection
# HalfSpace vs. Ball1 intersection
X = Ball1(zeros(2), 1.0);
H = HalfSpace([-1.0, 0.0], -1.0); # x >= 0
d = normalize([1.0, 0.0])

# line search using Optim
using Optim
# flat intersection at x = 1
H = HalfSpace([-1.0, 0.0], -1.0); # x >= 1

# default algorithm
@test ρ(d, X ∩ H) == ρ(d, H ∩ X) == 1.0

# Ball1 vs HalfSpace intersection using default algorithm
H = HalfSpace([1.0, 0.0], 0.0); # x = 0
# intersection at x = 0
H = HalfSpace([1.0, 0.0], 0.0); # x <= 0

# default algorithm
@test ρ(d, X ∩ H) < 1e-6 && ρ(d, H ∩ X) < 1e-6

# specify line search algorithm
@test ρ(d, X ∩ H, algorithm="line_search") < 1e-6 &&
ρ(d, H ∩ X, algorithm="line_search") < 1e-6

# Ball1 vs Hyperplane intersection
# HalfSpace vs. Ball2 intersection
B2 = Ball2(zeros(2), 1.0);
@test ρ(d, B2 ∩ H) < 1e-6 && ρ(d, H ∩ B2) < 1e-6

# Ball1 vs. Hyperplane intersection
H = Hyperplane([1.0, 0.0], 0.5); # x = 0.5
@test isapprox(ρ(d, X ∩ H, algorithm="line_search"), 0.5, atol=1e-6)
# For the projection algorithm, if the linear map is taken lazily we can use Ball1
Expand Down