content icon indicating copy to clipboard operation
content copied to clipboard

correct example of rect usage

Open Nommyde opened this issue 1 year ago • 1 comments
trafficstars

Description

Motivation

not using beginPath may cause errors and confuse beginners.

Additional details

Related issues and pull requests

Nommyde avatar Feb 11 '24 16:02 Nommyde

Preview URLs

(comment last updated: 2024-03-07 11:32:32)

github-actions[bot] avatar Feb 11 '24 16:02 github-actions[bot]

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 avatar Mar 05 '24 09:03 bsmth

@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.

Nommyde avatar Mar 05 '24 19:03 Nommyde

@bsmth regarding to your example of drawing multiple rectangles. It uses fillRect function (not rect). It is a different approach

Nommyde avatar Mar 05 '24 19:03 Nommyde

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 👍🏻

bsmth avatar Mar 07 '24 13:03 bsmth