diff options
author | Context Git Mirror Bot <phg42.2a@gmail.com> | 2015-03-09 20:15:05 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2015-03-09 20:15:05 +0100 |
commit | dc98ffdc842271d05903846b460fab90d4d83739 (patch) | |
tree | 49603cd805408ebdde3a7eafc59c40279dc7e9ad /metapost | |
parent | 08128a9710f7a34e16f7487b3bccfe7feadb36f1 (diff) | |
download | context-dc98ffdc842271d05903846b460fab90d4d83739.tar.gz |
2015-03-09 19:29:00
Diffstat (limited to 'metapost')
-rw-r--r-- | metapost/context/base/mp-chem.mpiv | 32 | ||||
-rw-r--r-- | metapost/context/base/mp-mlib.mpiv | 26 | ||||
-rw-r--r-- | metapost/context/base/mp-tool.mpii | 2 | ||||
-rw-r--r-- | metapost/context/base/mp-tool.mpiv | 9 |
4 files changed, 45 insertions, 24 deletions
diff --git a/metapost/context/base/mp-chem.mpiv b/metapost/context/base/mp-chem.mpiv index a316a1a30..7ca40bbea 100644 --- a/metapost/context/base/mp-chem.mpiv +++ b/metapost/context/base/mp-chem.mpiv @@ -11,7 +11,8 @@ %C therefore copyrighted by \PRAGMA. See licen-en.pdf for %C details. -%D This module is incomplete and experimental. +%D This module is incomplete and experimental. Okay, it's not that bad but we do need +%D some disclaimer. % either consistent setting or not @@ -300,7 +301,6 @@ enddef ; chem_init_all ; % WHY does this not work unless defined and then called? - % Like most often in ConTeXt, we will trap but then silently ignore mistaken use, % unless of course the error be too harmful... @@ -529,6 +529,17 @@ vardef chem_set (suffix $) = % This is a fairly complicated optimization and ajustement. It took some % thinking to get right, so beware! + % And then even more time fixing a bug of a rotation +- half the symmetry + % angle of a structure depending on the scale and/or the font size + % (through chem_b_length). + + % first save the symmetry angle of the structure (as in chem_rot): + chem_num0 := if chem_stacked[$] : 3 else : 0 fi ; + chem_num9 := if chem_tetra[$] : 360 else : + abs(angle(point 0+chem_num0 of chem_b_path[$]) - + angle(point 1+chem_num0 of chem_b_path[$])) + fi ; + if (chem_adjacent<>0) and chem_star[P] and chem_star[$] : % nop chem_adjacent := 0 ; @@ -581,7 +592,8 @@ vardef chem_set (suffix $) = -((point (chem_adjacent-1) of chem_b_path[P]) chem_transformed(P)) ; fi % adjust the bond angles - chem_rotation := (chem_rotation + angle(chem_pair1)-angle(chem_pair3)) mod 360 ; + chem_num4 := (angle(chem_pair1)-angle(chem_pair3)) zmod chem_num9 ; + chem_rotation := chem_rotation + chem_num4 ; if not chem_star[$] : chem_pair4 := if chem_star[P] : @@ -666,7 +678,8 @@ vardef chem_set (suffix $) = fi endfor if not chem_front[$] : % adjust rotation - chem_rotation := (chem_rotation + angle(chem_pair1)-angle(chem_pair3)) mod 360 ; + chem_num4 := angle(chem_pair1)-angle(chem_pair3) ; + chem_rotation := (chem_rotation + chem_num4) mod 360 ; fi ; chem_t := identity chem_transformed($) ; chem_pair4 := (point chem_num3 of chem_b_path[$]) transformed chem_t ; @@ -674,6 +687,9 @@ vardef chem_set (suffix $) = currentpicture := currentpicture shifted chem_pair4 ; chem_origin := chem_origin shifted chem_pair4 ; fi + if not chem_front[$] : % adjust rotation + chem_rotation := chem_rotation zmod chem_num9 ; + fi fi chem_substituent := 0 ; fi ; @@ -1571,9 +1587,9 @@ vardef chem_rot (suffix $) (expr d, s) = % ROT chem_rotation := 0 else : chem_num0 := if chem_stacked[$] : 3 else : 0 fi ; - chem_num1 := .5(angle(point d+chem_num0 of chem_b_path[$]) - + chem_num1 := .5(angle(point d+chem_num0 of chem_b_path[$]) - angle(point d+chem_num0-1 of chem_b_path[$])) ; - chem_rotation := (chem_rotation + s*chem_num1) mod 360 ; + chem_rotation := (chem_rotation + s*chem_num1) zmod 360 ; fi fi enddef ; @@ -1584,7 +1600,7 @@ vardef chem_mir (suffix $) (expr d, s) = % MIR if not chem_front[$] : if d=0 : % inversion if chem_mirror=origin : - chem_rotation := (chem_rotation + 180*s) mod 360 ; + chem_rotation := (chem_rotation + 180*s) zmod 360 ; else : chem_mirror := chem_mirror rotated 90 ; fi @@ -1600,7 +1616,7 @@ vardef chem_mir (suffix $) (expr d, s) = % MIR chem_num0 := -360 - chem_num0 ; fi chem_num0 := chem_num0 * s ; - chem_rotation := (chem_rotation + 2chem_num0) mod 360 ; + chem_rotation := (chem_rotation + 2chem_num0) zmod 360 ; chem_mirror := origin ; fi fi diff --git a/metapost/context/base/mp-mlib.mpiv b/metapost/context/base/mp-mlib.mpiv index 1140673ab..907c0c4b7 100644 --- a/metapost/context/base/mp-mlib.mpiv +++ b/metapost/context/base/mp-mlib.mpiv @@ -390,11 +390,11 @@ string mfun_prescript_separator ; mfun_prescript_separator := char(13) ; % Shades % for while we had this: -% -% newinternal shadefactor ; shadefactor := 1 ; -% pair shadeoffset ; shadeoffset := origin ; -% boolean trace_shades ; trace_shades := false ; -% + +newinternal shadefactor ; shadefactor := 1 ; % currently obsolete +pair shadeoffset ; shadeoffset := origin ; % currently obsolete +boolean trace_shades ; trace_shades := false ; % still there + % def withlinearshading (expr a, b) = % withprescript "sh_type=linear" % withprescript "sh_domain=0 1" @@ -523,8 +523,8 @@ def withcircularshade (expr a, b, ra, rb, ca, cb) = withprescript "sh_factor=1" withprescript "sh_color_a=" & colordecimals ca withprescript "sh_color_b=" & colordecimals cb - withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset) - withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset) + withprescript "sh_center_a=" & ddecimal a % (a shifted shadeoffset) + withprescript "sh_center_b=" & ddecimal b % (b shifted shadeoffset) withprescript "sh_radius_a=" & decimal ra withprescript "sh_radius_b=" & decimal rb enddef ; @@ -535,8 +535,8 @@ def withlinearshade (expr a, b, ca, cb) = withprescript "sh_factor=1" withprescript "sh_color_a=" & colordecimals ca withprescript "sh_color_b=" & colordecimals cb - withprescript "sh_center_a=" & ddecimal (a shifted shadeoffset) - withprescript "sh_center_b=" & ddecimal (b shifted shadeoffset) + withprescript "sh_center_a=" & ddecimal a % (a shifted shadeoffset) + withprescript "sh_center_b=" & ddecimal b % (b shifted shadeoffset) enddef ; % replaced (obsolete): @@ -595,8 +595,8 @@ vardef define_circular_shade (expr a, b, ra, rb, ca, cb) = & mfun_prescript_separator & "sh_factor=1" & mfun_prescript_separator & "sh_color_a=" & colordecimals ca & mfun_prescript_separator & "sh_color_b=" & colordecimals cb - & mfun_prescript_separator & "sh_center_a=" & ddecimal (a shifted shadeoffset) - & mfun_prescript_separator & "sh_center_b=" & ddecimal (b shifted shadeoffset) + & mfun_prescript_separator & "sh_center_a=" & ddecimal a % (a shifted shadeoffset) + & mfun_prescript_separator & "sh_center_b=" & ddecimal b % (b shifted shadeoffset) & mfun_prescript_separator & "sh_radius_a=" & decimal ra & mfun_prescript_separator & "sh_radius_b=" & decimal rb ; @@ -610,8 +610,8 @@ vardef define_linear_shade (expr a, b, ca, cb) = & mfun_prescript_separator & "sh_factor=1" & mfun_prescript_separator & "sh_color_a=" & colordecimals ca & mfun_prescript_separator & "sh_color_b=" & colordecimals cb - & mfun_prescript_separator & "sh_center_a=" & ddecimal (a shifted shadeoffset) - & mfun_prescript_separator & "sh_center_b=" & ddecimal (b shifted shadeoffset) + & mfun_prescript_separator & "sh_center_a=" & ddecimal a % (a shifted shadeoffset) + & mfun_prescript_separator & "sh_center_b=" & ddecimal b % (b shifted shadeoffset) ; mfun_defined_cs enddef ; diff --git a/metapost/context/base/mp-tool.mpii b/metapost/context/base/mp-tool.mpii index 62bd122f5..a5bb345a1 100644 --- a/metapost/context/base/mp-tool.mpii +++ b/metapost/context/base/mp-tool.mpii @@ -1407,7 +1407,7 @@ primarydef pct along pat = % also negative enddef ; primarydef len on pat = % no outer ( ) .. somehow fails - (arctime if len>0 : len else : (arclength(pat)+len) fi of pat) of pat + (arctime if len>=0 : len else : (arclength(pat)+len) fi of pat) of pat enddef ; % this cuts of a piece from both ends diff --git a/metapost/context/base/mp-tool.mpiv b/metapost/context/base/mp-tool.mpiv index dda8e84a1..30c3f0f50 100644 --- a/metapost/context/base/mp-tool.mpiv +++ b/metapost/context/base/mp-tool.mpiv @@ -368,6 +368,11 @@ vardef asinh primary x = ln(x+(x++1)) enddef ; vardef sinh primary x = save xx ; xx = exp x ; (xx-1/xx)/2 enddef ; vardef cosh primary x = save xx ; xx = exp x ; (xx+1/xx)/2 enddef ; +%D Like mod, but useful for anglesl it returns (-.5d,+.5d] and is used +%D in for instance mp-chem. + +primarydef a zmod b = (-((b/2 - a) mod b) + b/2) enddef ; + %D Sometimes this is handy: def undashed = @@ -1364,7 +1369,7 @@ primarydef pct along pat = % also negative enddef ; primarydef len on pat = % no outer ( ) .. somehow fails - (arctime if len>0 : len else : (arclength(pat)+len) fi of pat) of pat + (arctime if len>=0 : len else : (arclength(pat)+len) fi of pat) of pat enddef ; % this cuts of a piece from both ends @@ -2315,7 +2320,7 @@ enddef ; %D Handy: def break = - exitif true fi ; + exitif true ; % fi enddef ; %D New too: |