-%
-% Shift `curve' along the line given by the auxiliary points `p_in'
-% and `p_out' until `line' is a tangent, and return the shift.
-% If `curve' is shifted to position `p_in', it must intersect
-% `line', while shifted to `p_out' it must not.
-%
-def find_tangent_shift (expr line, curve, p_in, p_out) =
- begingroup;
- save mid, t, t_good, in, out;
- pair mid, in, out;
-
- in := p_in;
- out := p_out;
-
- forever:
- mid := 0.5 [in, out];
- exitif abs (out - mid) <= eps;
- t := xpart ((curve shifted mid) intersectiontimes line);
- if (t > 0):
- in := mid;
- t_good := t;
- else:
- out := mid;
- fi;
- endfor;
-
- mid
- endgroup
-enddef;
-
-
-%
-% Get subpath specified by `dir_in' and `dir_out' of `curve'
-% which is then shifted by `offset'. Assure that result has
-% the same orientation as `curve'.
-%
-def get_subpath (expr curve, dir_in, dir_out, offset) =
- begingroup;
- save t_in, t_out;
-
- t_in := directiontime dir_in of curve;
- t_out := directiontime dir_out of curve;
-
- if t_in > t_out:
- t_out := t_out + length curve;
- fi;
-
- (subpath (t_in, t_out) of curve) shifted offset
- endgroup
-enddef;
-
-