void CDrawShapeView::OnMouseMove(UINT nFlags, CPoint point) { CBaseView::OnMouseMove(nFlags, point); MgCommand* cmd = mgGetCommandManager()->getCommand(); m_proxy->motion.dragging = (!m_delayUp && (nFlags & MK_LBUTTON) && (m_downFlags & MK_LBUTTON)); if (m_proxy->motion.dragging) { m_proxy->motion.point = Point2d((float)point.x, (float)point.y); m_proxy->motion.pointM = m_proxy->motion.point * m_graph->xf.displayToModel(); if (!m_moved && mgHypot(m_proxy->motion.point.x - m_proxy->motion.startPoint.x, m_proxy->motion.point.y - m_proxy->motion.startPoint.y) > 5) { m_moved = TRUE; if (cmd) cmd->touchBegan(&m_proxy->motion); } else if (m_moved) { if (cmd) cmd->touchMoved(&m_proxy->motion); } m_proxy->motion.lastPoint = m_proxy->motion.point; m_proxy->motion.lastPointM = m_proxy->motion.pointM; } else if (cmd && !(nFlags & MK_LBUTTON)) { cmd->mouseHover(&m_proxy->motion); } }
bool mgcurv::arcTan( const Point2d& start, const Point2d& end, const Vector2d& startTan, Point2d& center, float& radius, float* startAngle, float* sweepAngle) { float a, b, c; // 弦的中垂线方程系数 a = end.x - start.x; b = end.y - start.y; c = -0.5f * (a*(end.x + start.x) + b*(end.y + start.y)); // 求中垂线和切线的交点center if (!mglnrel::crossLineAbc(a, b, c, startTan.x, startTan.y, -startTan.x * start.x - startTan.y * start.y, center, Tol::gTol())) return false; radius = mgHypot(center.x - start.x, center.y - start.y); if (startAngle && sweepAngle) { float sa = atan2f(start.y - center.y, start.x - center.x); float ea = atan2f(end.y - center.y, end.x - center.x); *startAngle = sa; if (startTan.crossProduct(start - center) > 0.f) *sweepAngle = -mgbase::to0_2PI(sa - ea); else *sweepAngle = mgbase::to0_2PI(ea - sa); } return true; }
bool mgcurv::arc3P( const Point2d& start, const Point2d& point, const Point2d& end, Point2d& center, float& radius, float* startAngle, float* sweepAngle) { float a1, b1, c1, a2, b2, c2; a1 = end.x - start.x; b1 = end.y - start.y; c1 = -0.5f * (a1 * (end.x + start.x) + b1 * (end.y + start.y)); a2 = end.x - point.x; b2 = end.y - point.y; c2 = -0.5f * (a2 * (end.x + point.x) + b2 * (end.y + point.y)); if (!mglnrel::crossLineAbc(a1, b1, c1, a2, b2, c2, center, Tol::gTol())) return false; radius = mgHypot(center.x - start.x, center.y - start.y); if (startAngle && sweepAngle) { // 分别计算圆心到三点的角度 float a = atan2f(start.y - center.y, start.x - center.x); float b = atan2f(point.y - center.y, point.x - center.x); float c = atan2f(end.y - center.y, end.x - center.x); *startAngle = a; // 判断圆弧的方向,计算转角 if (a < c) { if (a < b && b < c) // 逆时针 *sweepAngle = c - a; else *sweepAngle = c - a - _M_2PI; } else { if (a > b && b > c) // 顺时针 *sweepAngle = c - a; else *sweepAngle = _M_2PI-(a-c); } } return true; }
bool Matrix2d::isEqualTo(const Matrix2d& mat, const Tol& tol) const { return mgHypot(m11 - mat.m11, m12 - mat.m12) <= tol.equalVector() && mgHypot(m21 - mat.m21, m22 - mat.m22) <= tol.equalVector() && mgHypot(dx - mat.dx, dy - mat.dy) <= tol.equalVector(); }
float Matrix2d::scaleY() const { return mgIsZero(m21) ? fabsf(m22) : mgHypot(m21, m22); }
float Matrix2d::scaleX() const { return mgIsZero(m12) ? fabsf(m11) : mgHypot(m11, m12); }
float Matrix2d::scale() const { float sx = scaleX(); float sy = scaleY(); return fabsf(sx - sy) < _MGZERO ? sx : mgHypot(sx, sy); }
float MgBaseRect::getDiagonalLength() const { return mgHypot(getWidth(), getHeight()); }