Skip to content

Commit

Permalink
Handle degenerate LineBox when there are no points
Browse files Browse the repository at this point in the history
Something weird seems to be happening in LineBox generation for
Asymptote when it handles TicksStyle = {}, the default TickStyle

We get:

draw(, rgb(0.6, 0.24, 0.56327)+linewidth(0.66667));

Because there are no points.

Also TicksStyle handling seems weird since we shouldn't try to create
LineBox in the first place.
  • Loading branch information
rocky committed Jan 3, 2023
1 parent 3b3bd94 commit 89ed622
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 89ed622

Please sign in to comment.