| 267 | } |
| 268 | |
| 269 | static Point |
| 270 | predir(const BezierCPs& cps, |
| 271 | double time, |
| 272 | double t) |
| 273 | { |
| 274 | //Compute the unit vector in the direction of the bysector angle |
| 275 | Point dir; |
| 276 | Point p1, p2, p2p1, p1p2; |
| 277 | |
| 278 | p2 = getPointAt(cps, time, t); |
| 279 | p2p1 = getLeftPointAt(cps, time, t); |
| 280 | p1p2 = getRightPointAt(cps, time, t - 1); |
| 281 | p1 = getPointAt(cps, time, t - 1); |
| 282 | dir.x = 3. * (p2.x - p2p1.x); |
| 283 | dir.y = 3. * (p2.y - p2p1.y); |
| 284 | |
| 285 | double epsilon = norm(p1, p1p2, p2p1, p2); |
| 286 | double predirNormSquared = dir.x * dir.x + dir.y * dir.y; |
| 287 | if (predirNormSquared > epsilon) { |
| 288 | double normDir = std::sqrt(predirNormSquared); |
| 289 | assert(normDir != 0); |
| 290 | Point ret; |
| 291 | ret.x = dir.x / normDir; |
| 292 | ret.y = dir.y / normDir; |
| 293 | |
| 294 | return ret; |
| 295 | } |
| 296 | dir.x = 2. * p2p1.x - p1p2.x - p2.x; |
| 297 | dir.y = 2. * p2p1.y - p1p2.y - p2.y; |
| 298 | predirNormSquared = dir.x * dir.x + dir.y * dir.y; |
| 299 | |
| 300 | if (predirNormSquared > epsilon) { |
| 301 | double normDir = std::sqrt(predirNormSquared); |
| 302 | assert(normDir != 0); |
| 303 | Point ret; |
| 304 | ret.x = dir.x / normDir; |
| 305 | ret.y = dir.y / normDir; |
| 306 | |
| 307 | return ret; |
| 308 | } |
| 309 | dir.x = p2.x - p1.x + 3. * (p1p2.x - p2p1.x); |
| 310 | dir.y = p2.y - p1.y + 3. * (p1p2.y - p2p1.y); |
| 311 | predirNormSquared = dir.x * dir.x + dir.y * dir.y; |
| 312 | double normDir = std::sqrt(predirNormSquared); |
| 313 | assert(normDir != 0); |
| 314 | Point ret; |
| 315 | ret.x = dir.x / normDir; |
| 316 | ret.y = dir.y / normDir; |
| 317 | |
| 318 | return ret; |
| 319 | } |
| 320 | |
| 321 | static Point |
| 322 | postdir(const BezierCPs& cps, |
no test coverage detected