X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fleast-squares.cc;h=f6d70478ce324920a8dfb4c3c430ba3ed62fa173;hb=ea20c95eec3f834ef7d63da4c31bf23bcd80ff28;hp=8100e7ebb8af4ffcaa2ec30353bbdd122a95eacf;hpb=667d9bdb6227dd10819599c6d069a5eeb67eedd7;p=lilypond.git diff --git a/lily/least-squares.cc b/lily/least-squares.cc index 8100e7ebb8..f6d70478ce 100644 --- a/lily/least-squares.cc +++ b/lily/least-squares.cc @@ -1,28 +1,27 @@ -/* - least-squares.cc -- implement minimise_least_squares - +/* + least-squares.cc -- implement minimise_least_squares + source file of the GNU LilyPond music typesetter - - (c) 1996--2002 Han-Wen Nienhuys - - */ + + (c) 1996--2005 Han-Wen Nienhuys +*/ #include "least-squares.hh" -#include "warn.hh" +#include "warn.hh" void -minimise_least_squares (Real * coef, Real * offset, +minimise_least_squares (Real *coef, Real *offset, Array const &input) { Real sx = 0.0; Real sy = 0.0; - Real sqx =0.0; + Real sqx = 0.0; Real sxy = 0.0; - for (int i=0; i < input.size ();i++) + for (int i = 0; i < input.size ();i++) { - Real x=input[i][X_AXIS]; + Real x = input[i][X_AXIS]; Real y = input[i][Y_AXIS]; sx += x; sy += y; @@ -31,20 +30,20 @@ minimise_least_squares (Real * coef, Real * offset, } int N = input.size (); - *coef =0.0; - *offset =0.; - - Real den = (N*sqx - sqr (sx)); + *coef = 0.0; + *offset = 0.; + + Real den = (N *sqx - sqr (sx)); if (!N || !den) { programming_error ("minimise_least_squares (): Nothing to minimise"); *coef = 0.0; - *offset = N ? sy/N : 0.0; + *offset = N ? sy / N : 0.0; } else { - *coef = (N * sxy - sx*sy)/den; - *offset = (sy - (*coef) * sx)/N; + *coef = (N *sxy - sx * sy) / den; + *offset = (sy - (*coef) * sx) / N; } }