Accumulates the segment between pt1 and pt2 in the LLSQ, quantizing over the integer coordinate grid to properly weight long vectors.
| 584 | // Accumulates the segment between pt1 and pt2 in the LLSQ, quantizing over |
| 585 | // the integer coordinate grid to properly weight long vectors. |
| 586 | static void SegmentLLSQ(const FCOORD& pt1, const FCOORD& pt2, |
| 587 | LLSQ* accumulator) { |
| 588 | FCOORD step(pt2); |
| 589 | step -= pt1; |
| 590 | int xstart = IntCastRounded(MIN(pt1.x(), pt2.x())); |
| 591 | int xend = IntCastRounded(MAX(pt1.x(), pt2.x())); |
| 592 | int ystart = IntCastRounded(MIN(pt1.y(), pt2.y())); |
| 593 | int yend = IntCastRounded(MAX(pt1.y(), pt2.y())); |
| 594 | if (xstart == xend && ystart == yend) return; // Nothing to do. |
| 595 | double weight = step.length() / (xend - xstart + yend - ystart); |
| 596 | // Compute and save the y-position at the middle of each x-step. |
| 597 | for (int x = xstart; x < xend; ++x) { |
| 598 | double y = pt1.y() + step.y() * (x + 0.5 - pt1.x()) / step.x(); |
| 599 | accumulator->add(x + 0.5, y, weight); |
| 600 | } |
| 601 | // Compute and save the x-position at the middle of each y-step. |
| 602 | for (int y = ystart; y < yend; ++y) { |
| 603 | double x = pt1.x() + step.x() * (y + 0.5 - pt1.y()) / step.y(); |
| 604 | accumulator->add(x, y + 0.5, weight); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | // Adds any edges from a single segment of outline between pt1 and pt2 to |
| 609 | // the x_coords, y_coords vectors. pt1 and pt2 should be relative to the |
no test coverage detected