I'm working with HTML Canvas and have noticed that if I create a path, with let's say a 90 degree angle, that corner isn't drawn correctly; it has antialiasing. See the code below:
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="600" height="550" style="width: 480px; height: 440x;"></canvas>
<script>
const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");
ctx.beginPath();
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(200.5, 20.5);
ctx.lineTo(200.5, 100.5);
ctx.lineTo(20.5, 100.5);
ctx.stroke();
</script>
</body>
</html>
Here's a close-up screenshot of the corner:
Notice the corner pixel isn't black as it should be.
Now:
- I can draw that path as two separate lines by overshooting the corner slightly, and get the corner rendering properly. But then I can't fill it (to fill, I must have a connected path).
- I could overshoot, then go back 180 degrees, and then continue on. This would create a nice corner and have a continuous path. However, if I ever wanted a transparent stroke, that overlap would be noticeable.
lineJoin = "miter"is already set as default - the miter function does not work properly
Is there a way to solve this problem?
