ARTICLE AD BOX
Problem
In my app I need to draw a lot of polygons fast, for this I am using the following canvas primitives
ctx.beginPath() ctx.moveTo(points[0], points[1]) ctx.stroke()Unfortunately when I try to style the width of each line that is being drawn, the lines extend beyond the points I moveTo. This is unexpected, I expected only the thickness of the line being changed, not their endpoints.
Example
I have distilled my problem to the following minimal case. I have created a blue bounding box that should contain the drawn triangle / polygon. This works correctly when the linewidth is set to 1, but as soon as I increase the line width, the polygon exceeds the expected bounding box.
Possible cause
It looks like the lineWidth is added to the line end points. I cannot find anything on MDN that would suggest this would happen.
I would like a solution that increases the thickness of the lines, but keeps the polygon inside the bounding box. The solution must be fast as well.
