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
[next] Use degree units for rotation/skew in v5, opt-in for radians #4579
Conversation
I'm not convinced this is the best API solution. What if some plugins use radians and some use degrees? You don't want them fighting over this setting. What do you think about this #4133 (comment) by having |
@bigtimebuddy All plugins will have to make changes for v5 compatibility anyway, there are critical changes. Most of plugins are mine, and you can change stuff in |
Most of tools also use degrees and not rads. For spine I'll make entirely new runtime and deprecate v3/v4 support in it, there'll be spine for v3-v4 and for v5. We can remove rads setting in v6 |
WIP: Graphics. |
Make setting the degrees or radians a boolean, not setting a numerical value, that can happen behind the scenes. |
packages/math/src/Matrix.js
Outdated
@@ -361,6 +361,7 @@ export default class Matrix | |||
const skewX = -Math.atan2(-c, d); | |||
const skewY = Math.atan2(b, a); | |||
|
|||
const rad2deg = transform.useRadians ? 1.0 : (180.0 / Math.PI); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider import { RAD_TO_DEG } from './const'
and using RAD_TO_DEG
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'll be extra import line, I think my version is more verbose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With rollup it’s all flattened anyways so the extra import doesn’t matter. In fact, it’s better to import because this uses a single instance variable and compresses smaller. Verbosity is not useful here and constants should be declared, imo.
packages/math/src/Transform.js
Outdated
this._sx = Math.sin(this._rotation + this.skew._y); | ||
this._cy = -Math.sin(this._rotation - this.skew._x); // cos, added PI/2 | ||
this._sy = Math.cos(this._rotation - this.skew._x); // sin, added PI/2 | ||
const deg2rad = this.useRadians ? 1.0 : (Math.PI / 180.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment here as above: import { RAD_TO_DEG } from './const'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^^
packages/graphics/src/Graphics.js
Outdated
@@ -1,5 +1,5 @@ | |||
import { Container, Bounds } from '@pixi/display'; | |||
import { BLEND_MODES } from '@pixi/constants'; | |||
import { BLEND_MODES, DEG_TO_RAD } from '@pixi/constants'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEG_TO_RAD
is in @pixi/math
packages/settings/src/settings.js
Outdated
* | ||
* @static | ||
* @constant | ||
* @memberof PIXI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be @memberof PIXI.settings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chatted with @GoodBoyDigital about this and I feel strongly that we need to solicit feedback from the community for breaking changes or we keep the default as radians. It's a dramatic change. While I agree with Chad's original rationale, I don't want to rush this change through without some buy-in.
At first I wondered why, but after reading the issue, better compatibility and being more in line with other tools makes it worth it, IMO. |
I'm against this because it's a breaking change. Perhaps it could be offered as option? (but the default would be the current state so that nothing gets broken) On the other hand, people who switch to that new version of PixiJS could get a notification in the console and adjust their code. |
@bigtimebuddy need your feedback, whether we make |
I’m with @tobireif. Add util functions and work on the something more fun instead |
80e2295
to
26e238d
Compare
I thumbed up, but ultimately for me, internally, I don't really mind. Most of my annoyance is with DisplayObjects having rotation as radians, and it's not friendly using numeric data via json to set a display objects rotation. I'd be happy alone with @bigtimebuddy's comment of an additional getter / setter of 'angle' in degrees to compliment the 'rotation' in radians. 2 ways of accessing/changing the same information, just like setting width/height and setting scale do. Both useful in different contexts. |
I vote for keeping radians, I liked that tbh. Degrees are only nice for readability, not for math, There aren't much places you actually need degrees (?). Radians is used in trig functions (sin/cos/etc), so that would be awkward to work with when everything is in degrees. I think for support libraries like spline etc is easier to put a As alternative you could also add some convenience |
P.S. In my experience we always converted rads to degrees working with PIXI. |
bf6c452
to
ce54030
Compare
rads by default, @GoodBoyDigital wants it derp useDegrees better docs docs fix
0f0bccf
to
d6c13c4
Compare
Radians are now by default, like in v4. I put link to USE_DEGREES in relevant places in docs. |
now this extend will helping (function (R) {
Math.cosd = function(d) { return Math.cos(d * R); };
Math.sind = function(d) { return Math.sin(d * R); };
Math.tand = function(d) { return Math.tan(d * R); };
})(Math.PI / 180); Able to get the cosine at 45° by doing Math.cosd(45) |
@ivanpopelyshev I think you dismissed my point about plugins. I'd like to just put a finer point on it. Here's an example: Here's how we'd implement a simple plugin now that handles rotation: PIXI.DisplayObject.prototype.flip = function flip() {
this.rotation += Math.PI;
}; If I wanted to implement this same 3rd party plugin using this PR, I'd probably have to do this: PIXI.DisplayObject.prototype.flip = function flip() {
this.rotation += Math.PI * this.transform.rad2deg;
}; So a couple of points about this:
|
The PR wont be accepted if it will have too many lines of code. My concern is to enable storage in degrees, and ability to assign degrees to rotation. I see two ways:
|
If we were implementing, for example, a tween library and we wanted to support a developer using either seconds or milliseconds, we'd probably make a IMO the easiest solution here it to create an alternative to |
Two storage fields is a bad idea, both for core and plugins. Please confirm that you agree to store rotation in degrees. |
It’s not creating two storage fields, it’s one storage and one convenience method on DisplayObject. We should continue to store radians in Transform. |
element.rotationDeg = 30;
console.log(element.rotationDeg === 30); var deg2rad = Math.PI / 180.0;
var rad2deg = 180.0 / Math.PI;
console.log(30 * deg2rad * rad2deg); |
That's why I want to store degrees. Extra multiplication before using trigonometric functions is not a problem, especially when its always there. |
It has taken a long time to address this PR, thanks for your patience. Had a chat about this with @GoodBoyDigital and we have decided to close this for a couple of reasons:
If anyone is interested, we would welcome another PR which introduces separate DisplayObject |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Overview
This introduces a 💥 breaking change to default the units in v5 for rotation/skew/etc to degrees instead of radians. Using radians is still available as an opt-in for those who wish to use that unit or for backward compatibility (see Usage below).
Reference #4133
Pros
Math.PI/2
and no guesses in debugger: if rotation is 1.72, how much is that?Cons
* DEG_TO_RAD
in a few places, please look at changed files.Usage
For setting the global units to radians add the following line. This is needed if your project internally used radians and you require backward compatibility of functionality. Note: this must be set before any Transforms are created.
To override the global setting on a per-Transform basis, you can do this: