ofxHistoryPlot icon indicating copy to clipboard operation
ofxHistoryPlot copied to clipboard

issue in drawing horizontalGuides

Open johanjohan opened this issue 7 years ago • 3 comments

hey armadillu, thank you for the addon. using it i realize the following:

  • horizontalGuides get drawn at bad y-location due to issues in ofMap. i guess values are clamped to outputMin in case of FLT_EPSILON or there is a general float issue. it works with ofMap in double:
double ofMapDouble(double value, double inputMin, double inputMax, double outputMin, double outputMax, bool clamp) {

	if (std::abs(inputMin - inputMax) < DBL_EPSILON) {
		return outputMin;
	}
	else {
		double outVal = ((value - inputMin) / (inputMax - inputMin) * (outputMax - outputMin) + outputMin);

		if (clamp) {
			if (outputMax < outputMin) {
				if (outVal < outputMax)outVal = outputMax;
				else if (outVal > outputMin)outVal = outputMin;
			}
			else {
				if (outVal > outputMax)outVal = outputMax;
				else if (outVal < outputMin)outVal = outputMin;
			}
		}
		return outVal;
	}
}

  • furthermore, plotting values are shifted off horizontalGuides with the same y in case of respectBorders == true.

example: setting the range to [-0.00000001, +0.00000001] places a horizontalGuides with y=0 not in the center. once i correct that using ofMapDouble, drawing plotting values with y= 0 are not exactly on the horizontalGuide, but shifted due to respectBorders .

johanjohan avatar Sep 18 '17 02:09 johanjohan

hmmm it seems you are using really small values; OpenFrameworks doesn't really have support for float/double across the board, so I recommend you feed in larger values to the plot... Alternatively I could make a float/double version of it, but I think ofMesh only handles float so it would probably give trouble at draw time anyway

armadillu avatar Sep 25 '17 21:09 armadillu

yes, i am using a wide range of numbers. there is no need to change the whole addon to double, as i indicated, a substitution of ofMap() with double precision does the job in ofxHistoryPlot::draw():

	for(size_t i = 0; i < horizontalGuides.size(); i++){
		float myY = horizontalGuides[i];
		if (myY > plotLow && myY < plotHigh){ //TODO negative!
			float yy = ofMapDouble(myY, plotLow, plotHigh, 0, h, true); // MS was ofMap
			if(drawGuideValues){
				ofSetColor(horizontalGuideColors[i], 111); // 50
				ofDrawBitmapString(ofToString(horizontalGuides[i], precision), 10 + x, y + h - yy + 10 );
			}
			ofSetColor(horizontalGuideColors[i], 64 );
			ofDrawLine(x, y + h - yy, x + w, y + h - yy); // orig
		}
	}

ofMap chops small values to outputMin at FLT_EPSILON. that's all

johanjohan avatar Sep 26 '17 08:09 johanjohan

I see, thx! Do you want to make a PR with the necessary changes? I'm cool with replacing all ofMap() calls to a custom ofMap().

armadillu avatar Sep 27 '17 15:09 armadillu