One major problem in my attempt to answer to the CountryData flags question is that the way Mathematica handles filled curves differs from the way SVG and EPS style editors do. The latter two have the option to apply either of two rules, the non-zero rule or the even-odd rule, with the non-zero rule being default. The Windows .NET Framework 4.5 knows both rules too.

Mathematica'sFilledCurve doc page says:

Filled curves can be non-convex and intersect themselves. Self-intersecting curves are filled according to an even-odd rule that alternates between filling and not at each crossing.

Unfortunately, since Import translates a filled curve as a FilledCurve with this even-odd rule, one gets a star that was efficiently coded in SVG with five points as follows:

      {FaceForm[{Blue, Opacity[1.]}], 
       FilledCurve[{{{0, 2, 0}, {0, 1, 0}, {0, 1, 0}, {0, 1, 0}}}, 
          {{{366.902, 230.137}, {258.902,265.33599999999996}, 
            {326.105, 173.336}, {326.105,286.93799999999993}, 
            {258.902, 194.93800000000002}}}
       AspectRatio -> Automatic]

Mathematica graphics

(BTW: I would consider this behavior of Import a bug, as it doesn't respect the original's default setting.)

Getting a star, filled as desired, takes twice as much points:

  Polygon@{{427.3, 183.3}, {401.5, 218.4}, {360.2, 204.8}, {385.7, 
     240}, {360, 275.2}, {401.5, 261.8}, {427.3, 296.6}, {427.2, 
     253.5}, {468.1, 240}, {427.2, 226.6}}}]

Mathematica graphics

(and, of course, Import doesn't do this automatically.)

My question is: Is there a way to let FilledCurve behave according to a non-zero rule, for instance using some undocumented properties like discussed here and here? If not, would it be doable to automatically break up a FilledCurve (that not necessarily contains only straight lines) into separate entities that fill up the original shape as intended?

  • 4
    $\begingroup$ This isn't a bug in Import, it's an unfortunate limitation of the current Mathematica graphics language. Import's job is to create the best Mathematica representation of the input file as possible. The Mathematica graphics language simply doesn't support winding rule fills at this time. $\endgroup$
    – ragfield
    Oct 3 '12 at 15:46
  • 1
    $\begingroup$ @ragfield Fair enough. Given the presence of the necessary functionality in Microsoft's framework, it appears the addition of this capability to FilledCurve should be quite doable. May I suggest putting this on the wishlist for version 10? $\endgroup$ Oct 7 '12 at 15:41
  • $\begingroup$ @ragfield It seems that in Mathematica 12 there are now more filling rules available. See the documentation of WindingPolygon . It's a pity that FilledCurve does not already make use of this. Is it possible to put this on a To Do list? $\endgroup$ Apr 17 '19 at 20:30

We're getting closer. In Mathematica 12, there are now more filling rules available. The documentation of the new function WindingPolygon lists the following:

Mathematica graphics

The first star in the question (the one with the minimum number of edges), can now be shown without holes using WindingPolygon:

   0.001388888888888889], {EdgeForm[{Blue, Opacity[1.]}], 
   FaceForm[{Blue, Opacity[1.]}], 
   WindingPolygon[{{{366.902, 230.137}, {258.902, 
       265.33599999999996}, {326.105, 173.336}, {326.105, 
       286.93799999999993}, {258.902, 194.93800000000002}}}]}}, 
 AspectRatio -> Automatic]

Mathematica graphics

The filling rule we need here("NonzeroRule") is the default for WindingPolygon.

Alas, FilledCurve does not know these filling rules (yet?)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.