Clock: Point the hands precisely.

The clock hands do not always point exactly at the hour marks, which is
easy to see using Magnify (or a flat screen with sufficiently large
pixels): when a hand tries to points at 3 or 12 hours exactly, the
resulting line is not horizontal or vertical.

This is because the hands lines hinge on an array of coordinates, which
are calculated at run time using pi, and the calculation used to
approximate pi value as 3.1415.  This has been the case since respective
BeOS developer sample code from 1999 was imported into Haiku repository
in the initial commit in 2002.  Interestingly, BeOS R5.0.3 clock demo
does not have this bug.

Use M_PI for the pi value, point the hands precisely and fix my bug
report #19083.

Change-Id: Ie71889daed2efccd1596586f95b629f3b8e14c03
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8352
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Denis Ovsienko
2024-09-21 15:05:45 +00:00
committed by waddlesplash
parent 6d3408c82f
commit cd333360b3
+11 -8
View File
@@ -19,10 +19,13 @@
#include <time.h>
#include <math.h>
#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "Clock"
TOffscreenView::TOffscreenView(BRect frame, const char *name, short mRadius,
short hRadius, short offset, long face, bool show)
: BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),
@@ -77,27 +80,27 @@ dummy_label:
// Generate minutes points array
for (counter = 90; counter >= 0; counter -= 6, index++) {
x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
x = mRadius * cos(((360 - counter)/180.0) * M_PI);
x += 41;
y = mRadius * sin(((360 - counter)/180.0) * 3.1415);
y = mRadius * sin(((360 - counter)/180.0) * M_PI);
y += 41;
fMinutePoints[index].Set(x,y);
x = hRadius * cos(((360 - counter)/180.0) * 3.1415);
x = hRadius * cos(((360 - counter)/180.0) * M_PI);
x += 41;
y = hRadius * sin(((360 - counter)/180.0) * 3.1415);
y = hRadius * sin(((360 - counter)/180.0) * M_PI);
y += 41;
fHourPoints[index].Set(x,y);
}
for (counter = 354; counter > 90; counter -= 6,index++) {
x = mRadius * cos(((360 - counter)/180.0) * 3.1415);
x = mRadius * cos(((360 - counter)/180.0) * M_PI);
x += 41;
y = mRadius * sin(((360 - counter)/180.0) * 3.1415);
y = mRadius * sin(((360 - counter)/180.0) * M_PI);
y += 41;
fMinutePoints[index].Set(x,y);
x = hRadius * cos(((360 - counter)/180.0) * 3.1415);
x = hRadius * cos(((360 - counter)/180.0) * M_PI);
x += 41;
y = hRadius * sin(((360 - counter)/180.0) * 3.1415);
y = hRadius * sin(((360 - counter)/180.0) * M_PI);
y += 41;
fHourPoints[index].Set(x,y);
}