aboutsummaryrefslogtreecommitdiff
path: root/graphics/primitives.cpp
diff options
context:
space:
mode:
authorDavid Fioramonti2018-09-08 16:33:28 -0700
committerDavid Fioramonti2018-09-08 16:36:57 -0700
commita66e661df194963d4e649d122c33255e05a2e588 (patch)
tree4099907d33e71d64b0a4867adba74ecfbc3c4626 /graphics/primitives.cpp
parent5d77ade10bd1274756cb4a226080eb7673c0b693 (diff)
downloadscummvm-rg350-a66e661df194963d4e649d122c33255e05a2e588.tar.gz
scummvm-rg350-a66e661df194963d4e649d122c33255e05a2e588.tar.bz2
scummvm-rg350-a66e661df194963d4e649d122c33255e05a2e588.zip
GRAPHICS: Simplify trig usage in primitives
Combined if statements and simplified trig. cos(atan2(y,x)) = x / sqrt(x^2 + y^2) and sin(atan2(y,x)) = y / sqrt(x^2 + y^2).
Diffstat (limited to 'graphics/primitives.cpp')
-rw-r--r--graphics/primitives.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/graphics/primitives.cpp b/graphics/primitives.cpp
index 76c44b650d..1e48ca16b5 100644
--- a/graphics/primitives.cpp
+++ b/graphics/primitives.cpp
@@ -121,19 +121,16 @@ void drawThickLine2(int x1, int y1, int x2, int y2, int thick, int color, void (
if (dy <= dx) {
/* More-or-less horizontal. use wid for vertical stroke */
- /* Doug Claar: watch out for NaN in atan2 (2.0.5) */
/* 2.0.12: Michael Schwartz: divide rather than multiply;
TBB: but watch out for /0! */
- double ac = cos(atan2((double)dy, (double)dx));
- if (ac != 0) {
- wid = thick / ac;
+ if (dx != 0 && thick != 0) {
+ double ac_recip = 1/dx * sqrt(dx * dx + dy * dy); // 1 / cos(atan2((double)dy, (double)dx));
+ wid = thick * ac_recip;
} else {
wid = 1;
}
- if (wid == 0) {
- wid = 1;
- }
+
d = 2 * dy - dx;
incr1 = 2 * dy;
incr2 = 2 * (dy - dx);
@@ -185,14 +182,12 @@ void drawThickLine2(int x1, int y1, int x2, int y2, int thick, int color, void (
/* More-or-less vertical. use wid for horizontal stroke */
/* 2.0.12: Michael Schwartz: divide rather than multiply;
TBB: but watch out for /0! */
- double as = sin(atan2((double)dy, (double)dx));
- if (as != 0) {
- wid = thick / as;
+ if (dy != 0 && thick != 0) {
+ double as_recip = 1/dy * sqrt(dx * dx + dy * dy); // 1 / sin(atan2((double)dy, (double)dx));
+ wid = thick * as_recip;
} else {
wid = 1;
}
- if (wid == 0)
- wid = 1;
d = 2 * dx - dy;
incr1 = 2 * dx;