-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge the "diamond" enhancement to trunk.
FossilOrigin-Name: bc3bd914a386c504de0ab4862c0460d1ff287360567766e8889ad3d1e93afcd1
- Loading branch information
Showing
10 changed files
with
281 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Diamond objects | ||
|
||
A diamond acts much like a [box](./boxobj.md) except that its corners | ||
are rotated around the center point such that they become the shape’s | ||
four primary cardinal points: | ||
|
||
~~~~ pikchr indent | ||
D: diamond "Cardinal" "Points" | ||
dot ".n" above at D.n | ||
dot " .e" ljust at D.e | ||
dot ".s" below at D.s | ||
dot ".w " rjust at D.w | ||
~~~~ | ||
|
||
Indeed, before Pikchr [got this primitive](/info/36751abee2), the | ||
workaround was to draw an invisible box to hold the text, then draw | ||
lines between its cardinal points: | ||
|
||
~~~~ pikchr indent | ||
box width 150% invis "“Diamond”" "Label" | ||
line from last.w to last.n to last.e to last.s close | ||
~~~~ | ||
|
||
This does work, and it has the advantage of being compatible with the | ||
original PIC and with GNU `dpic`, but it also has a number of | ||
weaknesses, one of which is evident in comparing the examples above: the | ||
labels aren’t as well-centered when manually drawing the diamond. | ||
|
||
Another is the need for that 150% fudge factor to the invisible box’s | ||
width, without which the labels would be truncated by the dimensions | ||
Pikchr calculates for the invisible bounding box: | ||
|
||
~~~~ pikchr indent | ||
box invis "“Diamond”" "Label" | ||
line from last.w to last.n to last.e to last.s close | ||
~~~~ | ||
|
||
A third advantage falls out of this fact: the “`fit`” attribute works as | ||
expected for Pikchr diamonds. It cannot with the manual PIC-compatible | ||
workaround due to the lack of a properly-calculated bounding box, one taking | ||
into account the rotated cardinal points: | ||
|
||
~~~~ pikchr indent | ||
text "Unfitted:" | ||
diamond "D" | ||
text "Properly fitted:" | ||
diamond "D" fit | ||
text "Badly fitted:" | ||
box invis "D" fit | ||
line from last.w to last.n to last.e to last.s close | ||
~~~~ | ||
|
||
There’s a fourth, more subtle advantage to having this primtive built | ||
into the language: the location of the ordinal points is now | ||
well-defined: | ||
|
||
~~~~ pikchr indent | ||
D: diamond "Ordinal" "Points" | ||
dot " .ne" ljust above at D.ne | ||
dot " .se" ljust below at D.se | ||
dot ".sw " rjust below at D.sw | ||
dot ".nw " rjust above at D.nw | ||
~~~~ | ||
|
||
To replicate that with the PIC-compatible hack above, you’d have to do | ||
the geometry to work out where those points land along the lines. It’s | ||
better to leave that bit of tedious math to the Pikchr renderer. | ||
|
||
Unlike a box, you cannot currently round the corners on a diamond. You | ||
can, however, programmatically override the default height and width | ||
by redefining the `diamondht` and `diamondwid` variables. Here we show | ||
two different ways of making the diamond 25% larger: | ||
|
||
~~~~ pikchr indent | ||
D: diamond thick "Diamond" "Dimensions" width 125% height 125% | ||
X1: line thin color gray left 70% from 4mm left of (D.w,D.n) | ||
X2: line same from 4mm left of (D.w,D.s) | ||
text "height" small at 1/2 way between X1 and X2 | ||
line thin color gray from previous text.n up until even with X1 -> | ||
line thin color gray from previous text.s down until even with X2 -> | ||
X3: line thin color gray down 50% from 2mm below (D.w,D.s) | ||
X4: line same from 2mm below (D.e,D.s) | ||
text "width" small at 1/2 way between X3 and X4 | ||
line thin color gray from previous text.w left until even with X3 -> | ||
line thin color gray from previous text.e right until even with X4 -> | ||
diamondht = diamondht * 1.25 | ||
diamondwid = diamondwid * 1.25 | ||
diamond thick "Diamond" "Dimensions" at 1.5in right of D | ||
~~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
C: diamond "diamond" | ||
|
||
line from C to 3cm heading 00 from C chop; | ||
line from C to 3cm heading 10 from C chop; | ||
line from C to 3cm heading 20 from C chop; | ||
line from C to 3cm heading 30 from C chop; | ||
line from C to 3cm heading 40 from C chop; | ||
line from C to 3cm heading 50 from C chop; | ||
line from C to 3cm heading 60 from C chop; | ||
line from C to 3cm heading 70 from C chop; | ||
line from C to 3cm heading 80 from C chop; | ||
line from C to 3cm heading 90 from C chop; | ||
line from C to 3cm heading 100 from C chop; | ||
line from C to 3cm heading 110 from C chop; | ||
line from C to 3cm heading 120 from C chop; | ||
line from C to 3cm heading 130 from C chop; | ||
line from C to 3cm heading 140 from C chop; | ||
line from C to 3cm heading 150 from C chop; | ||
line from C to 3cm heading 160 from C chop; | ||
line from C to 3cm heading 170 from C chop; | ||
line from C to 3cm heading 180 from C chop; | ||
line from C to 3cm heading 190 from C chop; | ||
line from C to 3cm heading 200 from C chop; | ||
line from C to 3cm heading 210 from C chop; | ||
line from C to 3cm heading 220 from C chop; | ||
line from C to 3cm heading 230 from C chop; | ||
line from C to 3cm heading 240 from C chop; | ||
line from C to 3cm heading 250 from C chop; | ||
line from C to 3cm heading 260 from C chop; | ||
line from C to 3cm heading 270 from C chop; | ||
line from C to 3cm heading 280 from C chop; | ||
line from C to 3cm heading 290 from C chop; | ||
line from C to 3cm heading 300 from C chop; | ||
line from C to 3cm heading 310 from C chop; | ||
line from C to 3cm heading 320 from C chop; | ||
line from C to 3cm heading 330 from C chop; | ||
line from C to 3cm heading 340 from C chop; | ||
line from C to 3cm heading 350 from C chop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
D1: diamond "First Diamond" | ||
arrow | ||
D2: diamond "Above" above "Below" below | ||
arrow | ||
D3: diamond "Fitted" fit | ||
arrow from D2.s down 1cm | ||
down | ||
D4: diamond "Long string above" above "Below1" below fit | ||
right | ||
arrow | ||
D5: diamond width 300% "thin" fit | ||
arrow from D3.e right 2cm | ||
right | ||
D6: diamond height 300% "tall" above "diamond" below fit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters