From ee4abe25fdf0d056b5586ff33deea8979ccf761d Mon Sep 17 00:00:00 2001 From: Twan Koolen Date: Thu, 11 Oct 2018 11:47:10 -0400 Subject: [PATCH] Fix error when position bounds are negative. --- src/manipulate.jl | 3 ++- test/runtests.jl | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/manipulate.jl b/src/manipulate.jl index ea3401e..8b0daaa 100644 --- a/src/manipulate.jl +++ b/src/manipulate.jl @@ -28,8 +28,9 @@ function sliders(joint::Joint, values=clamp.(zeros(num_positions(joint)), positi resolution=0.01, prefix="") map(bounds, labels, values) do b, label, value num_steps = ceil(Int, (upper(b) - lower(b)) / resolution) + r = range(lower(b), stop=upper(b), length=num_steps) slider(range(lower(b), stop=upper(b), length=num_steps), - value=value, + value=clamp(value, first(r), last(r)), label=string(prefix, label)) end end diff --git a/test/runtests.jl b/test/runtests.jl index f513bf8..708ffa1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -104,6 +104,14 @@ vis = Visualizer() widget = manipulate!(mvis) end + @testset "manipulation - negative bounds issue" begin + mechanism = rand_chain_mechanism(Float64, Revolute{Float64}) + joint = first(joints(mechanism)) + joint.position_bounds .= RigidBodyDynamics.Bounds(-2.0, -1.0) + mvis = MechanismVisualizer(mechanism) + widget = manipulate!(mvis) + end + @testset "examples" begin dir = joinpath(@__DIR__, "..", "examples") for file in readdir(dir)