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

ScreenToWorldScale shouldn't have a division #2

Open
Apostolique opened this issue Feb 14, 2021 · 0 comments
Open

ScreenToWorldScale shouldn't have a division #2

Apostolique opened this issue Feb 14, 2021 · 0 comments

Comments

@Apostolique
Copy link

public float ScreenToWorldScale(float z = 0) => 1 / Vector2.Distance(ScreenToWorld(0, 0, z), ScreenToWorld(1, 0, z));

Should be

public float ScreenToWorldScale(float z = 0) => Vector2.Distance(ScreenToWorld(0, 0, z), ScreenToWorld(1, 0, z));

The reason it's bad is that let's say I have 200 pixels in screen scale and I want to know how many pixels that is in world scale, right now you have to do:

float inWorldScale = 200f / ScreenToWorldScale();

but it should be

float inWorldScale = 200f * ScreenToWorldScale();

Saves 2 divisions.

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

No branches or pull requests

1 participant