⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 line.cpp

📁 EDA PCB 电路设计工具源码 c/c++ for Linux, Windows, Mac, 2008.8 最新
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	ep = lijn->m_link->GetEndNode();  	Result_beginnode = PointInLine(bp,distance,Marge);	Result_endnode   = PointInLine(ep,distance,Marge);	Take_Action1 = ActionOnTable1(Result_beginnode,Result_endnode);	// The first switch will insert a crosspoint immediatly	switch (Take_Action1)	{		// for the cases see the returnvalue of ActionTable1		case 2: case 6: AddCrossing(ep);							 Number_of_Crossings = 1;							 break;		case 3: case 5: AddCrossing(bp);							 Number_of_Crossings = 1;							 break;		case 4: 			 AddCrossing(bp);							 AddCrossing(ep);							 Number_of_Crossings = 2;							 break;	}	// This switch wil investigate the points of this line in relation to lijn	switch (Take_Action1)	{		// for the cases see the returnvalue of ActionTable1		case 1: case 5: case 6:		  {				// Get the nodes from this line via the link				bp = m_link->GetBeginNode();				ep = m_link->GetEndNode();            Result_beginnode = lijn->PointInLine(bp,distance,Marge);            Result_endnode   = lijn->PointInLine(ep,distance,Marge);				Take_Action2 = ActionOnTable2(Result_beginnode,Result_endnode);				switch (Take_Action2)				{					// for the cases see the returnvalue of ActionTable2					case 1: {   // begin of scope to calculate the intersection									double X, Y, Denominator;									CalculateLineParameters();									Denominator  = (m_AA * lijn->m_BB) - (lijn->m_AA * m_BB);									// Denominator may not be 0									assert(Denominator != 0.0);									// Calculate intersection of both linesegments									X = ((m_BB * lijn->m_CC) - (lijn->m_BB * m_CC)) / Denominator;									Y = ((lijn->m_AA * m_CC) - (m_AA * lijn->m_CC)) / Denominator;                           //make a decent rounding to B_INT                           AddLineCrossing((B_INT)X,(B_INT)Y,lijn);							  }   // end of scope to calculate the intersection							  Number_of_Crossings++;							  break;					case 2: lijn->AddCrossing(ep);							  Number_of_Crossings++;							  break;					case 3: lijn->AddCrossing(bp);							  Number_of_Crossings++;							  break;					case 4: lijn->AddCrossing(bp);							  lijn->AddCrossing(ep);							  Number_of_Crossings = 2;							  break;				}		  }; break; // This break belongs to the outer switch	}	return Number_of_Crossings; //This is de final number of crossings}// Intersects two lines there must be a crossingint KBoolLine::Intersect_simple(KBoolLine * lijn){	// lijn must exist	assert(lijn);	double X, Y, Denominator;	Denominator  = (m_AA * lijn->m_BB) - (lijn->m_AA * m_BB);	// Denominator may not be 0	if (Denominator == 0.0)			m_GC->error("colliniar lines","line");	// Calculate intersection of both linesegments	X = ((m_BB * lijn->m_CC) - (lijn->m_BB * m_CC)) / Denominator;	Y = ((lijn->m_AA * m_CC) - (m_AA * lijn->m_CC)) / Denominator;	AddLineCrossing((B_INT)X,(B_INT)Y,lijn);	return(0);}// Intersects two lines there must be a crossingbool KBoolLine::Intersect2(Node* crossing,KBoolLine * lijn){	// lijn must exist	assert(lijn);	double X, Y, Denominator;	Denominator  = (m_AA * lijn->m_BB) - (lijn->m_AA * m_BB);	// Denominator may not be 0	if (Denominator == 0.0)		return false;	// Calculate intersection of both linesegments	X = ((m_BB * lijn->m_CC) - (lijn->m_BB * m_CC)) / Denominator;	Y = ((lijn->m_AA * m_CC) - (m_AA * lijn->m_CC)) / Denominator;	crossing->SetX((B_INT)X);	crossing->SetY((B_INT)Y);	return true;}//// test if a point lies in the linesegment. If the point isn't on the line// the function returns a value that indicates on which side of the// line the point is (in linedirection from first point to second point//// returns LEFT_SIDE, when point lies on the left side of the line//         RIGHT_SIDE, when point lies on the right side of the line//         ON_AREA, when point lies on the infinite line within a range//			  IN_AREA, when point lies in the area of the linesegment// 		  the returnvalues are declared in (LINE.H)PointStatus KBoolLine::PointInLine(Node *a_node, double& Distance, double Marge){	  Distance=0;	  //Punt must exist	  assert(a_node);	  // link must exist to get beginnode and endnode via link	  assert(m_link);	  // get the nodes form the line via the link	  Node *bp, *ep;	  bp = m_link->GetBeginNode();	  ep = m_link->GetEndNode();	  // both node must exist	  assert(bp && ep);	  // node may not be the same	  assert(bp != ep);     //quick test if point is begin or endpoint     if (a_node == bp || a_node == ep)        return IN_AREA;	  int Result_of_BBox=false;	  PointStatus Result_of_Online;	  // Checking if point is in bounding-box with marge     B_INT xmin=bmin(bp->GetX(),ep->GetX());     B_INT xmax=bmax(bp->GetX(),ep->GetX());     B_INT ymin=bmin(bp->GetY(),ep->GetY());     B_INT ymax=bmax(bp->GetY(),ep->GetY());     if (  a_node->GetX() >= (xmin - Marge) && a_node->GetX() <= (xmax + Marge) &&           a_node->GetY() >= (ymin - Marge) && a_node->GetY() <= (ymax + Marge) )		  Result_of_BBox=true;	  // Checking if point is on the infinite line	  Result_of_Online = PointOnLine(a_node, Distance, Marge);	  // point in boundingbox of the line and is on the line then the point is IN_AREA	  if ((Result_of_BBox) && (Result_of_Online == ON_AREA))			return IN_AREA;	  else			return Result_of_Online;}//// test if a point lies on the line. If the point isn't on the line// the function returns a value that indicates on which side of the// line the point is (in linedirection from first point to second point//// returns LEFT_SIDE, when point lies on the left side of the line//         ON_AREA, when point lies on the infinite line within a range//         RIGHT_SIDE, when point lies on the right side of the line// 		  LEFT_SIDE , RIGHT_SIDE , ON_AREAPointStatus KBoolLine::PointOnLine(Node *a_node, double& Distance, double Marge){   Distance=0;	// a_node must exist	assert(a_node);	// link must exist to get beginnode and endnode	assert(m_link);	// get the nodes from the line via the link	Node *bp, *ep;	bp = m_link->GetBeginNode();	ep = m_link->GetEndNode();	// both node must exist	assert(bp && ep);	// node may not be queal	assert(bp!=ep);   //quick test if point is begin or endpoint   if (a_node == bp || a_node == ep)      return ON_AREA;	CalculateLineParameters();	// calculate the distance of a_node in relation to the line	Distance = (m_AA * a_node->GetX())+(m_BB * a_node->GetY()) + m_CC;	if (Distance < -Marge)		return LEFT_SIDE;	else	{		if (Distance > Marge)			return RIGHT_SIDE;		else		 return ON_AREA;	}}//// Sets lines parameters// usage: a_line.Set(a_pointer_to_a_link);//void KBoolLine::Set(KBoolLink *a_link){	// points must exist	assert(a_link);	// points may not be equal	// must be an if statement because if an assert is used there will	// be a macro expansion error//	if (a_link->GetBeginNode()->Equal(a_link->GetEndNode(),MARGE)) assert(!a_link);	linecrosslist = NULL;	m_link = a_link;	m_valid_parameters = false;}KBoolLink* KBoolLine::GetLink(){   return m_link;}//// makes a line same as these// usage : line1 = line2;//KBoolLine& KBoolLine::operator=(const KBoolLine& a_line){	m_AA = a_line.m_AA;	m_BB = a_line.m_BB;	m_CC = a_line.m_CC;	m_link = a_line.m_link;  	linecrosslist = NULL;	m_valid_parameters = a_line.m_valid_parameters;	return *this;}Node* KBoolLine::OffsetContour(KBoolLine* const nextline,Node* _last_ins, double factor,Graph *shape){	KBoolLink* offs_currentlink;	KBoolLine  offs_currentline(m_GC);	KBoolLink* offs_nextlink;	KBoolLine  offs_nextline(m_GC);	Node* offs_end;	Node* offs_bgn_next;	Node* offs_end_next;	// make a node from this point	offs_end = new Node(GetEndNode(), m_GC);	Virtual_Point(offs_end,factor);	offs_currentlink=new KBoolLink(0, _last_ins,offs_end, m_GC);	offs_currentline.Set(offs_currentlink);	offs_bgn_next = new Node(nextline->m_link->GetBeginNode(), m_GC);	nextline->Virtual_Point(offs_bgn_next,factor);	offs_end_next = new Node(nextline->m_link->GetEndNode(), m_GC);	nextline->Virtual_Point(offs_end_next,factor);	offs_nextlink=new KBoolLink(0, offs_bgn_next, offs_end_next, m_GC);	offs_nextline.Set(offs_nextlink);	offs_currentline.CalculateLineParameters();	offs_nextline.CalculateLineParameters();	offs_currentline.Intersect2(offs_end,&offs_nextline);	// make a link between the current and the previous and add this to graph	shape->AddLink(offs_currentlink);	delete offs_nextlink;	return(offs_end);}Node* KBoolLine::OffsetContour_rounded(KBoolLine* const nextline,Node* _last_ins, double factor,Graph *shape){	KBoolLink* offs_currentlink;	KBoolLine  offs_currentline(m_GC);	KBoolLink* offs_nextlink;	KBoolLine  offs_nextline(m_GC);	Node* offs_end;	Node* medial_axes_point= new Node(m_GC);	Node* bu_last_ins = new Node(_last_ins, m_GC);	Node* offs_bgn_next;	Node* offs_end_next;	// make a node from this point	offs_end = new Node(GetEndNode(), m_GC);	*_last_ins = *GetBeginNode();	Virtual_Point(_last_ins,factor);	Virtual_Point(offs_end,factor);	offs_currentlink=new KBoolLink(0, _last_ins,offs_end, m_GC);	offs_currentline.Set(offs_currentlink);	offs_bgn_next = new Node(nextline->m_link->GetBeginNode(), m_GC);	nextline->Virtual_Point(offs_bgn_next,factor);	offs_end_next = new Node(nextline->m_link->GetEndNode(), m_GC);	nextline->Virtual_Point(offs_end_next,factor);	offs_nextlink=new KBoolLink(0, offs_bgn_next, offs_end_next, m_GC);	offs_nextline.Set(offs_nextlink);	offs_currentline.CalculateLineParameters();	offs_nextline.CalculateLineParameters();	offs_currentline.Intersect2(medial_axes_point,&offs_nextline);	double result_offs=sqrt( pow((double)GetEndNode()->GetY()-medial_axes_point->GetY(),2) +							 pow((double)GetEndNode()->GetX()-medial_axes_point->GetX(),2) );	if ( result_offs < fabs(m_GC->GetRoundfactor()*factor))	{		*_last_ins=*bu_last_ins;		*offs_end=*medial_axes_point;		delete medial_axes_point;		delete bu_last_ins;		// make a link between the current and the previous and add this to graph		delete offs_nextlink;		shape->AddLink(offs_currentlink);		return(offs_end);	}	else	{ //let us create a circle		*_last_ins=*bu_last_ins;		delete medial_axes_point;		delete bu_last_ins;		Node* endarc= new Node(offs_bgn_next, m_GC);		shape->AddLink(offs_currentlink);		delete offs_nextlink;		shape->CreateArc(GetEndNode(), &offs_currentline, endarc,fabs(factor),m_GC->GetInternalCorrectionAber());		return(endarc);	}}bool KBoolLine::OkeForContour(KBoolLine* const nextline,double factor,Node* LastLeft,Node* LastRight, LinkStatus& _outproduct){	assert(m_link);	assert(m_valid_parameters);	assert(nextline->m_link);	assert(nextline->m_valid_parameters);	factor = fabs(factor);//	PointStatus status=ON_AREA;	double distance=0;	Node offs_end_next(nextline->m_link->GetEndNode(), m_GC);	_outproduct= m_link->OutProduct(nextline->m_link,m_GC->GetAccur());	switch (_outproduct)	{		// current line lies on  leftside of prev line		case IS_RIGHT :		{			nextline->Virtual_Point(&offs_end_next,-factor);			// status=			nextline->PointOnLine(LastRight, distance, m_GC->GetAccur());			if (distance > factor)			{  PointOnLine(&offs_end_next, distance, m_GC->GetAccur());				if (distance > factor)					 return(true);			}		}		break;		// current line lies on  rightside of prev line		case IS_LEFT :		{			nextline->Virtual_Point(&offs_end_next,factor);			// status=			nextline->PointOnLine(LastLeft, distance, m_GC->GetAccur());			if (distance < -factor)			{  PointOnLine(&offs_end_next, distance, m_GC->GetAccur());				if (distance <-factor)					 return(true);			}		}		break;		// current line  lies on prev line		case IS_ON	 :		{			return(true);		}	}//end switch	return(false);}bool KBoolLine::Create_Ring_Shape(KBoolLine* nextline,Node** _last_ins_left,Node** _last_ins_right,double factor,Graph *shape){	Node* _current;	LinkStatus _outproduct=IS_ON;	if (OkeForContour(nextline,factor,*_last_ins_left,*_last_ins_right,_outproduct))	{		switch (_outproduct)		{			// Line 2 lies on  leftside of this line			case IS_RIGHT :			{				*_last_ins_left  =OffsetContour_rounded(nextline,*_last_ins_left,factor,shape);				*_last_ins_right =OffsetContour(nextline,*_last_ins_right,-factor,shape);			}			break;			case IS_LEFT :			{				*_last_ins_left  =OffsetContour(nextline,*_last_ins_left,factor,shape);				*_last_ins_right =OffsetContour_rounded(nextline,*_last_ins_right,-factor,shape);			}			break;			// Line 2 lies on this line			case IS_ON	 :			{				// make a node from this point				_current = new Node(m_link->GetEndNode(), m_GC);				Virtual_Point(_current,factor);				// make a link between the current and the previous and add this to graph				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;			}			break;		}//end switch		return(true);	}/*	else	{		switch (_outproduct)		{			// Line 2 lies on  leftside of this line			case IS_RIGHT :			{				*_last_ins_left  =OffsetContour_rounded(nextline,*_last_ins_left,factor,Ishape);				*_last_ins_right =OffsetContour(nextline,*_last_ins_right,-factor,Ishape);			}			break;			case IS_LEFT :			{				*_last_ins_left  =OffsetContour(nextline,*_last_ins_left,factor,Ishape);				*_last_ins_right =OffsetContour_rounded(nextline,*_last_ins_right,-factor,Ishape);			}			break;			// Line 2 lies on this line			case IS_ON	 :			{				// make a node from this point				_current = new Node(m_link->GetEndNode());				Virtual_Point(_current,factor);				// make a link between the current and the previous and add this to graph				Ishape->AddLink(*_last_ins_left, _current);				*_last_ins_left=_current;				_current = new Node(m_link->GetEndNode());				Virtual_Point(_current,-factor);				Ishape->AddLink(*_last_ins_right, _current);				*_last_ins_right=_current;			}			break;		}//end switch		return(true);	}*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -