X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fleast-squares.cc;h=492f5ff65d47c9694f22fcc2b967d5f934eb879e;hb=5b4b0d6e9a197e8f9eb085b7c2ad78b8be3e5cfc;hp=f6d70478ce324920a8dfb4c3c430ba3ed62fa173;hpb=bdf4ab13203502e7ec7cf9cf5896527643a07c1f;p=lilypond.git diff --git a/lily/least-squares.cc b/lily/least-squares.cc index f6d70478ce..492f5ff65d 100644 --- a/lily/least-squares.cc +++ b/lily/least-squares.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1996--2005 Han-Wen Nienhuys + (c) 1996--2008 Han-Wen Nienhuys */ #include "least-squares.hh" @@ -12,14 +12,14 @@ void minimise_least_squares (Real *coef, Real *offset, - Array const &input) + vector const &input) { Real sx = 0.0; Real sy = 0.0; Real sqx = 0.0; Real sxy = 0.0; - for (int i = 0; i < input.size ();i++) + for (vsize i = 0; i < input.size ();i++) { Real x = input[i][X_AXIS]; Real y = input[i][Y_AXIS]; @@ -28,22 +28,25 @@ minimise_least_squares (Real *coef, Real *offset, sqx += sqr (x); sxy += x*y; } - int N = input.size (); + + int count = input.size (); *coef = 0.0; *offset = 0.; - Real den = (N *sqx - sqr (sx)); - if (!N || !den) + Real den = (count * sqx - sqr (sx)); + if (!count || !den) { - programming_error ("minimise_least_squares (): Nothing to minimise"); + programming_error ("minimise_least_squares (): Nothing to minimise\n" + "This means that vertical spacing is triggered\n" + "before line breaking\n"); *coef = 0.0; - *offset = N ? sy / N : 0.0; + *offset = count ? sy / count : 0.0; } else { - *coef = (N *sxy - sx * sy) / den; - *offset = (sy - (*coef) * sx) / N; + *coef = (count * sxy - sx * sy) / den; + *offset = (sy - (*coef) * sx) / count; } }