104 tna_t *
const tnas = calloc((
size_t)inpn,
sizeof(
tna_t));
109 for (
int i = 1; i < inpn; i++)
110 tnas[i].t = tnas[i - 1].t +
dist(inps[i], inps[i - 1]);
111 for (
int i = 1; i < inpn; i++)
112 tnas[i].t /= tnas[inpn - 1].t;
113 for (
int i = 0; i < inpn; i++) {
114 tnas[i].
a[0] =
scale(ev0,
B1(tnas[i].t));
115 tnas[i].
a[1] =
scale(ev1,
B2(tnas[i].t));
117 if (
mkspline(inps, inpn, tnas, ev0, ev1, &p1, &v1, &p2, &v2) == -1) {
121 int fit =
splinefits(edges, edgen, p1, v1, p2, v2, inps, inpn);
134 for (
int i = 1; i < inpn - 1; i++) {
135 const double t = tnas[i].
t;
137 .
x =
B0(t) * p1.
x +
B1(t) * cp1.
x +
B2(t) * cp2.
x +
B3(t) * p2.
x,
138 .y =
B0(t) * p1.
y +
B1(t) * cp1.
y +
B2(t) * cp2.
y +
B3(t) * p2.
y};
139 if ((d =
dist(p, inps[i])) > maxd) {
145 const int spliti = maxi;
164 double c[2][2], x[2], det01, det0X, detX1;
165 double d01, scale0, scale3;
168 scale0 = scale3 = 0.0;
169 c[0][0] = c[0][1] = c[1][0] = c[1][1] = 0.0;
171 for (i = 0; i < inpn; i++) {
172 c[0][0] +=
dot(tnas[i].a[0], tnas[i].a[0]);
173 c[0][1] +=
dot(tnas[i].a[0], tnas[i].a[1]);
175 c[1][1] +=
dot(tnas[i].a[1], tnas[i].a[1]);
177 scale(inps[inpn - 1],
B23(tnas[i].t))));
178 x[0] +=
dot(tnas[i].a[0], tmp);
179 x[1] +=
dot(tnas[i].a[1], tmp);
181 det01 = c[0][0] * c[1][1] - c[1][0] * c[0][1];
182 det0X = c[0][0] * x[1] - c[0][1] * x[0];
183 detX1 = x[0] * c[1][1] - x[1] * c[0][1];
184 if (fabs(det01) >= 1e-6) {
185 scale0 = detX1 / det01;
186 scale3 = det0X / det01;
188 if (fabs(det01) < 1e-6 || scale0 <= 0.0 || scale3 <= 0.0) {
189 d01 =
dist(inps[0], inps[inpn - 1]) / 3.0;
194 *sv0 =
scale(ev0, scale0);
195 *sp1 = inps[inpn - 1];
196 *sv1 =
scale(ev1, scale3);
317 double scoeff[4], xcoeff[2], ycoeff[2];
318 double xroots[3], yroots[3], tv, sv, rat;
319 int rootn, xrootn, yrootn, i, j;
321 xcoeff[0] = lps[0].
x;
322 xcoeff[1] = lps[1].
x - lps[0].
x;
323 ycoeff[0] = lps[0].
y;
324 ycoeff[1] = lps[1].
y - lps[0].
y;
326 if (xcoeff[1] == 0) {
327 if (ycoeff[1] == 0) {
328 points2coeff(sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
329 scoeff[0] -= xcoeff[0];
330 xrootn =
solve3(scoeff, xroots);
331 points2coeff(sps[0].y, sps[1].y, sps[2].y, sps[3].y, scoeff);
332 scoeff[0] -= ycoeff[0];
333 yrootn =
solve3(scoeff, yroots);
338 for (j = 0; j < yrootn; j++)
339 addroot(yroots[j], roots, &rootn);
340 else if (yrootn == 4)
341 for (i = 0; i < xrootn; i++)
342 addroot(xroots[i], roots, &rootn);
344 for (i = 0; i < xrootn; i++)
345 for (j = 0; j < yrootn; j++)
346 if (xroots[i] == yroots[j])
347 addroot(xroots[i], roots, &rootn);
350 points2coeff(sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
351 scoeff[0] -= xcoeff[0];
352 xrootn =
solve3(scoeff, xroots);
355 for (i = 0; i < xrootn; i++) {
357 if (tv >= 0 && tv <= 1) {
360 sv = scoeff[0] + tv * (scoeff[1] + tv *
361 (scoeff[2] + tv * scoeff[3]));
362 sv = (sv - ycoeff[0]) / ycoeff[1];
363 if ((0 <= sv) && (sv <= 1))
370 rat = ycoeff[1] / xcoeff[1];
371 points2coeff(sps[0].y - rat * sps[0].x, sps[1].y - rat * sps[1].x,
372 sps[2].y - rat * sps[2].x, sps[3].y - rat * sps[3].x,
374 scoeff[0] += rat * xcoeff[0] - ycoeff[0];
375 xrootn =
solve3(scoeff, xroots);
378 for (i = 0; i < xrootn; i++) {
380 if (tv >= 0 && tv <= 1) {
383 sv = scoeff[0] + tv * (scoeff[1] +
384 tv * (scoeff[2] + tv * scoeff[3]));
385 sv = (sv - xcoeff[0]) / xcoeff[1];
386 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)