QRDecomposition::QRDecomposition(Mat* pA, Matd* pmQR/*=NULL*/) { m_pmQR = new Mat (*pA); // Initialize. QR = m_pmQR->data.db; m = m_pmQR->Rows(); n = m_pmQR->Cols(); Rdiag = new double[n]; // Main loop. for (int k = 0; k < n; k++) { // Compute 2-norm of k-th column without under/overflow. double nrm = 0; for (int i = k; i < m; i++) { nrm = Hypot(nrm, QR[i][k]); } if (nrm != 0.0) { // Form k-th Householder vector. if (QR[k][k] < 0) { nrm = - nrm; } for (int i = k; i < m; i++) { QR[i][k] /= nrm; } QR[k][k] += 1.0; // Apply transformation to remaining columns. for (int j = k + 1; j < n; j++) { int i; double s = 0.0; for (i = k; i < m; i++) { s += QR[i][k] * QR[i][j]; } s = (- s) / QR[k][k]; for (i = k; i < m; i++) { QR[i][j] += s * QR[i][k]; } } } Rdiag[k] = - nrm; } }
static void MouseButtonDown(AG_Event *event) { AG_HSVPal *pal = AG_SELF(); int btn = AG_INT(1); int x = AG_INT(2); int y = AG_INT(3); float r; if (!AG_WidgetIsFocused(pal)) AG_WidgetFocus(pal); switch (btn) { case AG_MOUSE_LEFT: if (y > pal->rAlpha.y) { UpdateAlpha(pal, x); pal->state = AG_HSVPAL_SEL_A; } else { x -= pal->circle.x; y -= pal->circle.y; r = Hypot((float)x, (float)y); if (r > (float)pal->circle.rin) { UpdateHue(pal, x, y); pal->state = AG_HSVPAL_SEL_H; } else { UpdateSV(pal, AG_INT(2), AG_INT(3)); pal->state = AG_HSVPAL_SEL_SV; } } AG_Redraw(pal); break; case AG_MOUSE_MIDDLE: case AG_MOUSE_RIGHT: OpenMenu(pal, x,y); break; } }
//----------------------------------------------------------------- float Dist(const Molecule &m1, const Molecule &m2) { return Hypot(m1.x-m2.x,m1.y-m2.y); }