void DocEdit::Paint(Draw& w) { Size sz = GetSize(); Color bg = color[IsShowEnabled() && !IsReadOnly() ? PAPER_NORMAL : PAPER_READONLY]; if(nobg) bg = Null; int y = -sb + 1; int pos = 0; int sell, selh; GetSelection(sell, selh); for(int i = 0; i < para.GetCount() && y < sz.cy; i++) { int h = GetHeight(i); if(y + h >= 0) { WString text = line[i]; Fmt fmt = Format(text); int p = pos; for(int i = 0; i < fmt.line.GetCount(); i++) { int n = fmt.LineEnd(i) - fmt.line[i]; int a = minmax(sell - p, 0, n); int b = minmax(selh - p, 0, n) - a; int c = n - a - b; int *wa = fmt.width + fmt.line[i]; int *wb = fmt.width + fmt.line[i] + a; int *wc = fmt.width + fmt.line[i] + a + b; int acx = sSum(wa, a); int bcx = sSum(wb, b); int ccx = sSum(wc, c); w.DrawRect(1, y, acx, fmt.fi.GetHeight(), bg); w.DrawText(1, y, ~fmt.text + fmt.line[i], font, IsShowEnabled() ? color[INK_NORMAL] : color[INK_DISABLED], a, wa); w.DrawRect(1 + acx, y, bcx, fmt.fi.GetHeight(), color[PAPER_SELECTED]); w.DrawText(1 + acx, y, ~fmt.text + fmt.line[i] + a, font, color[INK_SELECTED], b, wb); w.DrawRect(1 + acx + bcx, y, ccx, fmt.fi.GetHeight(), bg); w.DrawText(1 + acx + bcx, y, ~fmt.text + fmt.line[i] + a + b, font, color[INK_NORMAL], c, wc); p += n; w.DrawRect(1 + acx + bcx + ccx, y, cx - (acx + bcx + ccx), fmt.fi.GetHeight(), p >= sell && p < selh ? color[PAPER_SELECTED] : bg); y += fmt.fi.GetHeight(); } w.DrawRect(1, y, cx, after, color[PAPER_NORMAL]); y += after; } else y += h; pos += line[i].GetLength() + 1; } w.DrawRect(0, -sb, sz.cx, 1, bg); w.DrawRect(0, 0, 1, sz.cy, bg); w.DrawRect(sz.cx - 1, 0, 1, sz.cy, bg); if(eofline) w.DrawRect(1, y++, cx, 1, SColorShadow); if(y < sz.cy) w.DrawRect(1, y, cx, sz.cy - y, bg); DrawTiles(w, DropCaret(), CtrlImg::checkers()); }
FouPack::FouPack(const QVector< double >* T, const QVector< double >* Y, int FouDegree, double FouShortestPeriod_h) : MinPack(T, Y), fouDegree(FouDegree), fouShortestPeriod_h(FouShortestPeriod_h), Pyy(0), s(fouDegree+1, QVector<double>(t->size(), 1)), c(fouDegree+1, QVector<double>(t->size(), 1)), mat_LU (gsl_matrix_alloc (2*fouDegree+1, 2*fouDegree+1)), per (gsl_permutation_alloc(2*fouDegree+1)), Dy (gsl_vector_alloc (2*fouDegree+1)) { gsl_vector *wy = gsl_vector_calloc (2*fouDegree+1); // set to 0 for (int tNr = 0; tNr < y->size(); tNr++) wy->data[0] += y->at(tNr); gsl_matrix_set(mat_LU, 0, 0, t->size()); vector<double> sSum(2*fouDegree+1); vector<double> cSum(2*fouDegree+1); sSum[0] = 0; cSum[0] = t->size(); for (int tNr = 0; tNr < t->size(); tNr++) { const double tPha = 2*M_PI * 24.0 * t->at(tNr) / fouDegree / fouShortestPeriod_h; for (int deg = 1; deg <= fouDegree; deg++) { s[deg][tNr] = sin(deg*tPha); c[deg][tNr] = cos(deg*tPha); sSum[deg] += s[deg][tNr]; cSum[deg] += c[deg][tNr]; wy->data[deg] += y->at(tNr)*s[deg][tNr]; wy->data[deg+fouDegree] += y->at(tNr)*c[deg][tNr]; } for (int deg = fouDegree+1; deg <= 2*fouDegree; deg++) { sSum[deg] += sin(deg*tPha); cSum[deg] += cos(deg*tPha); } } for (int deg = 1; deg <= fouDegree; deg++) { gsl_matrix_set(mat_LU, 0, deg, sSum[deg]); gsl_matrix_set(mat_LU, 0, deg+fouDegree, cSum[deg]); gsl_matrix_set(mat_LU, deg, 0, sSum[deg]); gsl_matrix_set(mat_LU, deg+fouDegree, 0, cSum[deg]); for (int deg2 = 1; deg2 < deg; deg2++) { gsl_matrix_set(mat_LU, deg, deg2, 0.5*(cSum[deg-deg2]-cSum[deg+deg2])); gsl_matrix_set(mat_LU, deg+fouDegree, deg2, 0.5*(sSum[deg+deg2]-sSum[deg-deg2])); // sin changes sign gsl_matrix_set(mat_LU, deg, deg2+fouDegree, 0.5*(sSum[deg+deg2]+sSum[deg-deg2])); // sin changes sign gsl_matrix_set(mat_LU, deg+fouDegree, deg2+fouDegree, 0.5*(cSum[deg-deg2]+cSum[deg+deg2])); } for (int deg2 = deg; deg2 <= fouDegree; deg2++) { gsl_matrix_set(mat_LU, deg, deg2, 0.5*(cSum[deg2-deg]-cSum[deg2+deg])); gsl_matrix_set(mat_LU, deg+fouDegree, deg2, 0.5*(sSum[deg2+deg]+sSum[deg2-deg])); // sin changes sign gsl_matrix_set(mat_LU, deg, deg2+fouDegree, 0.5*(sSum[deg2+deg]-sSum[deg2-deg])); // sin changes sign gsl_matrix_set(mat_LU, deg+fouDegree, deg2+fouDegree, 0.5*(cSum[deg2-deg]+cSum[deg2+deg])); } } int sign; gsl_linalg_LU_decomp (mat_LU, per, &sign); gsl_linalg_LU_solve(mat_LU, per, wy, Dy); const double NMyy = Dy->data[0] * wy->data[0]; double Psyys = 0, Pcyyc = 0; for (int deg = 1; deg <= fouDegree; deg++) { Psyys += Dy->data[deg] * wy->data[deg]; Pcyyc += Dy->data[deg+fouDegree] * wy->data[deg+fouDegree]; } Pyy = yy - NMyy - Psyys - Pcyyc; gsl_vector_free(wy); func.n = 2; func.f = f; func.df = df; func.fdf = fdf; func.params = reinterpret_cast<void*>(this); }