diff options
Diffstat (limited to 'metapost/context/base/mpxl/mp-tool.mpxl')
-rw-r--r-- | metapost/context/base/mpxl/mp-tool.mpxl | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/metapost/context/base/mpxl/mp-tool.mpxl b/metapost/context/base/mpxl/mp-tool.mpxl index 294dddcb9..28d1bbf3e 100644 --- a/metapost/context/base/mpxl/mp-tool.mpxl +++ b/metapost/context/base/mpxl/mp-tool.mpxl @@ -2593,7 +2593,24 @@ primarydef p cornered c = endfor cycle) enddef ; -permanent smoothed, cornered ; +% Mikael Sundqvist came up with this one. We made it robust for points being too close +% for smoothing. + +primarydef p smoothcornered c = + ( begingroup ; + save cc ; + if not cycle p: (point 0 of p) -- fi + for i=1 upto length(p) : + hide (cc := min(c,arclength (subpath(i-1,i) of p)/2);) + (point i-1 of p) shifted (cc*(unitvector(point i of p - point i-1 of p))) -- + (point i of p) shifted (cc*(unitvector(point i-1 of p - point i of p))) .. + controls point i of p .. + endfor + if cycle p : cycle else : point 1 along p fi + endgroup ) +enddef ; + +permanent smoothed, cornered, smoothcornered ; % cmyk color support @@ -3911,18 +3928,21 @@ enddef; permanent hatched ; -% By Mikael Sundqvist: +% By Mikael Sundqvist, with a little evolution: -numeric mfun_dash_len ; +numeric mfun_dash_on, mfun_dash_off ; primarydef p withdashes len = hide ( - save l, n ; + save l, t, n, m ; pair t ; l := arclength p ; - n := l div len ; - if odd(n) : n := n + 1 fi ; - mfun_dash_len := l / n ; + t := paired(len) ; + m := xpart t + ypart t ; + n := l / (l div m) / m ; + mfun_dash_on := n * xpart t ; + mfun_dash_off := n * ypart t ; ) - p dashed dashpattern (on mfun_dash_len off mfun_dash_len) + p dashed dashpattern (on mfun_dash_on off mfun_dash_off) enddef ; +permanent withdashes ; |