# [NTG-context] Metapost: directionpoint gives unexpected point(?)

Taco Hoekwater taco at bittext.nl
Fri Feb 12 10:55:31 CET 2021

```
> On 12 Feb 2021, at 10:31, Mikael Sundqvist <mickep at gmail.com> wrote:
>
> Hi Taco,
>
> thanks, from your observation and the way I build the paths, I found
> out that I can avoid the problem by shortening the paths I join just
> slightly:
>
> cl := (fullcircle scaled 4u) shifted z0;
> cl := cl cutbefore point (1/6+epsilon) along cl cutafter point
> (2/6-epsilon) along cl;
> cs := (fullcircle scaled 16u) shifted z1;
> cs := cs cutafter point (1/6-epsilon) along cs;
>
> and indeed, it works here now, with different values of the scale u,
> and it seems more stable.

Here is a quick hack I wrote that does the cleanup in a postprocessing stage. It is not very generic or clever, but it works for your case:

def clean_path(suffix p) =
begingroup;
save q,precontrols,postcontrols,points, skip, i,j;
boolean skip;
pair precontrols[],postcontrols[],points[] ;
j := 0;
for i = 0 upto length p:
skip := false;
if abs(xpart point i of p - xpart point i+1 of p)<0.01:
if abs(ypart point i of p - ypart point i+1 of p)<0.01:
skip := true;
fi
fi
if not skip:
points[j] := point i of p;
postcontrols[j] := postcontrol i of p;
precontrols[j+1] := precontrol i+1 of p;
j := j + 1;
fi
endfor;
if abs(xpart point 0 of p - xpart point length p of p)<0.01:
if abs(ypart point 0 of p - ypart point length p of p)<0.01:
j := j - 1;
fi
fi
p := for i=0 upto j-1: points[i] .. controls postcontrols[i] and precontrols[i+1] .. endfor cycle;
endgroup;
enddef;

show p0;
clean_path(p0);
show p0;

>
> PS I found out that eps and epsilon both worked, and I do not see in
> the metafun manual if there is a difference.

The original intent was for eps to be just a ’small enough value that a human will not notice it’ where epsilon is intended as ’the smallest representable value’. Neither really work that way because depending on how you use metapost eps can be quite visible (especially in non-scaled number systems) and (more importantly) in the new non-scaled number systems epsilon cannot really be the smallest representable value for numerical and practical reasons.

So in reality, we always use these definitions:

eps      := .00049 ;      % this is a pretty small positive number
epsilon  := 1/256/256

Best wishes,
Taco

—
Taco Hoekwater              E: taco at bittext.nl
genderfluid (all pronouns)

```