Skip to content

Commit

Permalink
Merge pull request #716 from Mathics3/empty-LineBox-fix
Browse files Browse the repository at this point in the history
Handle degenerate LineBox when there are no points
  • Loading branch information
rocky authored Jan 4, 2023
2 parents e2c5770 + 89ed622 commit 7b4f260
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion mathics/builtin/box/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,9 @@ def extent(self):


class LineBox(_Polyline):
# Boxing methods for a list of Line.
"""
Boxing methods for a list of Lines.
"""

def init(self, graphics, style, item=None, lines=None):
super(LineBox, self).init(graphics, item, style)
Expand Down
4 changes: 3 additions & 1 deletion mathics/builtin/drawing/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2348,7 +2348,9 @@ def _apply_fn(self, f: Callable, x_value):

class ParametricPlot(_Plot):
"""
<url>:WMA link: https://reference.wolfram.com/language/ref/ParametricPlot.html</url>
<url>
:WMA link
: https://reference.wolfram.com/language/ref/ParametricPlot.html</url>
<dl>
<dt>'ParametricPlot[{$f_x$, $f_y$}, {$u$, $umin$, $umax$}]'
<dd>plots a parametric function $f$ with the parameter $u$ ranging from $umin$ to $umax$.
Expand Down
12 changes: 12 additions & 0 deletions mathics/builtin/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ def convert(content):


class _Polyline(_GraphicsElementBox):
"""
A structure containing a list of line segments
stored in ``self.lines`` created from
a list of points.
Lines are formed by pairs of consecutive point.
"""

def do_init(self, graphics, points):
if not points.has_form("List", None):
raise BoxExpressionError
Expand All @@ -356,6 +364,10 @@ def do_init(self, graphics, points):
):
elements = points.elements
self.multi_parts = True
elif len(points.elements) == 0:
# Ensure there are no line segments if there are no points.
self.lines = []
return
else:
elements = [ListExpression(*points.elements)]
self.multi_parts = False
Expand Down

0 comments on commit 7b4f260

Please sign in to comment.