content
content copied to clipboard
correct example of rect usage
Description
Motivation
not using beginPath may cause errors and confuse beginners.
Additional details
Related issues and pull requests
Preview URLs
(comment last updated: 2024-03-07 11:32:32)
Thanks for the suggestion @Nommyde! I'm against adding this line here without an explanation, however. It's not required for the current example to work reliably (or draw multiple rectangles). I'm leaning towards leaving this as-is unless you have some other suggestions, for instance a note linking to drawing paths or some other examples showing why it could be problematic to leave it out. What do you think?
@bsmth The case I faced with is too complicated to describe, but I can try to do it later if this comment and new changes don't convince you. It is important for understanding that rect is just a part of the path building process. Please take a look here: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineTo#javascript this example has beginPath, and if you delete that line, the example still works. Why should we leave beginPath there but not in the rect documentation? The idea and the processes are the same.
@bsmth regarding to your example of drawing multiple rectangles. It uses fillRect function (not rect). It is a different approach
Please take a look here: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineTo#javascript this example has beginPath, and if you delete that line, the example still works. Why should we leave beginPath there but not in the rect documentation? The idea and the processes are the same.
OK I can see why we're doing it now. I'm alright with the changes, thanks for adding the rationale 👍🏻