summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2022-10-14 10:56:48 +0200
committerContext Git Mirror Bot <phg@phi-gamma.net>2022-10-14 10:56:48 +0200
commit0aa93a6d31a45d8df2d8516567b98967ce04f183 (patch)
tree7e1942650512f1994ca56c1eba245973240d4b71 /metapost
parentc161b7d6fe142231346cc1844e6e27c0ab7718c1 (diff)
downloadcontext-0aa93a6d31a45d8df2d8516567b98967ce04f183.tar.gz
2022-10-14 10:15:00
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/base/mpxl/mp-math.mpxl10
-rw-r--r--metapost/context/base/mpxl/mp-tool.mpxl41
2 files changed, 44 insertions, 7 deletions
diff --git a/metapost/context/base/mpxl/mp-math.mpxl b/metapost/context/base/mpxl/mp-math.mpxl
index 404d42160..3d9ad81d3 100644
--- a/metapost/context/base/mpxl/mp-math.mpxl
+++ b/metapost/context/base/mpxl/mp-math.mpxl
@@ -172,6 +172,16 @@ else : % decimal
fi ;
+%D Variant on post to the mailing list by MC:
+
+vardef atantwo(expr dy, dx) =
+ if dx == 0 :
+ if dy < 0 : - fi pi / 2
+ else :
+ atan(dy/dx) if dx > 0 : if dy < 0 : - else : + fi pi fi
+ fi
+enddef ;
+
permanent
m_acos, m_acosh, m_asin, m_asinh, m_atan, m_atantwo, m_atanh, m_cbrt, m_ceil,
m_copysign, m_cos, m_cosh, m_deg, m_erf, m_erfc, m_exp, m_exptwo, m_expm, m_fabs,
diff --git a/metapost/context/base/mpxl/mp-tool.mpxl b/metapost/context/base/mpxl/mp-tool.mpxl
index 7462b0ace..7b7814eef 100644
--- a/metapost/context/base/mpxl/mp-tool.mpxl
+++ b/metapost/context/base/mpxl/mp-tool.mpxl
@@ -675,12 +675,16 @@ vardef mfun_tool_striped_angle(expr option, p, asked_angle, asked_gap) text extr
mask := shape rotated used_angle ;
maximum := max (xpart llcorner mask, xpart urcorner mask, ypart llcorner mask, ypart urcorner mask) ;
minimum := min (xpart llcorner mask, xpart urcorner mask, ypart llcorner mask, ypart urcorner mask) ;
+ % a hack:
+maximum := maximum + max(xpart urcorner shape, ypart urcorner shape);
+minimum := minimum - max(xpart urcorner shape, ypart urcorner shape);
+ %
pattern := image (
if isinner :
mfun_tool_striped_angle_action extra ;
for s within shape :
if stroked s or filled s :
- clip currentpicture to pathpart s ;
+ clip currentpicture to pathpart s ;
fi
endfor ;
else :
@@ -741,6 +745,29 @@ def do_stripe_path_a (text asked_spec) (text asked_draw) (expr asked_path) text
draw image(asked_draw asked_path asked_text) anglestriped(3,0,0) asked_spec ;
enddef ;
+%D A more efficient variant by Mikael:
+
+% path p ; p := fullcircle scaled 3cm && (unitsquare scaled 2cm shifted (4cm,4cm)) && cycle ;
+% draw hatch(p,30,0.2cm) ; draw p ;
+
+vardef hatch(expr p, a, d) =
+ save thestripe, diag, b ; picture thestripe ; numeric diag ; path b ;
+ b := boundingbox p;
+ diag := 0.55 * ( abs((urcorner b) - (llcorner b)) ) ;
+ thestripe := image (
+ draw (-diag,0) -- (diag, 0) &&
+ for i = d step d until diag:
+ (-diag, i) -- (diag, i) &&
+ (-diag,-i) -- (diag,-i) &&
+ endfor nocycle
+ withpen currentpen ;
+ ) ;
+ thestripe := thestripe shifted center b ;
+ thestripe := thestripe rotatedaround(center b, a) ;
+ clip thestripe to p ;
+ thestripe
+enddef ;
+
%D A few normalizing macros:
% primarydef p xsized w =
@@ -4350,12 +4377,12 @@ tertiarydef p cutbeforefirst q =
begingroup ;
save mfun_b, mfun_p ; path mfun_b, mfun_p ; mfun_b := sortedpath (p intersectiontimeslist q) ;
if (point 0 of mfun_b) <> (-1,-1) :
- mfun_p := subpath(xpart point 0 of mfun_b, infinity) of p;
+ mfun_p := subpath(xpart point 0 of mfun_b, length p) of p;
else :
mfun_p := p ;
fi ;
mfun_p
- endgroup ;
+ endgroup
enddef ;
tertiarydef p cutafterfirst q =
@@ -4367,7 +4394,7 @@ tertiarydef p cutafterfirst q =
mfun_p := p ;
fi ;
mfun_p
- endgroup ;
+ endgroup
enddef ;
@@ -4375,12 +4402,12 @@ tertiarydef p cutbeforelast q =
begingroup ;
save mfun_b, mfun_p ; path mfun_b, mfun_p ; mfun_b := sortedpath (p intersectiontimeslist q) ;
if (point 0 of mfun_b) <> (-1,-1) :
- mfun_p := subpath(xpart point (length mfun_b) of mfun_b, infinity) of p;
+ mfun_p := subpath(xpart point (length mfun_b) of mfun_b, length p) of p;
else :
mfun_p := p ;
fi ;
mfun_p
- endgroup ;
+ endgroup
enddef ;
tertiarydef p cutafterlast q =
@@ -4392,7 +4419,7 @@ tertiarydef p cutafterlast q =
mfun_p := p ;
fi ;
mfun_p
- endgroup ;
+ endgroup
enddef ;
% I don't want to define this path every time I make a demo: