📄 line.cpp
字号:
return(false);}void KBoolLine::Create_Begin_Shape(KBoolLine* nextline,Node** _last_ins_left,Node** _last_ins_right,double factor,Graph *shape){ factor = fabs(factor); LinkStatus _outproduct; _outproduct= m_link->OutProduct(nextline->m_link,m_GC->GetAccur()); switch (_outproduct) { case IS_RIGHT : { *_last_ins_left = new Node(m_link->GetEndNode(), m_GC); Virtual_Point(*_last_ins_left,factor); *_last_ins_right = new Node(nextline->m_link->GetBeginNode(), m_GC); nextline->Virtual_Point(*_last_ins_right,-factor); shape->AddLink(*_last_ins_left, *_last_ins_right); *_last_ins_left=OffsetContour_rounded(nextline,*_last_ins_left,factor,shape); } break; case IS_LEFT : { *_last_ins_left = new Node(nextline->m_link->GetBeginNode(), m_GC); nextline->Virtual_Point(*_last_ins_left,factor); *_last_ins_right = new Node(m_link->GetEndNode(), m_GC); Virtual_Point(*_last_ins_right,-factor); shape->AddLink(*_last_ins_left, *_last_ins_right); *_last_ins_right=OffsetContour_rounded(nextline,*_last_ins_right,-factor,shape); } break; // Line 2 lies on this line case IS_ON : { *_last_ins_left = new Node(nextline->m_link->GetBeginNode(), m_GC); Virtual_Point(*_last_ins_left,factor); *_last_ins_right = new Node(nextline->m_link->GetBeginNode(), m_GC); Virtual_Point(*_last_ins_right,-factor); shape->AddLink(*_last_ins_left, *_last_ins_right); } break; }//end switch}void KBoolLine::Create_End_Shape(KBoolLine* nextline,Node* _last_ins_left,Node* _last_ins_right,double factor,Graph *shape){ Node* _current; factor = fabs(factor); LinkStatus _outproduct; _outproduct= m_link->OutProduct(nextline->m_link,m_GC->GetAccur()); switch (_outproduct) { case IS_RIGHT : { _current = new Node(m_link->GetEndNode(), m_GC); Virtual_Point(_current,-factor); shape->AddLink(_last_ins_right, _current); _last_ins_right=_current; _last_ins_left=OffsetContour_rounded(nextline,_last_ins_left,factor,shape); shape->AddLink(_last_ins_left,_last_ins_right); } break; case IS_LEFT : { _current = new Node(m_link->GetEndNode(), m_GC); Virtual_Point(_current,factor); shape->AddLink(_last_ins_left, _current); _last_ins_left=_current; _last_ins_right=OffsetContour_rounded(nextline,_last_ins_right,-factor,shape); shape->AddLink(_last_ins_right, _last_ins_left); } break; // Line 2 lies on this line case IS_ON : { _current = new Node(m_link->GetEndNode(), m_GC); Virtual_Point(_current,factor); shape->AddLink(_last_ins_left, _current); _last_ins_left=_current; _current = new Node(m_link->GetEndNode(), m_GC); Virtual_Point(_current,-factor); shape->AddLink(_last_ins_right, _current); _last_ins_right=_current; shape->AddLink(_last_ins_left, _last_ins_right); } break; }//end switch}//// Generate from the found crossings a part of the graph//bool KBoolLine::ProcessCrossings(TDLI<KBoolLink>* _LI){ Node *last; KBoolLink *dummy;// assert (beginnode && endnode); if (!linecrosslist) return false; if (linecrosslist->empty()) return false; if (linecrosslist->count()>1) SortLineCrossings(); m_link->GetEndNode()->RemoveLink(m_link); last=m_link->GetEndNode(); // Make new links : while (!linecrosslist->empty()) { dummy=new KBoolLink(m_link->GetGraphNum(),(Node*) linecrosslist->tailitem(),last, m_GC); dummy->SetBeenHere(); dummy->SetGroup(m_link->Group()); _LI->insbegin(dummy); last=(Node*)linecrosslist->tailitem(); linecrosslist->removetail(); } // Recycle this link : last->AddLink(m_link); m_link->SetEndNode(last); delete linecrosslist; linecrosslist=NULL; return true;}/*// Sorts the links on the X valuesint NodeXYsorter(Node* a, Node* b){ if ( a->GetX() < b->GetX()) return(1); if ( a->GetX() > b->GetX()) return(-1); //they are eqaul in x if ( a->GetY() < b->GetY()) return(-1); if ( a->GetY() > b->GetY()) return(1); //they are eqaul in y return(0);}//// Generate from the found crossings a part of the graph// this routine is used in combination with the scanbeam class// the this link most stay at the same place in the sorted graph// The link is split into peaces wich are inserted sorted into the graph// on beginnode.// The mostleft link most become the new link for the beam record// therefore the mostleft new/old link is returned to become the beam record link// also the part returned needs to have the bin flag set to the original value it had in the beamKBoolLink* KBoolLine::ProcessCrossingsSmart(TDLI<KBoolLink>* _LI){ Node *lastinserted; KBoolLink *new_link; KBoolLink *returnlink; assert (beginnode && endnode); if (!linecrosslist) return this; if (linecrosslist->empty()) return this; if (linecrosslist->count()>1) { SortLineCrossings(); } int inbeam; //most left at the beginnode or endnode if (NodeXYsorter(beginnode,endnode)==1) { //re_use this link endnode->RemoveLink(this); linecrosslist->insend(endnode); //the last link to create is towards this node endnode=(Node*) linecrosslist->headitem(); endnode->AddLink(this); inbeam=NodeXYsorter(_LI->item()->beginnode,beginnode); switch (inbeam) { case -1: case 0: bin=true; break; case 1: bin=false; break; } returnlink=this; lastinserted=endnode; linecrosslist->removehead(); // Make new links starting at endnode while (!linecrosslist->empty()) { new_link=new KBoolLink(graphnum,lastinserted,(Node*) linecrosslist->headitem()); new_link->group=group; int inbeam=NodeXYsorter(_LI->item()->beginnode,lastinserted); switch (inbeam) { case -1: { double x,y,xl,yl; char buf[80]; x=((Node*)(linecrosslist->headitem()))->GetX(); y=((Node*)(linecrosslist->headitem()))->GetY(); xl=_LI->item()->beginnode->GetX(); yl=_LI->item()->beginnode->GetY(); sprintf(buf," x=%f , y=%f inserted before %f,%f",x,y,xl,yl); _messagehandler->info(buf,"scanbeam"); new_link->bin=true; } break; case 0: new_link->bin=true; returnlink=new_link; break; case 1: new_link->bin=false; break; } //insert a link into the graph that is already sorted on beginnodes of the links. //starting at a given position // if empty then just insert if (_LI->empty()) _LI->insend(new_link); else { // put new item left of the one that is bigger are equal int i=0; int insert=0; while(!_LI->hitroot()) { if ((insert=linkXYsorter(new_link,_LI->item()))!=-1) break; (*_LI)++; i++; } _LI->insbefore_unsave(new_link); if (insert==0 && _LI->item()->beginnode!=new_link->beginnode) //the begin nodes are equal but not the same merge them into one node { Node* todelete=_LI->item()->beginnode; new_link->beginnode->Merge(todelete); delete todelete; } //set back iter (*_LI) << (i+1); } lastinserted=(Node*)linecrosslist->headitem(); linecrosslist->removehead(); } } else { //re_use this link endnode->RemoveLink(this); linecrosslist->insend(endnode); //the last link to create is towards this node endnode=(Node*) linecrosslist->headitem(); endnode->AddLink(this); inbeam=NodeXYsorter(_LI->item()->beginnode,endnode); switch (inbeam) { case -1: case 0: bin=true; break; case 1: bin=false; break; } returnlink=this; lastinserted=endnode; linecrosslist->removehead(); // Make new links starting at endnode while (!linecrosslist->empty()) { new_link=new KBoolLink(graphnum,lastinserted,(Node*) linecrosslist->headitem()); new_link->group=group; inbeam=NodeXYsorter(_LI->item()->beginnode,(Node*) linecrosslist->headitem()); switch (inbeam) { case -1: case 0: new_link->bin=true; break; case 1: new_link->bin=false; break; } inbeam=NodeXYsorter(_LI->item()->beginnode,lastinserted); switch (inbeam) { case -1: { double x,y,xl,yl; char buf[80]; x=lastinserted->GetX(); y=lastinserted->GetY(); xl=_LI->item()->beginnode->GetX(); yl=_LI->item()->beginnode->GetY(); sprintf(buf," x=%f , y=%f inserted before %f,%f",x,y,xl,yl); _messagehandler->info(buf,"scanbeam"); } break; case 0: break; case 1: returnlink=new_link; break; } //insert a link into the graph that is already sorted on beginnodes of the links. //starting at a given position // if empty then just insert if (_LI->empty()) _LI->insend(new_link); else { // put new item left of the one that is bigger are equal int i=0; int insert=0; while(!_LI->hitroot()) { if ((insert=linkXYsorter(new_link,_LI->item()))!=-1) break; (*_LI)++; i++; } _LI->insbefore_unsave(new_link); if (insert==0 && _LI->item()->beginnode!=new_link->beginnode) //the begin nodes are equal but not the same merge them into one node { Node* todelete=_LI->item()->beginnode; new_link->beginnode->Merge(todelete); delete todelete; } //set back iter (*_LI) << (i+1); } lastinserted=(Node*)linecrosslist->headitem(); linecrosslist->removehead(); } } delete linecrosslist; linecrosslist=NULL; return returnlink;}*/static int NODE_X_ASCENDING_L (Node* a, Node* b){ if(b->GetX() > a->GetX()) return(1); else if(b->GetX() == a->GetX()) return(0); return(-1);}static int NODE_X_DESCENDING_L(Node* a, Node* b){ if(a->GetX() > b->GetX()) return(1); else if(a->GetX() == b->GetX()) return(0); return(-1);}static int NODE_Y_ASCENDING_L (Node* a, Node* b){ if(b->GetY() > a->GetY()) return(1); else if(b->GetY() == a->GetY()) return(0); return(-1);}static int NODE_Y_DESCENDING_L(Node* a, Node* b){ if(a->GetY() > b->GetY()) return(1); else if(a->GetY() == b->GetY()) return(0); return(-1);}//// This function finds out which sortfunction to use with sorting// the crossings.//void KBoolLine::SortLineCrossings(){ TDLI<Node> I(linecrosslist); B_INT dx, dy; dx=babs(m_link->GetEndNode()->GetX() - m_link->GetBeginNode()->GetX()); dy=babs(m_link->GetEndNode()->GetY() - m_link->GetBeginNode()->GetY()); if (dx > dy) { // thislink is more horizontal then vertical if (m_link->GetEndNode()->GetX() > m_link->GetBeginNode()->GetX()) I.mergesort(NODE_X_ASCENDING_L); else I.mergesort(NODE_X_DESCENDING_L); } else { // this link is more vertical then horizontal if (m_link->GetEndNode()->GetY() > m_link->GetBeginNode()->GetY()) I.mergesort(NODE_Y_ASCENDING_L); else I.mergesort(NODE_Y_DESCENDING_L); }}//// Adds a cross Node to this. a_node may not be deleted before processing the crossings//void KBoolLine::AddCrossing(Node *a_node){ if (a_node==m_link->GetBeginNode() || a_node==m_link->GetEndNode()) return; if (!linecrosslist) { linecrosslist=new DL_List<void*>(); linecrosslist->insend(a_node); } else { TDLI<Node> I(linecrosslist); if (!I.has(a_node)) I.insend(a_node); }}//// see above//Node* KBoolLine::AddCrossing(B_INT X, B_INT Y){ Node* result=new Node(X,Y, m_GC); AddCrossing(result); return result;}DL_List<void*>* KBoolLine::GetCrossList(){ if (linecrosslist) return linecrosslist; return NULL;}bool KBoolLine::CrossListEmpty(){ if (linecrosslist) return linecrosslist->empty(); return true;}/*bool KBoolLine::HasInCrossList(Node *n){ if(linecrosslist!=NULL) { TDLI<Node> I(linecrosslist); return I.has(n); } return false;}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -