Skip to content

Commit

Permalink
sagemathgh-35113: added check for invalid range in contour_plot and d…
Browse files Browse the repository at this point in the history
…erivatives

    
### 📚 Description

Solves sagemath#35032

Add if condition in misc.py which contour_plot uses to check for invalid
range entered by user(xmin > xmax or ymin>ymax)

### 📝 Checklist


- [x ] I have made sure that the title is self-explanatory and the
description concisely explains the PR.
- [ x] I have linked an issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.
    
URL: sagemath#35113
Reported by: Agamdeep Singh
Reviewer(s): Agamdeep Singh, Kwankyu Lee
  • Loading branch information
Release Manager committed Mar 24, 2023
2 parents 90f14dc + cd0c618 commit f18723d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/sage/plot/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def setup_for_eval_on_grid(funcs,
ValueError: At least one variable range has more than 3 entries: each should either have 2 or 3 entries, with one of the forms (xmin, xmax) or (x, xmin, xmax)
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(y,1,-1),(x,-1,1)], plot_points=5)
(<sage...>, [(1.0, -1.0, 0.5), (-1.0, 1.0, 0.5)])
(<sage...>, [(-1.0, 1.0, 0.5), (-1.0, 1.0, 0.5)])
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(x,1,-1),(x,-1,1)], plot_points=5)
Traceback (most recent call last):
...
Expand All @@ -106,9 +106,9 @@ def setup_for_eval_on_grid(funcs,
...
ValueError: plot start point and end point must be different
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(x,1,-1),(y,-1,1)], return_vars=True)
(<sage...>, [(1.0, -1.0, 2.0), (-1.0, 1.0, 2.0)], [x, y])
(<sage...>, [(-1.0, 1.0, 2.0), (-1.0, 1.0, 2.0)], [x, y])
sage: sage.plot.misc.setup_for_eval_on_grid(x+y, [(y,1,-1),(x,-1,1)], return_vars=True)
(<sage...>, [(1.0, -1.0, 2.0), (-1.0, 1.0, 2.0)], [y, x])
(<sage...>, [(-1.0, 1.0, 2.0), (-1.0, 1.0, 2.0)], [y, x])
TESTS:
Expand Down Expand Up @@ -139,6 +139,14 @@ def setup_for_eval_on_grid(funcs,
else:
vars, free_vars = unify_arguments(funcs)

# check for invalid range (xmin > xmax or ymin > ymax) and swap
if len(ranges) > 1:
for i in range(len(ranges)):
if ranges[i][-2] > ranges[i][-1]:
ranges[i] = list(ranges[i])
ranges[i][-1], ranges[i][-2] = ranges[i][-2], ranges[i][-1]
ranges[i] = tuple(ranges[i])

# pad the variables if we don't have enough
nargs = len(ranges)
if len(vars) < nargs:
Expand Down

0 comments on commit f18723d

Please sign in to comment.