Skip to content

Commit e4985e4

Browse files
authored
Merge pull request #1412 from mathics/polygon-fill-rule
WL uses evenodd fill rule for polygons
2 parents d53004f + 5a48e8f commit e4985e4

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

mathics/builtin/graphics.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,15 +1532,23 @@ def extent(self):
15321532
class Polygon(Builtin):
15331533
"""
15341534
<dl>
1535-
<dt>'Polygon[{$point_1$, $point_2$ ...}]'
1536-
<dd>represents the filled polygon primitive.
1537-
<dt>'Polygon[{{$p_11$, $p_12$, ...}, {$p_21$, $p_22$, ...}, ...}]'
1538-
<dd>represents a number of filled polygon primitives.
1535+
<dt>'Polygon[{$point_1$, $point_2$ ...}]'
1536+
<dd>represents the filled polygon primitive.
1537+
1538+
<dt>'Polygon[{{$p_11$, $p_12$, ...}, {$p_21$, $p_22$, ...}, ...}]'
1539+
<dd>represents a number of filled polygon primitives.
15391540
</dl>
15401541
1542+
A Right Triangle:
15411543
>> Graphics[Polygon[{{1,0},{0,0},{0,1}}]]
15421544
= -Graphics-
15431545
1546+
Notice that there is a line connecting from the last point to the first one.
1547+
1548+
A point is an element of the polygon if a ray from the point in any direction in the plane crosses the boundary line segments an odd number of times.
1549+
>> Graphics[Polygon[{{150,0},{121,90},{198,35},{102,35},{179,90}}]]
1550+
= -Graphics-
1551+
15441552
>> Graphics3D[Polygon[{{0,0,0},{0,1,1},{1,0,0}}]]
15451553
= -Graphics3D-
15461554
"""

mathics/formatter/svg.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,15 @@ def polygonbox(self, **options):
303303
]
304304
mesh.append(data)
305305
svg += '<meshgradient data="%s" />' % json.dumps(mesh)
306+
307+
# Perhaps one day this c
308+
fill_rule="evenodd"
309+
306310
for line in self.lines:
307-
svg += '<polygon points="%s" style="%s" />' % (
308-
" ".join("%f,%f" % coords.pos() for coords in line),
309-
style,
310-
)
311+
svg += f"""
312+
<polygon points="{" ".join("%f,%f" % coords.pos() for coords in line)}"
313+
fill-rule="{fill_rule}"
314+
style="{style}" />"""
311315
# print("XXX PolygonBox", svg)
312316
return svg
313317

0 commit comments

Comments
 (0)