Skip to content

Commit 54945a8

Browse files
author
HarshKhandeparkar
committed
fix: Xiaolin Wu's algo to anti alias circles
1 parent 5819d93 commit 54945a8

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

src/kernels/plot.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,27 @@ export function getPlotKernel(
5050

5151
const graphColor = graphPixels[this.thread.y][this.thread.x];
5252

53-
if (dist <= brushSize + 1) {
54-
let intensity = 0;
55-
56-
// The following code basically blurs the line by convolving a simple average kernel
57-
// Very crude implementation of https://developer.nvidia.com/gpugems/gpugems2/part-iii-high-quality-rendering/chapter-22-fast-prefiltered-lines
58-
for (let i = x - 1; i <= x + 1; i++) {
59-
for (let j = y - 1; j <= y + 1; j++) {
60-
const xDist = (i - x1);
61-
const yDist = (j - y1);
62-
63-
const dist = Math.sqrt(xDist ** 2 + yDist ** 2);
64-
65-
intensity += (1 / 9) * Math.min(
66-
1,
67-
Math.floor(brushSize / dist)
68-
)
69-
}
70-
}
53+
if (
54+
dist >= brushSize &&
55+
dist <= brushSize + 1
56+
) {
57+
let intensity = Math.max(0, 1 - (dist - brushSize));
7158

7259
return [
7360
brushColor[0] * intensity + graphColor[0] * (1 - intensity),
7461
brushColor[1] * intensity + graphColor[1] * (1 - intensity),
7562
brushColor[2] * intensity + graphColor[2] * (1 - intensity)
7663
]
7764
}
65+
else if (
66+
dist < brushSize
67+
) {
68+
return [
69+
brushColor[0],
70+
brushColor[1],
71+
brushColor[2]
72+
]
73+
}
7874
else return graphColor;
7975
},
8076
{

0 commit comments

Comments
 (0)