2
$\begingroup$

IMPORTANT: This post is a follow-up to Scaling edge thicknesses, and in particular to the accepted answer in that thread.


Basically, I'm trying to use the idea given in that answer to implement 2-dimensional graphics "components" (i.e. user-defined likes of built-in graphic items such as Disk and Rectangle) whose line thicknesses will not be subject to the vagaries extensively illustrated in that thread's question.

Here's what the sort of graphics "components" I'm referring to looks like:

elements = {Thickness[0.08],
            {Line[{{1, 1}, {1, 5}, {5, 5}, {5, 1}, {1, 1}}], 
             Line[{{1, 3}, {5, 3}}], Line[{{3, 1}, {3, 5}}]}};

component[slot_] := GeometricTransformation[elements, TranslationTransform[{6 (slot - 1), 0}]];

Show[Graphics[Array[component, 1], Background -> LightBlue],
     Axes -> True, AxesOrigin -> {0, 0}, ImageSize -> {Automatic, 80}]

Mathematica graphics

...although this one still suffers from "line thickness instability":

Show[Graphics[Array[component, 3], Background -> LightBlue],
     Axes -> True, AxesOrigin -> {0, 0}, ImageSize -> {Automatic, 80}]

Mathematica graphics

(NB: If you think the solution to this problem should be trivial, please read the superb discussion of it in Scaling edge thicknesses.)


NOTES:

  1. the axes and background are not part of the component; I've included them only for reference;
  2. as defined above, component takes only an integer as argument, corresponding to a horizontal position; this is just to keep the example simple; a more useful component would, at minimum accept a full position vector as argument; more typically, it would also accept an argument specifying its size.

I tried to fix this "line thickness instability" by implementing the components in a way that makes use of the Inset idea given in the answer mentioned earlier. More specifically, I tried this:

insetComponent[slot_] := Inset[Graphics[elements], {1 + 6 (slot - 1), 0}, {0, 0}, 1];

...but it is off to an unauspicious start:

Show[Graphics[Array[insetComponent, 1], Background -> LightBlue],
     Axes -> True, AxesOrigin -> {0, 0}, ImageSize -> {Automatic, 80}]

Mathematica graphics

I am baffled by the appearance of this output. Anyway, to better see what's going on, I added a tiny bit (?) of PlotRangePadding:

Show[Graphics[Array[insetComponent, 1], Background -> LightBlue], 
     Axes -> True, AxesOrigin -> {0, 0}, ImageSize -> {Automatic, 80}, 
     PlotRangePadding -> 1]

Mathematica graphics

...and made the whole thing bigger to better see what's going on:

Show[Graphics[Array[insetComponent, 1], Background -> LightBlue], 
     Axes -> True, AxesOrigin -> {0, 0}, ImageSize -> {Automatic, 300}, 
     PlotRangePadding -> 1]

Mathematica graphics

For the life of me, I cannot figure out why the component has been placed where it is...

My question, however, is not about Inset per se, but about how to implement reusable graphic components (with or without Inset), that I can include anywhere within a Graphics object (just like a Disk or Rectangle object), without worrying about their lines growing obese.

(My hope is that Inset won't end up introducing instabilities and unpredictabilities of its own.)

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.