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

feat(emath): Add scale and scale2 to Rects #4673

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zkldi
Copy link
Contributor

@zkldi zkldi commented Jun 18, 2024

I find myself wanting this API quite a lot, and I imagine it'll probably be useful for others.

What?

This PR adds Rect::scale and Rect::scale2 functions, which work a lot like expand, but instead multiply by a scale.

i.e.

rect.scale(2.0); // rect is 2x as big, still in same center
rect.scale2(vec2(1.5, 2.0)); // rect is 1.5x as big on x axis, 2.0x as big on y axis. still in same center

Why?

Before this you either had to write this yourself or use a expand in a cumbersome way:

rect.expand2(vec2(rect.width() * scale.x / 2.0, rect.height() * scale.y / 2.0));

I find myself wanting to scale things up by a factor frequently enough, and it seems like a useful addition to have a multiply-based variant of expand.

I realise this is pretty minor, but it seems useful enough to me!

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.

None yet

2 participants