From b9a7e870cf47674c90331b41f9267768992b49cb Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Tue, 19 Apr 2022 20:58:40 +0200 Subject: 2022-04-19 19:52:00 --- metapost/context/base/mpxl/mp-tool.mpxl | 83 +++++++++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 9 deletions(-) (limited to 'metapost/context/base/mpxl/mp-tool.mpxl') diff --git a/metapost/context/base/mpxl/mp-tool.mpxl b/metapost/context/base/mpxl/mp-tool.mpxl index 749f3d657..f53a6d75b 100644 --- a/metapost/context/base/mpxl/mp-tool.mpxl +++ b/metapost/context/base/mpxl/mp-tool.mpxl @@ -3967,6 +3967,8 @@ permanent withdashes ; path mfun_b ; pair mfun_k ; +path mfun_nullpath ; + tertiarydef p sortedintersectiontimes q = sortedpath (p intersectiontimeslist q) enddef ; @@ -3975,24 +3977,87 @@ tertiarydef p intersectionpath q = begingroup ; save mfun_b ; path mfun_b ; mfun_b := sortedpath (p intersectiontimeslist q) ; save mfun_k ; pair mfun_k ; mfun_k := point 0 of mfun_b; - .5[point xpart mfun_k of p, point ypart mfun_k of q] - for i = 1 upto length(mfun_b) : - hide(mfun_k := point i of mfun_b;) - -- .5[point xpart mfun_k of p, point ypart mfun_k of q] - endfor + if mfun_k <> (-1,-1) : + .5[point xpart mfun_k of p, point ypart mfun_k of q] + for i = 1 upto length(mfun_b) : + hide(mfun_k := point i of mfun_b;) + -- .5[point xpart mfun_k of p, point ypart mfun_k of q] + endfor + else : + mfun_nullpath + fi endgroup enddef ; tertiarydef p firstintersectionpath q = begingroup ; save mfun_b ; path mfun_b ; mfun_b := sortedpath (p intersectiontimeslist q) ; - point xpart (point 0 of mfun_b) of p - for i = 1 upto length(mfun_b) : - -- point xpart (point i of mfun_b) of p - endfor + if (point 0 of mfun_b) <> (-1,-1) : + point xpart (point 0 of mfun_b) of p + for i = 1 upto length(mfun_b) : + -- point xpart (point i of mfun_b) of p + endfor + else : + mfun_nullpath + fi endgroup enddef ; tertiarydef p secondintersectionpath q = q firstintersectionpath p enddef; + +vardef intersectionsfound expr p = + (point 0 of p) <> (-1,-1) +enddef ; + +%D As part of our intersection journey MS came up with: + +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; + else : + mfun_p := p ; + fi ; + mfun_p + endgroup ; +enddef ; + +tertiarydef p cutafterfirst 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(0, xpart point 0 of mfun_b) of p; + else : + mfun_p := p ; + fi ; + mfun_p + endgroup ; +enddef ; + + +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; + else : + mfun_p := p ; + fi ; + mfun_p + endgroup ; +enddef ; + +tertiarydef p cutafterlast 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(0, xpart point (length mfun_b) of mfun_b) of p; + else : + mfun_p := p ; + fi ; + mfun_p + endgroup ; +enddef ; -- cgit v1.2.3