]> granicus.if.org Git - graphviz/commitdiff
rephrase some magic numbers in Smyrna into their originating computation
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 26 May 2021 15:12:03 +0000 (08:12 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 29 May 2021 00:58:17 +0000 (17:58 -0700)
This removes the use of some double literals with implicit conversion to floats,
squashing some -Wfloat-conversion compiler warnings. It also makes the resulting
code clearer. The compiler constant-folds these at -O1 and above, so there is no
loss of performance. The resulting expressions are slightly different to the
original, but if anything they are a more accurate representation of the intent
here.

CHANGELOG.md
cmd/smyrna/trackball.c

index 64921974433e3f678eaab675f2de7a0ab82500ec..a62750f338401c4f02b6c321f784be2e7bf7e656 100644 (file)
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## [Unreleased]
 
+### Changed
+
+- marginally more accurate computations in Smyrna sphere projection
+
 ## [2.47.2] - 2021-05-26
 
 ### Added
index a49ad5cce3b82bd445283b9b80d9906fccd61e3b..041f1165ca47dec6a46810dbf715aec1f547ef5e 100644 (file)
@@ -208,10 +208,10 @@ static float tb_project_to_sphere(float r, float x, float y)
     float d, t, z;
 
     d = hypotf(x, y);
-    if (d < r * 0.70710678118654752440) {      /* Inside sphere */
+    if (d < r * (1.0f / sqrtf(2.0f))) {        /* Inside sphere */
        z = sqrt(r * r - d * d);
     } else {                   /* On hyperbola */
-       t = r / 1.41421356237309504880;
+       t = r / sqrtf(2.0f);
        z = t * t / d;
     }
     return z;