]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/bezier.cc
Run `make grand-replace'.
[lilypond.git] / lily / bezier.cc
index f5489e7d40b16825bc18728800073f582895b7a3..18d7836cbfe1d37762ccf8ce4d5134affe8f949e 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1998--2006 Jan Nieuwenhuizen <janneke@gnu.org>
+  (c) 1998--2008 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
 #include "bezier.hh"
@@ -14,21 +14,6 @@ Real binomial_coefficient_3[] = {
   1, 3, 3, 1
 };
 
-Real
-binomial_coefficient (Real over, int under)
-{
-  Real x = 1.0;
-
-  while (under)
-    {
-      x *= over / Real (under);
-
-      over -= 1.0;
-      under--;
-    }
-  return x;
-}
-
 void
 scale (vector<Offset> *array, Real x, Real y)
 {
@@ -132,33 +117,30 @@ Bezier::curve_point (Real t) const
 }
 
 /*
-  Cache binom(3,j) t^j (1-t)^{3-j}
+  Cache binom (3, j) t^j (1-t)^{3-j}
 */
-static struct Polynomial bezier_term_cache[4];
-static bool done_cache_init;
+struct Polynomial_cache {
+  Polynomial terms_[4];
+  Polynomial_cache ()
+  {
+    for (int j = 0; j <= 3; j++)
+      terms_[j]
+       = binomial_coefficient_3[j]
+       * Polynomial::power (j, Polynomial (0, 1))
+       * Polynomial::power (3 - j, Polynomial (1, -1));
+  }
+};
 
-void
-init_polynomial_cache ()
-{
-  for (int j = 0; j <= 3; j++)
-    bezier_term_cache[j]
-      = binomial_coefficient_3[j]
-      * Polynomial::power (j, Polynomial (0, 1))
-      * Polynomial::power (3 - j, Polynomial (1, -1));
-  done_cache_init = true;
-}
+static Polynomial_cache poly_cache;
 
 Polynomial
 Bezier::polynomial (Axis a) const
 {
-  if (!done_cache_init)
-    init_polynomial_cache ();
-
   Polynomial p (0.0);
   Polynomial q;
   for (int j = 0; j <= 3; j++)
     {
-      q = bezier_term_cache[j];
+      q = poly_cache.terms_[j];
       q *= control_[j][a];
       p += q;
     }