... | ... | @@ -14,6 +14,35 @@ There is not much to say about the axis itself, the *LineChartRasterizer* does n |
|
|
|
|
|
## **Line rasterizing algorithm**
|
|
|
The *LineChartRasterizer* currently uses the **bresenham** algorithm to draw a line between two datapoints as nearly to the ideal line as possible. Because **bresenham** assumes an equal distant grid, there is a conversion to be done between the geometrical position (for example in milimetres) and the dot position, measured in braillecell/ dots. The current implementation looksup the nearest point, which is why there are sometime aritfact points.
|
|
|
Here the code:
|
|
|
` private void bresenham(final Double xStart, final Double yStart, final Double xEnd, final Double yEnd) {
|
|
|
int y0 = (int) (mCanvas.toDotRectangle(mCellLineArea).intWrapper().getHeight() - yStart);
|
|
|
int y1 = (int) (mCanvas.toDotRectangle(mCellLineArea).intWrapper().getHeight() - yEnd);
|
|
|
int x0 = (int) (xStart.doubleValue());
|
|
|
int x1 = (int) (xEnd.doubleValue());
|
|
|
int dx = abs(x1 - x0);
|
|
|
int dy = -abs(y1 - y0);
|
|
|
int sx = x0 < x1 ? 1 : -1;
|
|
|
int sy = y0 < y1 ? 1 : -1;
|
|
|
int err = dx + dy;
|
|
|
int e2;
|
|
|
while (true) {
|
|
|
mCanvas.getCurrentPage().setValue((int) (mCanvas.toDotRectangle(mCellLineArea).getHeight() - y0), (int) x0, true);
|
|
|
if (x0 == x1 && y0 == y1) {
|
|
|
break;
|
|
|
}
|
|
|
e2 = 2 * err;
|
|
|
if (e2 > dy) {
|
|
|
err += dy;
|
|
|
x0 += sx;
|
|
|
}
|
|
|
if (e2 < dx) {
|
|
|
err += dx;
|
|
|
y0 += sy;
|
|
|
}
|
|
|
}
|
|
|
}`
|
|
|
|
|
|
There is future work to be done in evaluating more line draw algorithms, for example "P. Stephenson, B. Litow: Running the line:Line drawing using runs and runs of runs". Sadly, this algorithm is closed source and was only made available after the project finished.
|
|
|
|
|
|
## **Point rasterizing algorithm**
|
... | ... | |