72 if (! _list)
return -1;
74 unsigned n = _list->length();
78 double x0 = (* _list)[0]->x();
79 double y0 = (* _list)[0]->y();
80 double x1 = (* _list)[1]->x();
81 double y1 = (* _list)[1]->y();
82 if (x0 == x1)
return -2;
83 _slope = (y0 - y1) / (x0 - x1);
84 _yOffset = - _slope * x1 + y1;
89 double sum = double(
n);
90 double sumX = 0., sumY = 0., sumX2 = 0., sumXY = 0., sumY2 = 0.;
91 for (
unsigned i = 0; i <
n; i++) {
102 _det = sum * sumX2 - sumX * sumX;
103 if (_det == 0.)
return -3;
105 _slope = (sumXY * sum - sumX * sumY) / _det;
106 _yOffset = (sumX2 * sumY - sumX * sumXY) / _det;