| 424 | } |
| 425 | |
| 426 | void PathInPlanarTriangleStrip::find( const Vector2f & end, std::function< void(float) > edgeCrossPosition ) |
| 427 | { |
| 428 | nextEdgeNewLeft( end ); |
| 429 | |
| 430 | auto curr = edges_.back().left; |
| 431 | auto prev = previous_[curr]; |
| 432 | for ( int i = (int)edges_.size() - 2; i >= 0; --i ) |
| 433 | { |
| 434 | if ( edges_[i].left == prev ) |
| 435 | { |
| 436 | edgeCrossPosition( 0 ); |
| 437 | curr = prev; |
| 438 | prev = previous_[prev]; |
| 439 | } |
| 440 | else if ( edges_[i].right == prev ) |
| 441 | { |
| 442 | edgeCrossPosition( 1 ); |
| 443 | curr = prev; |
| 444 | prev = previous_[prev]; |
| 445 | } |
| 446 | else if ( edges_[i].left == curr ) |
| 447 | { |
| 448 | edgeCrossPosition( 0 ); |
| 449 | } |
| 450 | else if ( edges_[i].right == curr ) |
| 451 | { |
| 452 | edgeCrossPosition( 1 ); |
| 453 | } |
| 454 | else |
| 455 | { |
| 456 | float lc = cross( prev, edges_[i].left, curr ); |
| 457 | float rc = cross( prev, edges_[i].right, curr ); |
| 458 | if ( lc - rc != 0 ) |
| 459 | { |
| 460 | edgeCrossPosition( std::clamp( lc / ( lc - rc ), 0.0f, 1.0f ) ); |
| 461 | } |
| 462 | else |
| 463 | { |
| 464 | // prev-point and curr-point are on the same line with edges_[i], return something |
| 465 | edgeCrossPosition( 0.5f ); |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | class TriangleStripUnfolder |
| 472 | { |
no test coverage detected