6
$\begingroup$

Bug introduced in 11.3


I was revisiting an earlier problem of mine related to designing 3D objects with extruded text for 3D printing. The accepted answer no longer works in V11.3 if a certain subset of letters are used. For example, while this works as expected:

 BoundaryDiscretizeGraphics[Text[#], _Text] & /@ CharacterRange["A", "C"]

a slight modification results in failure to discretize the graphics.

BoundaryDiscretizeGraphics[Text[# <> #], _Text] & /@ CharacterRange["A", "C"]

enter image description here

Working through various pairs of letters, it appears as if BoundaryDiscretizeGraphics fails if neither of the letters contains an annulus (correct math term?). So "AA" and "AC" will both work, but with "CE" and "CD", only the latter text will be rendered properly.

enter image description here

Of the single letter options, only lower case "i" and lower case "j" fail, which somehow makes sense because in these two cases, there exists two regions, neither of which have an annulus.

All of these problems are not present in the 11.2 version on the Raspberry Pi.

enter image description here

While this is primarily a public service announcement, I am looking for suggestions for workarounds to creating letter-shaped regions. My application requires that it work on both traditional desktop platforms as well as the Raspberry Pi, so timing does become a concern.

$\endgroup$
  • $\begingroup$ I observe the same with version 11.3 on Windows 7 x64. Tagging as a bug. $\endgroup$ – Alexey Popkov May 30 '18 at 9:13
5
$\begingroup$

I think it is worth reporting this issue to support.

To see what might be going on, try DiscretizeGraphics instead:

DiscretizeGraphics[Text["CC"], _Text]

enter image description here

You'll notice that the output appears to be a non-simple polygon, and I think this is why BoundaryDiscretizeGraphics fails to produce a region. To workaround this issue, you can insert a small space between the letters:

BoundaryDiscretizeGraphics[Text["C\[VeryThinSpace]C"], _Text]

enter image description here

Update

The OP in a comment mentioned that my workaround doesn't help for letters that have disconnected pieces, e.g., "i".

Another possibility for creating a region from letters is to use an ImportString/ExportString round trip to the "PDF" format, which creates a Graphics object, and then discretize the resulting Graphics object. For example:

g = First @ ImportString @ ExportString[Style["Ci", 100], "PDF"]

enter image description here

The output is a Graphics object:

g //Head

Graphics

Use BoundaryDiscretizeRegion on this graphics object:

BoundaryDiscretizeGraphics[g, MaxCellMeasure->Infinity]

enter image description here

$\endgroup$
  • $\begingroup$ I had picked up on the same issue with DiscretizeGraphics; your workaround is very nice. $\endgroup$ – bobthechemist May 27 '18 at 18:20
  • $\begingroup$ The \[VeryThinSpace] solution does not work with lower case i and j since spaces cannot be added below the dots (obviously). $\endgroup$ – bobthechemist May 30 '18 at 11:48
  • $\begingroup$ @bobthechemist I've updated my answer with another method that hopefully proves useful. $\endgroup$ – Carl Woll May 30 '18 at 23:11

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.