diff options
author | Hans Hagen <pragma@wxs.nl> | 2016-12-21 20:09:16 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2016-12-21 20:09:16 +0100 |
commit | 72e032447232f3f89056f352d3f6b8e2abc499cb (patch) | |
tree | dcce6719b22076c68a286ac202ea4245999c0843 /metapost | |
parent | ae375264381ae74f70415b2351bdbf209248e1af (diff) | |
download | context-72e032447232f3f89056f352d3f6b8e2abc499cb.tar.gz |
2016-12-21 18:57:00
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/mpiv/mp-chem.mpiv | 2 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-grap.mpiv | 6 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-luas.mpiv | 16 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-mlib.mpiv | 2 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-node.mpiv | 16 | ||||
-rw-r--r-- | metapost/context/base/mpiv/mp-tool.mpiv | 39 |
6 files changed, 55 insertions, 26 deletions
diff --git a/metapost/context/base/mpiv/mp-chem.mpiv b/metapost/context/base/mpiv/mp-chem.mpiv index 72ab8037d..4ed9eaa8f 100644 --- a/metapost/context/base/mpiv/mp-chem.mpiv +++ b/metapost/context/base/mpiv/mp-chem.mpiv @@ -1381,7 +1381,7 @@ vardef chem_bw@# (suffix $) (expr f, t, r, c) = % BW enddef ; vardef chem_bd@# (suffix $) (expr f, t, r, c) = % BD - if chem_star[$] : chem_rbd#@($,f,t,r,c) ; fi + if chem_star[$] : chem_rbd@#($,f,t,r,c) ; fi enddef ; vardef chem_rbd@# (suffix $) (expr f, t, r, c) = % RBD diff --git a/metapost/context/base/mpiv/mp-grap.mpiv b/metapost/context/base/mpiv/mp-grap.mpiv index 51b2e5a3d..5f102fe1c 100644 --- a/metapost/context/base/mpiv/mp-grap.mpiv +++ b/metapost/context/base/mpiv/mp-grap.mpiv @@ -473,9 +473,9 @@ enddef ; % String manipulation routines for MetaPost % It is harmless to input this file more than once. -vardef isdigit primary d = - ("0"<=d)and(d<="9") -enddef ; +% vardef isdigit primary d = +% ("0"<=d)and(d<="9") +% enddef ; % Number of initial characters of string s where `c <character>' is true diff --git a/metapost/context/base/mpiv/mp-luas.mpiv b/metapost/context/base/mpiv/mp-luas.mpiv index 8c30da279..253438dee 100644 --- a/metapost/context/base/mpiv/mp-luas.mpiv +++ b/metapost/context/base/mpiv/mp-luas.mpiv @@ -105,3 +105,19 @@ enddef ; def message expr t = if t <> "" : lua.mp.report(t) fi ; enddef ; + +% a few helpers + +% A few helpers: + +vardef isarray suffix a = + lua.mp.isarray(str a) +enddef ; + +vardef prefix suffix a = + lua.mp.prefix(str a) +enddef ; + +vardef dimensions suffix a = + lua.mp.dimensions(str a) +enddef ; diff --git a/metapost/context/base/mpiv/mp-mlib.mpiv b/metapost/context/base/mpiv/mp-mlib.mpiv index 0c7dddf4c..3ad7d0efb 100644 --- a/metapost/context/base/mpiv/mp-mlib.mpiv +++ b/metapost/context/base/mpiv/mp-mlib.mpiv @@ -1608,7 +1608,7 @@ def nofill text t = fill t withpostscript "collect" enddef ; % so we can do: withcolor "red" -def resolvedcolor expr s = +vardef resolvedcolor primary s = % lua.mp.namedcolor(s) % conflicts with macro namedcolor % lua.mp.NamedColor(s) % okay but, can also be % lua.mp("NamedColor",s) % which gives expansion mess diff --git a/metapost/context/base/mpiv/mp-node.mpiv b/metapost/context/base/mpiv/mp-node.mpiv index c7b0bcabe..fdd308ad1 100644 --- a/metapost/context/base/mpiv/mp-node.mpiv +++ b/metapost/context/base/mpiv/mp-node.mpiv @@ -21,17 +21,25 @@ boolean context_node ; context_node := true ; % returns a pair suffix if the path is unknown vardef makenode@#(suffix p)(text t) = - save i ; numeric i ; + save i, b ; numeric i ; string b ; for a = t : if unknown i : % first argument is the index i = a ; - if not picture p.pic[i] : picture p.pic[] ; fi - if not pair p.pos[i] : pair p.pos[] ; fi + if isarray p : % % note that one needs to declare "path p[] ; picture p[]pic[] ;" % before calling node() if one is to use a pseudo-array for p % because "picture p1.pic[] ;" is not a valid syntax! % + % The following works, but is a bit awkward... + % + b := prefix p ; + if not picture p.pic[i] : scantokens("picture " & b & "[]pic[] ;") ; fi + if not pair p.pos[i] : scantokens("pair " & b & "[]pos[] ;") ; fi + else : + if not picture p.pic[i] : picture p.pic[] ; fi + if not pair p.pos[i] : pair p.pos[] ; fi + fi else : if known p.pic[i] : addto p.pic[i] also @@ -140,7 +148,7 @@ vardef nodeboundingpoint@#(suffix p)(expr i) = fi enddef ; -% returns pair: scaled laboff direction +% returns pair: scaled laboff direction vardef relative@#(expr s) = (mfun_laboff@# scaled s) diff --git a/metapost/context/base/mpiv/mp-tool.mpiv b/metapost/context/base/mpiv/mp-tool.mpiv index 809384ef7..c3775ad92 100644 --- a/metapost/context/base/mpiv/mp-tool.mpiv +++ b/metapost/context/base/mpiv/mp-tool.mpiv @@ -871,7 +871,7 @@ secondarydef p intersection_point q = begingroup save x_, y_ ; (x_,y_) = p intersectiontimes q ; - if x_ < 0 : + if x_< 0 : intersection_found := false ; center p % origin else : @@ -3243,8 +3243,9 @@ enddef ; %D These new helpers are by Alan and are used in for instance the mp-node %D module. -newinternal crossingoption ; crossingoption := 0 ; -newinternal crossingscale ; crossingscale := 20 ; +newinternal crossingdebug ; crossingdebug := 0 ; +newinternal crossingscale ; crossingscale := 10 ; +newinternal crossingnumbermax ; crossingnumbermax := 1000 ; % primary, secondary or tertiary? always hard to decide but primary makes sense @@ -3262,20 +3263,20 @@ primarydef p crossingunder q = fi endfor elseif path p : - save n, m, t, a, b, c, r, bcuttings, hold ; - numeric n, m, t[] ; + save n, t, a, b, c, r, bcuttings, hold ; + numeric n, t[], hold ; path a, b, c, r, bcuttings, hold[] ; c := makepath(currentpen scaled crossingscale) ; r := if picture q : boundingbox fi q ; - t[0] := n := m := 0 ; + t[0] := n := hold := 0 ; a := p ; % The cutbefore/cutafter using c below prevents endless loops! %forever : % find all intersections - for i=1 upto 100 : % limit the number, until we can make this robust + for i=1 upto crossingnumbermax : % safeguard clearxy ; z = a intersectiontimes r ; if x < 0 : - exitif m < 1 ; - a := hold[m] ; m := m - 1 ; + exitif hold < 1 ; + a := hold[hold] ; hold := hold - 1 ; clearxy ; z = a intersectiontimes r ; fi (t[incr n], whatever) = p intersectiontimes point x of a ; @@ -3295,14 +3296,18 @@ primarydef p crossingunder q = if length bcuttings > 0 : clearxy ; z = b intersectiontimes r ; if x >= 0 : - hold[incr m] := b ; + hold[incr hold] := b ; fi fi fi fi - if length cuttings = 0 : - exitif m < 1 ; - a := hold[m] ; m := m - 1 ; + if length cuttings = 0 : % a single point: nothing cut + exitif hold < 1 ; + a := hold[hold] ; hold := hold - 1 ; + fi + if i = crossingnumbermax : + message("crossingunder reached maximum " & decimal i & + " intersections."); fi endfor @@ -3316,15 +3321,15 @@ primarydef p crossingunder q = % Now, n>1 ! % t[0] is the first point of the path and t[n] is the last point % (or the first intersection beyond the length if cyclic) - m := 0 ; + save m ; m := 0 ; for i=if cycle p: 2 else: 1 fi upto n : % skip the first segment if cyclic % as it gets repeated (fully) at the end. - if crossingoption > 0 : - if crossingoption = 1 : + if crossingdebug > 0 : + if crossingdebug = 1 : addto pic doublepath c shifted point t[i] of p withpen currentpen withtransparency(1,.5) ; - elseif crossingoption = 2 : + elseif crossingdebug = 2 : addto pic also infotext (incr m,crossingscale/5) shifted point t[i] of p ; |