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

Deprecate FlxPoint.angleBetween and make angles consistent #2482

Merged
merged 11 commits into from
Apr 25, 2022

Conversation

Geokureli
Copy link
Member

@Geokureli Geokureli commented Jan 14, 2022

fixes #2037 and #956

Created FlxAngle.angleFromOrigin, and changed every "angle from coordinates" util to use it, just about everywhere and made 0 degrees point RIGHT everywhere. 2037 hit a road block looking for a "fast atan", but I hardly think it's worth the extreme lack of precision

I ran some speed tests, here:

// --- HashLink ---
// label  [times run]          total time         adjusted time
slow check  [1000000] - 11.4790916442871   - 3.87918949127197
fast check  [1000000] - 8.74979496002197   - 1.14989280700684
return 1.0  [1000000] - 7.59990215301514   - 0
// --- JS ---
slow check [10000000] - 5.874000000059604  - 3.6850000001490115
fast check [10000000] - 4.197000000029803  - 2.00800000011921
return 1.0 [10000000] - 2.188999999910593  - 0
// --- Neko ---
slow check   [100000] - 10.0919961929321   - 1.1138916015625
fast check   [100000] - 16.0075902938843   - 7.02948570251465
return 1.0   [100000] - 8.97810459136963   - 0

is it faster? Ignoring neko, it's roughly 2-3 times faster when adjusted against a simple literal return! however, these gains will likely never have a significant impact, and if someone needs that optimization (and less precision), they probably know how to make their own. Even if we could fix the lack of precision, this speed bonus just seems frivolous. However if we do want to replace Math.atan2 with something else, we can now change one spot to affect everything in the framework.

Note: FlxSwipe and FlxPath angles no longer have their previous 90 degree offset. this should be the only backwards compatibility issue this PR introduces

Additional changes

  • Added FlxAngle utlis: degreesBetween, radiansBetween, degreesBetweenPoint, radiansBetweenPoint, degreesBetweenMouse, radiansBetweenMouse, degreesBetweenTouch and radiansBetweenTouch
  • Deprecated FlxAngle utils: getCartesianCoords, getPolarCoords and angleFromFacing
  • Added degrees and radians fields to FlxDirectionFlags to replace FlxAngle.angleFromFacing

@Geokureli Geokureli added this to the 5.0.0 milestone Apr 20, 2022
@Geokureli Geokureli mentioned this pull request Apr 20, 2022
10 tasks
@Geokureli Geokureli merged commit c6e7561 into HaxeFlixel:dev Apr 25, 2022
@Geokureli Geokureli deleted the deprecate_anglebetween branch May 10, 2022 20:28
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.

Weird results with angleBetween (FlxAngle VS FlxPoint)
1 participant