Angle Comparison odd behavior

Bugs will be moved here once resolved.

Post » Thu Jan 24, 2013 4:47 pm

My apologies if this is a documented/normal behaviour. I could not find anything about this in the Manual/Forums.

Work around is to use anglediff instead of simply comparing with operators.

Link to .capx file (required!):
https://docs.google.com/file/d/0B20uobjbjbtgbjRaa2d1ZTdWOEE/edit

Steps to reproduce:
1. Run the capx
2. Notice that the result of the first comparison is "1" (true) and the second is "0" (false)
3. Check the objects angle and the comparison code

Observed result:
The first comparison is true, and the second is false

Expected result:
Both should be true

Browsers affected:
This is most likely browser independent

Operating system & service pack:
Windows 7 Enterprise SP1

Construct 2 version:
116 (64bit)

Thanks a lot for all the hard work.Alcemon2013-01-24 16:48:10
B
19
S
4
G
4
Posts: 70
Reputation: 3,896

Post » Thu Jan 24, 2013 10:01 pm

If you set your text to display Sprite.Angle, you'll notice that the angle is in fact not 60, but 60.00014... etc. It should probably be a whole number, don't know why it isn't.

You can use int(Sprite.Angle) to round off the value for now though.Nimtrix2013-01-24 22:02:54
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Fri Jan 25, 2013 8:59 am

Yes, I figured as much.

If you use only functions/methods specifically aimed at angles you should never run into this problem but as soon as you start treating angles as a "normal number" you will probably run into unexpected behaviors like this one.

The problem is that I cannot figure out if this is a bug or intended. At least I could not find any reference or warning to this behavior.
B
19
S
4
G
4
Posts: 70
Reputation: 3,896

Post » Fri Jan 25, 2013 12:53 pm

Closing as not a bug: as @Nimtrix said the angle is not actually 60, so it is correct that the comparison returns 0.

The reason why is internally angles are stored as radians, so converting from and to degrees causes slight floating point inaccuracies. This is normal in computing, and the standard thing to do is check if a number is within a range (e.g. abs(value - 60) < 0.01).
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Fri Jan 25, 2013 1:00 pm

Thanks for the answer.

It's probably worth to explain this fact to newcomers somewhere to save them some debug time and to make their lives easier.

Well...at least this forum thread should pop up now when searching for the issue
B
19
S
4
G
4
Posts: 70
Reputation: 3,896


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 0 guests