hEntity GraphicsWindow::SplitEntity(hEntity he, Vector pinter) { Entity *e = SK.GetEntity(he); int entityType = e->type; hEntity ret; if(e->IsCircle()) { ret = SplitCircle(he, pinter); } else if(e->type == Entity::LINE_SEGMENT) { ret = SplitLine(he, pinter); } else if(e->type == Entity::CUBIC || e->type == Entity::CUBIC_PERIODIC) { ret = SplitCubic(he, pinter); } else { Error("Couldn't split this entity; lines, circles, or cubics only."); return Entity::NO_ENTITY; } // Finally, delete the request that generated the original entity. int reqType = EntReqTable::GetRequestForEntity(entityType); SK.request.ClearTags(); for(int i = 0; i < SK.request.n; i++) { Request *r = &(SK.request.elem[i]); if(r->group.v != activeGroup.v) continue; if(r->type != reqType) continue; // If the user wants to keep the old entities around, they can just // mark them construction first. if(he.v == r->h.entity(0).v && !r->construction) { r->tag = 1; break; } } DeleteTaggedRequests(); return ret; }
/* *-------------------------------------------------------------------------------- * 函数名 : CreatePos * 功能 : 计算出轨迹上所有点的集合,保存到列表中去 * 算法 : 由五角星的外部五个顶点和内部五个顶点依次连线, * 能过 LineDDA 函数得出所有的轨迹点座标 * 前置条件 : 必须已经设定了轨迹起始点座标和终止点座标 * 后置条件 : 在 m_listTrackPoints 列表中保存所有轨迹点的座标 *-------------------------------------------------------------------------------- */ BOOL CFiveSideTrack::CreatePos() { CPoint ptOutVertex[5]; // 五等分圆,得到五个顶点座标 SplitCircle(m_ptTrackStartPoint, m_ptTrackEndPoint, 5, ptOutVertex); // 将五边形的外部五顶点依次连线用 LineDDA 得到轨迹点 LineDDA(ptOutVertex[0].x, ptOutVertex[0].y, ptOutVertex[1].x, ptOutVertex[1].y, CTrack::AddPosToList, (LPARAM) this); LineDDA(ptOutVertex[1].x, ptOutVertex[1].y, ptOutVertex[2].x, ptOutVertex[2].y, CTrack::AddPosToList, (LPARAM) this); LineDDA(ptOutVertex[2].x, ptOutVertex[2].y, ptOutVertex[3].x, ptOutVertex[3].y, CTrack::AddPosToList, (LPARAM) this); LineDDA(ptOutVertex[3].x, ptOutVertex[3].y, ptOutVertex[4].x, ptOutVertex[4].y, CTrack::AddPosToList, (LPARAM) this); LineDDA(ptOutVertex[4].x, ptOutVertex[4].y, ptOutVertex[0].x, ptOutVertex[0].y, CTrack::AddPosToList, (LPARAM) this); return TRUE; }
/* *-------------------------------------------------------------------------------- * 函数名 : Draw * 功能 : 画出椭圆轨迹 * 参数 : * CPoint& ptStart - 椭圆外围矩形左上角座标 * CPoint& ptEnd - 椭圆外围矩形右下角座标 * 算法 : 五等分圆得到五个顶点,再由此五点的交叉连线得到五个内部顶点 *-------------------------------------------------------------------------------- */ void CFiveSideTrack::Draw(const CPoint &ptStart, const CPoint &ptEnd) const { HDC hDC = m_hDC; if (ptStart.x == ptEnd.x && ptStart.y == ptEnd.y) { // 起点和终点相同,就画一个点 SetPixel(hDC, ptStart.x, ptEnd.y, TRACK_PEN_COLOR); return; } CPoint ptOutVertex[5]; // 五等分圆,得到五个顶点座标 SplitCircle(ptStart, ptEnd, 5, ptOutVertex); // 画五边形 MoveToEx(hDC, ptOutVertex[0].x, ptOutVertex[0].y, NULL); LineTo(hDC, ptOutVertex[1].x, ptOutVertex[1].y); LineTo(hDC, ptOutVertex[2].x, ptOutVertex[2].y); LineTo(hDC, ptOutVertex[3].x, ptOutVertex[3].y); LineTo(hDC, ptOutVertex[4].x, ptOutVertex[4].y); LineTo(hDC, ptOutVertex[0].x, ptOutVertex[0].y); }