100 tna_t *
const tnas = calloc((
size_t)inpn,
sizeof(
tna_t));
105 for (
int i = 1; i < inpn; i++)
106 tnas[i].t = tnas[i - 1].t +
dist(inps[i], inps[i - 1]);
107 for (
int i = 1; i < inpn; i++)
108 tnas[i].t /= tnas[inpn - 1].t;
109 for (
int i = 0; i < inpn; i++) {
110 tnas[i].
a[0] =
scale(ev0,
B1(tnas[i].t));
111 tnas[i].
a[1] =
scale(ev1,
B2(tnas[i].t));
113 if (
mkspline(inps, inpn, tnas, ev0, ev1, &p1, &v1, &p2, &v2) == -1) {
117 int fit =
splinefits(edges, edgen, p1, v1, p2, v2, inps, inpn);
130 for (
int i = 1; i < inpn - 1; i++) {
131 const double t = tnas[i].
t;
133 .
x =
B0(t) * p1.
x +
B1(t) * cp1.
x +
B2(t) * cp2.
x +
B3(t) * p2.
x,
134 .y =
B0(t) * p1.
y +
B1(t) * cp1.
y +
B2(t) * cp2.
y +
B3(t) * p2.
y};
135 if ((d =
dist(p, inps[i])) > maxd) {
141 const int spliti = maxi;
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);
306 double scoeff[4], xcoeff[2], ycoeff[2];
307 double xroots[3], yroots[3], tv, sv, rat;
308 int rootn, xrootn, yrootn, i, j;
310 xcoeff[0] = lps[0].
x;
311 xcoeff[1] = lps[1].
x - lps[0].
x;
312 ycoeff[0] = lps[0].
y;
313 ycoeff[1] = lps[1].
y - lps[0].
y;
315 if (xcoeff[1] == 0) {
316 if (ycoeff[1] == 0) {
317 points2coeff(sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
318 scoeff[0] -= xcoeff[0];
319 xrootn =
solve3(scoeff, xroots);
320 points2coeff(sps[0].y, sps[1].y, sps[2].y, sps[3].y, scoeff);
321 scoeff[0] -= ycoeff[0];
322 yrootn =
solve3(scoeff, yroots);
327 for (j = 0; j < yrootn; j++)
328 addroot(yroots[j], roots, &rootn);
329 else if (yrootn == 4)
330 for (i = 0; i < xrootn; i++)
331 addroot(xroots[i], roots, &rootn);
333 for (i = 0; i < xrootn; i++)
334 for (j = 0; j < yrootn; j++)
335 if (xroots[i] == yroots[j])
336 addroot(xroots[i], roots, &rootn);
339 points2coeff(sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
340 scoeff[0] -= xcoeff[0];
341 xrootn =
solve3(scoeff, xroots);
344 for (i = 0; i < xrootn; i++) {
346 if (tv >= 0 && tv <= 1) {
347 points2coeff(sps[0].y, sps[1].y, sps[2].y, sps[3].y, scoeff);
348 sv = scoeff[0] + tv * (scoeff[1] + tv * (scoeff[2] + tv * scoeff[3]));
349 sv = (sv - ycoeff[0]) / ycoeff[1];
350 if ((0 <= sv) && (sv <= 1))
357 rat = ycoeff[1] / xcoeff[1];
358 points2coeff(sps[0].y - rat * sps[0].x, sps[1].y - rat * sps[1].x,
359 sps[2].y - rat * sps[2].x, sps[3].y - rat * sps[3].x, scoeff);
360 scoeff[0] += rat * xcoeff[0] - ycoeff[0];
361 xrootn =
solve3(scoeff, xroots);
364 for (i = 0; i < xrootn; i++) {
366 if (tv >= 0 && tv <= 1) {
367 points2coeff(sps[0].x, sps[1].x, sps[2].x, sps[3].x, scoeff);
368 sv = scoeff[0] + tv * (scoeff[1] + tv * (scoeff[2] + tv * scoeff[3]));
369 sv = (sv - xcoeff[0]) / xcoeff[1];
370 if ((0 <= sv) && (sv <= 1))
int Proutespline(Pedge_t *barriers, size_t n_barriers, Ppolyline_t input_route, Pvector_t endpoint_slopes[2], Ppolyline_t *output_route)
static int splinefits(Pedge_t *edges, size_t edgen, Ppoint_t pa, Pvector_t va, Ppoint_t pb, Pvector_t vb, Ppoint_t *inps, int inpn)
static int mkspline(Ppoint_t *inps, int inpn, const tna_t *tnas, Ppoint_t ev0, Ppoint_t ev1, Ppoint_t *sp0, Ppoint_t *sv0, Ppoint_t *sp1, Ppoint_t *sv1)
static int reallyroutespline(Pedge_t *edges, size_t edgen, Ppoint_t *inps, int inpn, Ppoint_t ev0, Ppoint_t ev1)