This low-level trigonometry code is not only insanely hard to read, but unnecessarily slow. Consider the use of higher-level vector algebra, e.g. the
functions from Thor. It will increase development speed and reduce maintenance and debugging efforts.
Instead of
xS += ((x - tx) / sqrt(pow(x - tx, 2) + pow(y - ty, 2))) * speed;
yS += ((y - ty) / sqrt(pow(x - tx, 2) + pow(y - ty, 2))) * speed;
you write:
s += thor::unitVector(v - t) * speed;
Now tell me which one is more readable.
if ((xS >!mS) & (xS <! -mS))
if ((yS >!yS) & (yS <!- yS))
What exactly are you trying to achieve with those signs? <! and >! are neither digraphs nor operators, you're doing something terribly wrong here.
(675)
Another WTF snippet
These parentheses don't contribute to operator precedence.
While it is missing a case 0: it is also missing a default: as well for catching things like this. Default cases are good for when you are unsure if you've got all the cases and/or catching errors as well.
When you're unsure if you've got all the cases, you have a serious problem, because you don't understand your program's logic.
By adding a
default: case in such a case and performing regular logic (or nothing) inside it, you prevent possible compiler warnings and hide logic errors. The only sane thing to do in such a "catch-all"
default: label is an
assert(false);, because this branch of execution shall never be reached in a well-written program.
Note that I'm not talking against
default: when its intention is clear, but against the practice of adding it "if you're unsure".