X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fleast-squares.cc;h=77113e940b5169b291a3112388517076bd21f4f1;hb=36342ddfdbf0c112be9cb4ce471417e9c0e8fa1f;hp=abac75b1bd0e856cd8fcfaa39222703087cd9331;hpb=c659cb200486c2f908703696a1b2873e78c8160a;p=lilypond.git diff --git a/lily/least-squares.cc b/lily/least-squares.cc index abac75b1bd..77113e940b 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--2004 Han-Wen Nienhuys - - */ + + (c) 1996--2005 Han-Wen Nienhuys +*/ #include "least-squares.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; } }