102 tna_t *
const tnas = calloc((
size_t)inpn,
sizeof(
tna_t));
107 for (
int i = 1; i < inpn; i++)
108 tnas[i].t = tnas[i - 1].t +
dist(inps[i], inps[i - 1]);
109 for (
int i = 1; i < inpn; i++)
110 tnas[i].t /= tnas[inpn - 1].t;
111 for (
int i = 0; i < inpn; i++) {
112 tnas[i].
a[0] =
scale(ev0,
B1(tnas[i].t));
113 tnas[i].
a[1] =
scale(ev1,
B2(tnas[i].t));
115 if (
mkspline(inps, inpn, tnas, ev0, ev1, &p1, &v1, &p2, &v2) == -1) {
119 int fit =
splinefits(edges, edgen, p1, v1, p2, v2, inps, inpn);
132 for (
int i = 1; i < inpn - 1; i++) {
133 const double t = tnas[i].
t;
135 .
x =
B0(t) * p1.
x +
B1(t) * cp1.
x +
B2(t) * cp2.
x +
B3(t) * p2.
x,
136 .y =
B0(t) * p1.
y +
B1(t) * cp1.
y +
B2(t) * cp2.
y +
B3(t) * p2.
y};
137 if ((d =
dist(p, inps[i])) > maxd) {
143 const int spliti = maxi;
162 double c[2][2], x[2], det01, det0X, detX1;
163 double d01, scale0, scale3;
166 scale0 = scale3 = 0.0;
167 c[0][0] = c[0][1] = c[1][0] = c[1][1] = 0.0;
169 for (i = 0; i < inpn; i++) {
170 c[0][0] +=
dot(tnas[i].a[0], tnas[i].a[0]);
171 c[0][1] +=
dot(tnas[i].a[0], tnas[i].a[1]);
173 c[1][1] +=
dot(tnas[i].a[1], tnas[i].a[1]);
175 scale(inps[inpn - 1],
B23(tnas[i].t))));
176 x[0] +=
dot(tnas[i].a[0], tmp);
177 x[1] +=
dot(tnas[i].a[1], tmp);
179 det01 = c[0][0] * c[1][1] - c[1][0] * c[0][1];
180 det0X = c[0][0] * x[1] - c[0][1] * x[0];
181 detX1 = x[0] * c[1][1] - x[1] * c[0][1];
182 if (fabs(det01) >= 1e-6) {
183 scale0 = detX1 / det01;
184 scale3 = det0X / det01;
186 if (fabs(det01) < 1e-6 || scale0 <= 0.0 || scale3 <= 0.0) {
187 d01 =
dist(inps[0], inps[inpn - 1]) / 3.0;
192 *sv0 =
scale(ev0, scale0);
193 *sp1 = inps[inpn - 1];
194 *sv1 =
scale(ev1, scale3);
315 double scoeff[4], xcoeff[2], ycoeff[2];
316 double xroots[3], yroots[3], tv, sv, rat;
317 int rootn, xrootn, yrootn, i, j;
319 xcoeff[0] = lps[0].
x;
320 xcoeff[1] = lps[1].
x - lps[0].
x;
321 ycoeff[0] = lps[0].
y;
322 ycoeff[1] = lps[1].
y - lps[0].
y;
324 if (xcoeff[1] == 0) {
325 if (ycoeff[1] == 0) {
326 points2coeff(sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
327 scoeff[0] -= xcoeff[0];
328 xrootn =
solve3(scoeff, xroots);
329 points2coeff(sps[0].y, sps[1].y, sps[2].y, sps[3].y, scoeff);
330 scoeff[0] -= ycoeff[0];
331 yrootn =
solve3(scoeff, yroots);
336 for (j = 0; j < yrootn; j++)
337 addroot(yroots[j], roots, &rootn);
338 else if (yrootn == 4)
339 for (i = 0; i < xrootn; i++)
340 addroot(xroots[i], roots, &rootn);
342 for (i = 0; i < xrootn; i++)
343 for (j = 0; j < yrootn; j++)
344 if (xroots[i] == yroots[j])
345 addroot(xroots[i], roots, &rootn);
348 points2coeff(sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
349 scoeff[0] -= xcoeff[0];
350 xrootn =
solve3(scoeff, xroots);
353 for (i = 0; i < xrootn; i++) {
355 if (tv >= 0 && tv <= 1) {
358 sv = scoeff[0] + tv * (scoeff[1] + tv *
359 (scoeff[2] + tv * scoeff[3]));
360 sv = (sv - ycoeff[0]) / ycoeff[1];
361 if ((0 <= sv) && (sv <= 1))
368 rat = ycoeff[1] / xcoeff[1];
369 points2coeff(sps[0].y - rat * sps[0].x, sps[1].y - rat * sps[1].x,
370 sps[2].y - rat * sps[2].x, sps[3].y - rat * sps[3].x,
372 scoeff[0] += rat * xcoeff[0] - ycoeff[0];
373 xrootn =
solve3(scoeff, xroots);
376 for (i = 0; i < xrootn; i++) {
378 if (tv >= 0 && tv <= 1) {
381 sv = scoeff[0] + tv * (scoeff[1] +
382 tv * (scoeff[2] + tv * scoeff[3]));
383 sv = (sv - xcoeff[0]) / xcoeff[1];
384 if ((0 <= sv) && (sv <= 1))
static int mkspline(Ppoint_t *, int, const tna_t *, Ppoint_t, Ppoint_t, Ppoint_t *, Ppoint_t *, Ppoint_t *, Ppoint_t *)
int Proutespline(Pedge_t *barriers, size_t n_barriers, Ppolyline_t input_route, Ppoint_t endpoint_slopes[2], Ppolyline_t *output_route)
static int splinefits(Pedge_t *, size_t, Ppoint_t, Pvector_t, Ppoint_t, Pvector_t, Ppoint_t *, int)