After some mysterious behavior appeared in a project I've been working on, I finally figured out that controlP5 slider methods can give slightly inaccurate numbers! The issue appears to be in sliders only, as far as i can tell - a non-constraint of decimal places when dividing control location by the width of the control.
The code below illustrates the problem, the value is set to 2.00 and auto-initialization prints the value immediately to the p5 text window. The value is exactly 2.0 as you would expect. But set the control to 2.00 with the mouse and the value becomes 2.0066667, and you can't get it to exactly 2.0! At different pixel widths of controls this doesn't happen, as well as different ranges of minimum-maximum, again because it depends on non-rounded result of mathematical division. But it's a real problem if you enlarge a control, or change its max, and all of a sudden you're getting different numbers without knowing it.
It seems to me there needs to be a controller method to set desired places of decimal precision, or even better, a way to set how you want values incremented (e.g. by 0.1, 0.05, etc), so they would neatly snap. Of course this can be fixed easily with rounding in the controller function, but...
Code:
import controlP5.*;
ControlP5 controlP5;
float F = 2.0;
void setup() {
size(400,200, JAVA2D);
controlP5 = new ControlP5(this);
controlP5.setAutoInitialization(true);
controlP5.addSlider("Test", 0, 7, F, 20, 20,150,15);
}
void draw() {
background(0);
}
void Test(float _F) {
println(_F);
}