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

Add maximum_radius_with_center #232

Merged
merged 4 commits into from
Dec 16, 2020
Merged

Conversation

blegat
Copy link
Member

@blegat blegat commented Nov 15, 2020

  • Tests
  • Add in doc

cc @ferrolho

@codecov
Copy link

codecov bot commented Nov 15, 2020

Codecov Report

Merging #232 (5ab5e60) into master (a5b4772) will decrease coverage by 0.71%.
The diff coverage is 88.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #232      +/-   ##
==========================================
- Coverage   90.16%   89.45%   -0.72%     
==========================================
  Files          38       38              
  Lines        2532     2333     -199     
==========================================
- Hits         2283     2087     -196     
+ Misses        249      246       -3     
Impacted Files Coverage Δ
src/center.jl 94.02% <88.23%> (-2.34%) ⬇️
src/polyhedra_to_lp_bridge.jl 55.17% <0.00%> (-4.21%) ⬇️
src/projection_opt.jl 65.51% <0.00%> (-2.23%) ⬇️
src/representation.jl 62.50% <0.00%> (-2.21%) ⬇️
src/doubledescription.jl 74.41% <0.00%> (-1.67%) ⬇️
src/defaultlibrary.jl 93.18% <0.00%> (-1.47%) ⬇️
src/lphrep.jl 88.09% <0.00%> (-1.27%) ⬇️
src/decompose.jl 70.79% <0.00%> (-1.24%) ⬇️
src/elements.jl 84.40% <0.00%> (-1.24%) ⬇️
src/repop.jl 90.52% <0.00%> (-1.22%) ⬇️
... and 24 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a5b4772...5ab5e60. Read the comment docs.

src/center.jl Outdated
return zero(T)
end
else
radius = min(radius, (hs.β - center ⋅ hs.a) / n)
Copy link
Contributor

@ferrolho ferrolho Nov 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this won't work at the first iteration because:

julia> min(nothing, 2.5)
ERROR: MethodError: no method matching isless(::Float64, ::Nothing)
Closest candidates are:
  isless(::Missing, ::Any) at missing.jl:87
  isless(::Float64, ::Float64) at float.jl:465
  isless(::AbstractFloat, ::AbstractFloat) at operators.jl:165
  ...

Shall we add a check above? Something like isnothing(radius) && (radius = (hs.β - center ⋅ hs.a) / n)?

Copy link
Contributor

@ferrolho ferrolho Nov 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, adding isnothing(radius) && (radius = (hs.β - center ⋅ hs.a) / n) is not ideal because radius = min(radius, (hs.β - center ⋅ hs.a) / n) would run afterwards unnecessarily. Adding another branch to the if statement may be better.

@blegat blegat force-pushed the bl/maximum_radius_with_center branch from 35eaab2 to 074c132 Compare November 15, 2020 20:44
@ferrolho
Copy link
Contributor

While writing the basic tests for this I noticed a case for which maximum_radius_with_center returned a negative radius. We may want to throw an error for such cases.

Example:

julia> p = hrep([1 1; -1 -1], [0, -1])
H-representation MixedMatHRep{Int64,Array{Int64,2}}:
2-element iterator of HalfSpace{Int64,Array{Int64,1}}:
 HalfSpace([1, 1], 0)
 HalfSpace([-1, -1], -1)

julia> r = Polyhedra.maximum_radius_with_center(p, zeros(2))
-0.7071067811865475

@blegat blegat merged commit 12379c7 into master Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants