From b448ad184049152d910389996fc8a4f3f3d85e38 Mon Sep 17 00:00:00 2001 From: Asger Horn Brorholt Date: Wed, 27 Mar 2024 16:28:19 +0100 Subject: [PATCH] Better error reporting --- src/BarbaricReachability.jl | 10 +++++++++- src/Grids.jl | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/BarbaricReachability.jl b/src/BarbaricReachability.jl index 0edfbf6..420dbe2 100644 --- a/src/BarbaricReachability.jl +++ b/src/BarbaricReachability.jl @@ -83,7 +83,15 @@ function draw_barbaric_transition!(model, colors=(:black, :gray), plotargs...) - ix, iy = indexof((==(Colon())), slice) + + ix, iy = 0, 0 + if 1 == count((==(Colon())), slice) + ix = iy = 1 + elseif 2 != count((==(Colon())), slice) + throw(ArgumentError("The slice argument should be an array of indices and exactly two colons. Example: [:, 10, :]")) + else + ix, iy = indexof((==(Colon())), slice) + end samples = [s for s in SupportingPoints(model.samples_per_axis, partition)] scatter!([s[ix] for s in samples], [s[iy] for s in samples], diff --git a/src/Grids.jl b/src/Grids.jl index 217c6ad..e2b3466 100644 --- a/src/Grids.jl +++ b/src/Grids.jl @@ -86,7 +86,7 @@ function box(grid::Grid, state) for dim in 1:grid.dimensions if !(grid.bounds.lower[dim] <= state[dim] < grid.bounds.upper[dim]) - throw(ArgumentError("State is out of bounds for this grid")) + throw(ArgumentError("State $state is outside this grid's bounds $(grid.bounds)")) end indices[dim] = floor(Int, (state[dim] - grid.bounds.lower[dim])/grid.granularity[dim]) + 1