vintagepc / MK404

A functional Simulator for Prusa (Mini/Einsy) Rambo based printers
https://vintagepc.github.io/MK404/
GNU General Public License v3.0
70 stars 9 forks source link

Remove the need to calculate sqrt by using squared distance #342

Closed GilesBathgate closed 2 years ago

GilesBathgate commented 2 years ago

Description

Minor performance tweak. When doing distance comparisons (c^2 = a^2+b^2), you can calculate c < 10, or you can do c^2 < 100.

Behaviour/ Breaking changes

Expect the same behaviour, and probably no noticeable performance gain, but still...

Have you tested the changes?

Yes, seems to work with MK3 as before.

GilesBathgate commented 2 years ago

Also note (f/5)^2 = f^2/5^2 ;)

vintagepc commented 2 years ago

Unfortunately the OSX compiler doesn't recognize that syntax:

/Users/runner/work/MK404/MK404/parts/components/PINDA.cpp:47:25: error: result of '10^2' is 8; did you mean '1e2'? [-Werror,-Wxor-used-as-pow]
                        if (fEdistSquared<(10^2))
                                           ~~^~
                                           1e2
/Users/runner/work/MK404/MK404/parts/components/PINDA.cpp:47:25: note: replace expression with '0xA ^ 2' or use 'xor' instead of '^' to silence this warning
vintagepc commented 2 years ago

... and more importantly, ^ is bitwise XOR, not "power"

GilesBathgate commented 2 years ago

@vintagepc Oh dear, schoolboy error. I've fixed it.

codecov[bot] commented 2 years ago

Codecov Report

Merging #342 (5a9e9c3) into master (c1a0c6b) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #342   +/-   ##
=======================================
  Coverage   91.14%   91.14%           
=======================================
  Files         166      166           
  Lines        7692     7692           
=======================================
  Hits         7011     7011           
  Misses        681      681           
Impacted Files Coverage Δ
parts/components/PINDA.cpp 96.87% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update c1a0c6b...5a9e9c3. Read the comment docs.