jonobr1 / two.js

A renderer agnostic two-dimensional drawing api for the web.
https://two.js.org
MIT License
8.27k stars 454 forks source link

[Question] Additional 1px on rectangle dimensions? #731

Closed JohnPaulHarold closed 1 month ago

JohnPaulHarold commented 1 month ago

Describe your question

When I create a rect with specific dimensions, I'm finding that when calling getBoundingClientRect() there is an additional 1px added. Is this expected behaviour, and if so, why does it happen?

If this feels like a bug, I can update the ticket, or raise a new one.

Your code (either pasted here, or a link to a hosted example)

https://codepen.io/johnpaulharold/pen/Rwzwrmw

Environment (please select one):


If applicable:

Desktop (please complete the following information):

jonobr1 commented 1 month ago

Yes, due to browser inconsistency noStroke is actually the same as stroke = 'transparent'. As a result, the stroke technically exists, but is not visible to the end user. This can be remedied by path.linewidth = 0

But, to your point we can add path.linewidth = 0 to the noStroke method to increase coverage.

JohnPaulHarold commented 1 month ago

Thanks. I thought I'd tried that, but I realised I might have been using lineWidth.

Do you want me to raise a request ticket asking for linewidth = 0 to be added to the noStroke() function?

jonobr1 commented 1 month ago

No need, fixed it here: https://github.com/jonobr1/two.js/pull/732

JohnPaulHarold commented 1 month ago

Thanks! This question is answered for me.