X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fleast-squares.cc;h=582e5b0dcb2bb655832512338f0fe57489f77cd8;hb=f26ba98bff8314bf0b379d3eea7fb3bee7e31dc3;hp=79d463d184802722a5f8693636d3d358796872df;hpb=75eebcb49e52d296b1da3e1074e0825d2c780db4;p=lilypond.git diff --git a/lily/least-squares.cc b/lily/least-squares.cc index 79d463d184..582e5b0dcb 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--2006 Han-Wen Nienhuys + (c) 1996--2007 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; } }