ansonvwang / dat-gui

Automatically exported from code.google.com/p/dat-gui
0 stars 0 forks source link

Negative floating point range initialises incorrectly #52

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Steps to reproduce:

1. Add a new control with a range -1 to 1
2. Set the property value it binds to as a negative number (i.e. -0.55)

What's happening:
The range will be in increments of 1 between -1 and 1 but should be a floating 
point increment between that range. It will also show the current value as -1.

How to fix:
Sorry, just thought it was easier to provide the fix as it's a one liner and 
easier for the owners to add rather than me cloning the repo :)
Basically in the NumberController there is a line to init the impliedStep that 
looks like this:

this.__impliedStep = Math.pow(10, 
Math.floor(Math.log(this.initialValue)/Math.LN10))/10;

but should be this (to correctly account for the log of a negative number:

this.__impliedStep = Math.abs(Math.pow(10, 
Math.floor(Math.log(Math.abs(this.initialValue)) / Math.LN10)) / 10);

This change is working well for me and hope it helps in some small way :)

Thanks for the library too!

Original issue reported on code.google.com by paul.car...@gmail.com on 14 Aug 2014 at 11:25