Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stroke width calculation #2178

Merged
merged 1 commit into from
May 8, 2015

Conversation

sapics
Copy link
Contributor

@sapics sapics commented May 8, 2015

From #1929, strokeWidth calculation dose not depends on stroke.

closes #2177

@asturur
Copy link
Member

asturur commented May 8, 2015

I definitely missed this.
Inspecting for #2177 i noticed that, and i was about to fix this.

@sapics
Copy link
Contributor Author

sapics commented May 8, 2015

@asturur i found it from #2177, too!

@asturur
Copy link
Member

asturur commented May 8, 2015

@sapics if you remove the half part of strokewidth, and you scale will FULL strokewidth in both _setObjectScale and _scaleObjectEqually, you will notice that #2177 is fixed.

i mean

strokeWidth = target.strokeWidth;
transform.newScaleX = localMouse.x / (target.width + strokeWidth);
transform.newScaleY = localMouse.y / (target.height + strokeWidth);

For the third function you modified check if apply.

Obviously if we are doing something with width, we cannot just use half of stroke.
For vLine and hLine still some tweak is necessary, so leave strokewidth in a separate var.

Could you make that? if i do this we will have conflicting PR

@sapics
Copy link
Contributor Author

sapics commented May 8, 2015

Absolutely!
I have not understood about definition of localMouse yet, thus, I cannot judge HALF or FULL strokeWidth is right.
It would be better to close this PR to avoid conflict.

@sapics sapics closed this May 8, 2015
@asturur asturur reopened this May 8, 2015
@asturur
Copy link
Member

asturur commented May 8, 2015

I think this PR is good, let's just finish it.
Exactly where you changed the strokeWidth definition, if you remove the use of strokeWidth / 2 and use strokeWidth, the object scaling is fixed 99% of time.

localMouse depends on the translate ( s) function, there are at least 3, and the fix is ugly as shit for them.
the fix would be:

          vLine = target.type === 'line' && target.width === 0,
          hLine = target.type === 'line' && target.height === 0,
          strokeWidthX = hLine ? 0 : target.strokeWidth,
          strokeWidthY = vLine ? 0 : target.strokeWidth;

and use strokeWidthX and strokeWidthY for the x and y instead of general strokeWidth.

If you try to resize this in current kitchensink on fabricJS.com:

canvas.add(new fabric.Rect({
 width:50, height:50,
      fill: 'red',
      stroke: 'blue',
      strokeWidth: 20
}))

You will notice that is wrong.
So the scaling function we have is just wrong, no one notice because large strokeWidth is not so popular.

@asturur
Copy link
Member

asturur commented May 8, 2015

@sapics thanks!

Can you also rebase the commit to have them nice?

@sapics
Copy link
Contributor Author

sapics commented May 8, 2015

@asturur I am sorry, I misunderstood you wrote.
I create jsfiddle to check this fix.
PREVIOUS: http://jsfiddle.net/sapics/tt5zjjot/8/
THIS PR: http://jsfiddle.net/sapics/tt5zjjot/7/

@sapics
Copy link
Contributor Author

sapics commented May 8, 2015

Sure!!

@asturur
Copy link
Member

asturur commented May 8, 2015

To fix the "translate effect" that still remain for just horizontal or vertical lines i would wait.

We should spam this code

          vLine = target.type === 'line' && target.width === 0,
          hLine = target.type === 'line' && target.height === 0,
          strokeWidthX = hLine ? 0 : target.strokeWidth,
          strokeWidthY = vLine ? 0 : target.strokeWidth;

All around the functions, while i want to do something more clean.
@kangax i think you can merge this after a quick look.

@sapics sapics force-pushed the fix-stroke-width-calculation branch from 6a4d0d2 to 328c108 Compare May 8, 2015 06:55
@sapics
Copy link
Contributor Author

sapics commented May 8, 2015

@asturur Thank you! I have fixed as you coded and rebase!

@sapics sapics force-pushed the fix-stroke-width-calculation branch from 15428d6 to d459a87 Compare May 8, 2015 07:29
kangax added a commit that referenced this pull request May 8, 2015
@kangax kangax merged commit 264d73c into fabricjs:master May 8, 2015
@kangax
Copy link
Member

kangax commented May 8, 2015

Awesome, thanks. Don't forget changelog please.

@sapics sapics deleted the fix-stroke-width-calculation branch May 8, 2015 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mouse scaling bug
3 participants