[Kst] extragear/graphics/kst/kst
Andrew Walker
arwalker at sumusltd.com
Tue May 10 21:18:50 CEST 2005
SVN commit 412117 by arwalker:
Fix round off problems. BUG:104933
M +44 -27 trunk/extragear/graphics/kst/kst/kst2dplot.cpp
--- trunk/extragear/graphics/kst/kst/kst2dplot.cpp #412116:412117
@@ -1335,7 +1335,26 @@
double xmin, ymin, xmax, ymax;
double xdelta;
int accuracy = 0;
-
+
+ // check how many decimal places we need based on the scale
+ getLScale(xmin,ymin,xmax,ymax);
+ if (isXLog()) {
+ xdelta = (pow(10.0,xmax)-pow(10.0,xmin))/(double)pr.width();
+ } else {
+ xdelta = (xmax-xmin)/(double)pr.width();
+ }
+ xdelta = convertTimeDiffValueToDays(axisInterpretation, xdelta);
+ xdelta *= 24.0 * 60.0 * 60.0;
+
+ if (xdelta == 0.0) {
+ accuracy = FULL_PRECISION;
+ } else {
+ accuracy = 1 - int(log10(xdelta));
+ if (accuracy < 0) {
+ accuracy = 0;
+ }
+ }
+
if (axisTimezoneLocal) {
dJD += timezoneHrs() / 24.0;
} else {
@@ -1361,6 +1380,28 @@
dJDDay += 1.0;
}
+ // get time of day from day fraction
+ int hour = int(dDayFraction*24.0);
+ int minute = int((dDayFraction*24.0 - (double)hour)*60.0);
+ double second = ((dDayFraction*24.0 - (double)hour)*60.0 - (double)minute)*60.0;
+
+ if (accuracy >= 0) {
+ second *= pow(10.0,accuracy);
+ second = floor(second+0.5);
+ second /= pow(10.0,accuracy);
+ if (second >= 60.0) {
+ second -= 60.0;
+ minute++;
+ if (minute == 60) {
+ minute = 0;
+ hour++;
+ if (hour == 24) {
+ hour = 0;
+ }
+ }
+ }
+ }
+
double j2 = dJDDay + 1524.0;
double j3 = floor(6680.0 + ( (j2 - 2439870.0) - 122.1 )/365.25);
double j4 = floor(j3 * 365.25);
@@ -1378,31 +1419,7 @@
if (year <= 0) {
--year;
}
-
- // get time of day from day fraction
- int hour = int(dDayFraction*24.0);
- int minute = int((dDayFraction*24.0 - (double)hour)*60.0);
- double second = ((dDayFraction*24.0 - (double)hour)*60.0 - (double)minute)*60.0;
-
- // check how many decimal places we need based on the scale
- getLScale(xmin,ymin,xmax,ymax);
- if (isXLog()) {
- xdelta = (pow(10.0,xmax)-pow(10.0,xmin))/(double)pr.width();
- } else {
- xdelta = (xmax-xmin)/(double)pr.width();
- }
- xdelta = convertTimeDiffValueToDays(axisInterpretation, xdelta);
- xdelta *= 24.0 * 60.0 * 60.0;
-
- if (xdelta == 0.0) {
- accuracy = FULL_PRECISION;
- } else {
- accuracy = 1 - int(log10(xdelta));
- if (accuracy < 0) {
- accuracy = 0;
- }
- }
-
+
// check how many decimal places for the seconds we actually need to show
if (accuracy > 0) {
QString strSecond;
@@ -1444,7 +1461,7 @@
length += 6;
length += accuracy;
}
-
+
switch (axisDisplay) {
case AXIS_DISPLAY_YYMMDDHHMMSS_SS:
label.sprintf("%d/%02d/%02d %02d:%02d:%02.*f", year, month, day, hour, minute, accuracy, second);
More information about the Kst
mailing list