99 Pvector_t v1, v2, splitv, splitv1, splitv2;
107 tna_t *new_tnas = realloc(tnas,
sizeof(
tna_t) * (
size_t)inpn);
108 if (new_tnas ==
NULL)
114 for (i = 1; i < inpn; i++)
115 tnas[i].t = tnas[i - 1].t +
dist(inps[i], inps[i - 1]);
116 for (i = 1; i < inpn; i++)
117 tnas[i].t /= tnas[inpn - 1].t;
118 for (i = 0; i < inpn; i++) {
119 tnas[i].
a[0] =
scale(ev0,
B1(tnas[i].t));
120 tnas[i].
a[1] =
scale(ev1,
B2(tnas[i].t));
122 if (
mkspline(inps, inpn, tnas, ev0, ev1, &p1, &v1, &p2, &v2) == -1)
124 int fit =
splinefits(edges, edgen, p1, v1, p2, v2, inps, inpn);
133 for (maxd = -1, maxi = -1, i = 1; i < inpn - 1; i++) {
135 p.
x =
B0(t) * p1.
x +
B1(t) * cp1.
x +
B2(t) * cp2.
x +
B3(t) * p2.
x;
136 p.
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)
141 splitv1 =
normv(
sub(inps[spliti], inps[spliti - 1]));
142 splitv2 =
normv(
sub(inps[spliti + 1], inps[spliti]));
143 splitv =
normv(
add(splitv1, splitv2));
159 double c[2][2], x[2], det01, det0X, detX1;
160 double d01, scale0, scale3;
163 scale0 = scale3 = 0.0;
164 c[0][0] = c[0][1] = c[1][0] = c[1][1] = 0.0;
166 for (i = 0; i < inpn; i++) {
167 c[0][0] +=
dot(tnas[i].a[0], tnas[i].a[0]);
168 c[0][1] +=
dot(tnas[i].a[0], tnas[i].a[1]);
170 c[1][1] +=
dot(tnas[i].a[1], tnas[i].a[1]);
172 scale(inps[inpn - 1],
B23(tnas[i].t))));
173 x[0] +=
dot(tnas[i].a[0], tmp);
174 x[1] +=
dot(tnas[i].a[1], tmp);
176 det01 = c[0][0] * c[1][1] - c[1][0] * c[0][1];
177 det0X = c[0][0] * x[1] - c[0][1] * x[0];
178 detX1 = x[0] * c[1][1] - x[1] * c[0][1];
179 if (fabs(det01) >= 1e-6) {
180 scale0 = detX1 / det01;
181 scale3 = det0X / det01;
183 if (fabs(det01) < 1e-6 || scale0 <= 0.0 || scale3 <= 0.0) {
184 d01 =
dist(inps[0], inps[inpn - 1]) / 3.0;
189 *sv0 =
scale(ev0, scale0);
190 *sp1 = inps[inpn - 1];
191 *sv1 =
scale(ev1, scale3);
312 double scoeff[4], xcoeff[2], ycoeff[2];
313 double xroots[3], yroots[3], tv, sv, rat;
314 int rootn, xrootn, yrootn, i, j;
316 xcoeff[0] = lps[0].
x;
317 xcoeff[1] = lps[1].
x - lps[0].
x;
318 ycoeff[0] = lps[0].
y;
319 ycoeff[1] = lps[1].
y - lps[0].
y;
321 if (xcoeff[1] == 0) {
322 if (ycoeff[1] == 0) {
323 points2coeff(sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
324 scoeff[0] -= xcoeff[0];
325 xrootn =
solve3(scoeff, xroots);
326 points2coeff(sps[0].y, sps[1].y, sps[2].y, sps[3].y, scoeff);
327 scoeff[0] -= ycoeff[0];
328 yrootn =
solve3(scoeff, yroots);
333 for (j = 0; j < yrootn; j++)
334 addroot(yroots[j], roots, &rootn);
335 else if (yrootn == 4)
336 for (i = 0; i < xrootn; i++)
337 addroot(xroots[i], roots, &rootn);
339 for (i = 0; i < xrootn; i++)
340 for (j = 0; j < yrootn; j++)
341 if (xroots[i] == yroots[j])
342 addroot(xroots[i], roots, &rootn);
345 points2coeff(sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
346 scoeff[0] -= xcoeff[0];
347 xrootn =
solve3(scoeff, xroots);
350 for (i = 0; i < xrootn; i++) {
352 if (tv >= 0 && tv <= 1) {
355 sv = scoeff[0] + tv * (scoeff[1] + tv *
356 (scoeff[2] + tv * scoeff[3]));
357 sv = (sv - ycoeff[0]) / ycoeff[1];
358 if ((0 <= sv) && (sv <= 1))
365 rat = ycoeff[1] / xcoeff[1];
366 points2coeff(sps[0].y - rat * sps[0].x, sps[1].y - rat * sps[1].x,
367 sps[2].y - rat * sps[2].x, sps[3].y - rat * sps[3].x,
369 scoeff[0] += rat * xcoeff[0] - ycoeff[0];
370 xrootn =
solve3(scoeff, xroots);
373 for (i = 0; i < xrootn; i++) {
375 if (tv >= 0 && tv <= 1) {
378 sv = scoeff[0] + tv * (scoeff[1] +
379 tv * (scoeff[2] + tv * scoeff[3]));
380 sv = (sv - xcoeff[0]) / xcoeff[1];
381 if ((0 <= sv) && (sv <= 1))
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)
static int mkspline(Ppoint_t *, int, tna_t *, Ppoint_t, Ppoint_t, Ppoint_t *, Ppoint_t *, Ppoint_t *, Ppoint_t *)