CPoint DiaEllipse::getCrossPoint(const CPoint& from, const CPoint& to) const { CPoint center = getCentralPoint(); double distance = sqrt(pow(static_cast<double>(to.x) - from.x, 2) + pow(static_cast<double>(to.y) - from.y, 2)); double distance_y = to.y - from.y; double distance_x = to.x - from.x; double sin_gamma = distance_y / distance; double cos_gamma = distance_x / distance; double a = (m_x2 - m_x1) / 2; double b = (m_y2 - m_y1) / 2; double radius = a*b / (sqrt( pow(b,2)*pow(cos_gamma,2) + pow(a,2)*pow(sin_gamma,2) )); double a1 = radius * cos_gamma; double b1 = radius * sin_gamma; double result_x = from.x + a1; double result_y = from.y + b1; if (to == center) { result_x = to.x - a1; result_y = to.y - b1; } return CPoint(static_cast<int>(result_x), static_cast<int>(result_y)); }
void DiaEntity::setCentralPoint(CPoint point) { CPoint oldPoint = getCentralPoint(); std::pair<LONG,LONG> vec; vec.first = point.x - oldPoint.x; vec.second = point.y - oldPoint.y; applyVec(vec); }
QPoint MyMoveServer::normalizeGesture(QList<QPoint>& gesture) { // Normalize the gesture int gw = 0; int gh = 0; QPoint cp = getCentralPoint(gesture, gw, gh); int tmp = 0; //qDebug("gw: %d, gh: %d", gw, gh); for (int i=0; i < gesture.length(); i++) { gesture[i].rx() -= cp.x(); gesture[i].ry() -= cp.y(); gesture[i].rx() = (int)(gesture[i].x()*(1000.0/gw)); gesture[i].ry() = (int)(gesture[i].y()*(500.0/gh)); //qDebug("%d %d", gesture[i].x(), gesture[i].y()); } return cp; }
BOOL DiaGridView::GetStyleRowCol( ROWCOL nRow, ROWCOL nCol, CGXStyle& style, GXModifyType mt, int nType ) { auto cell = GetRowData(nRow); if( !cell ) return FALSE; CPoint point = cell->getCentralPoint(); switch(nCol) { case 1: style.SetValue(getStringFigureTypeName( cell->type() )); return TRUE; case 2: style.SetValue(point.x); return TRUE; case 3: style.SetValue(point.y); return TRUE; case 4: style .SetControl(GX_IDS_CTRL_COMBOBOX) .SetChoiceList("solid\ndash\ndashdot\ndashdotdot") .SetValue(getStringContourTypeName( cell->getContourStyle() )); return TRUE; case 5: style .SetControl(GX_IDS_CTRL_HOTSPOT) .SetInterior(cell->getContourColor()); return TRUE; } return FALSE; }