square of distance from line segment (x1,y1, x2,y2) to point (x3,y3) */
| 539 | |
| 540 | /* square of distance from line segment (x1,y1, x2,y2) to point (x3,y3) */ |
| 541 | staticfn long |
| 542 | line_dist_coord(long x1, long y1, long x2, long y2, long x3, long y3) |
| 543 | { |
| 544 | long px = x2 - x1; |
| 545 | long py = y2 - y1; |
| 546 | long s = px * px + py * py; |
| 547 | long x, y, dx, dy, distsq = 0; |
| 548 | float lu = 0; |
| 549 | |
| 550 | if (x1 == x2 && y1 == y2) |
| 551 | return dist2(x1, y1, x3, y3); |
| 552 | |
| 553 | lu = ((x3 - x1) * px + (y3 - y1) * py) / (float) s; |
| 554 | if (lu > 1) |
| 555 | lu = 1; |
| 556 | else if (lu < 0) |
| 557 | lu = 0; |
| 558 | |
| 559 | x = x1 + lu * px; |
| 560 | y = y1 + lu * py; |
| 561 | dx = x - x3; |
| 562 | dy = y - y3; |
| 563 | distsq = dx * dx + dy * dy; |
| 564 | |
| 565 | return distsq; |
| 566 | } |
| 567 | |
| 568 | /* guts of l_selection_gradient */ |
| 569 | void |
no test coverage detected