コード例 #1
0
ファイル: shape_points.cpp プロジェクト: johanvdw/saga-debian
//---------------------------------------------------------
TSG_Intersection CSG_Shape_Points::On_Intersects(CSG_Shape *pShape)
{
	CSG_Shape	*piPoints, *pjPoints;

	if( CSG_Shape::Get_Point_Count() < pShape->Get_Point_Count() )
	{
		piPoints	= this;
		pjPoints	= pShape;
	}
	else
	{
		piPoints	= pShape;
		pjPoints	= this;
	}

	bool	bIn		= false;
	bool	bOut	= false;

	for(int iPart=0; iPart<piPoints->Get_Part_Count(); iPart++)
	{
		for(int iPoint=0; iPoint<piPoints->Get_Point_Count(iPart); iPoint++)
		{
			CSG_Point	Point	= piPoints->Get_Point(iPoint, iPart);

			for(int jPart=0; jPart<pjPoints->Get_Part_Count(); jPart++)
			{
				for(int jPoint=0; jPoint<pjPoints->Get_Point_Count(jPart); jPoint++)
				{
					if( Point.is_Equal(pjPoints->Get_Point(jPoint, jPart)) )
					{
						bIn		= true;
					}
					else
					{
						bOut	= true;
					}

					if( bIn && bOut )
					{
						return( INTERSECTION_Overlaps );
					}
				}
			}
		}
	}

	if( bIn )
	{
		return( piPoints == this ? INTERSECTION_Contained : INTERSECTION_Contains );
	}

	return( INTERSECTION_None );
}
コード例 #2
0
//---------------------------------------------------------
bool CSG_Network::Remove_End_Nodes(void)
{
	int		iEdge, n;

	//-----------------------------------------------------
	for(iEdge=0; iEdge<m_Edges.Get_Count(); iEdge++)
	{
		CSG_Shape	*pEdge	= m_Edges.Get_Shape(iEdge);

		if( pEdge->asInt(3) == SHAPE_TYPE_Line )
		{
			bool	bRemove	= false;

			for(int iNode=1; iNode<=2 && !bRemove; iNode++)
			{
				CSG_Network_Node	&Node	= Get_Node(pEdge->asInt(iNode));
				CSG_Point			Point	= Node.Get_Point();
				CSG_Shape			*pNext;

				if(	(	(pNext = m_Edges.Get_Shape(Node.Get_Edge_Next(pEdge->asInt(0),  true))) != NULL
						&&	pNext->asInt(3) == SHAPE_TYPE_Polygon
						&&	!Point.is_Equal(pNext->Get_Point(0, 0, false)) )
				||	(	(pNext = m_Edges.Get_Shape(Node.Get_Edge_Next(pEdge->asInt(0), false))) != NULL
						&&	pNext->asInt(3) == SHAPE_TYPE_Polygon
						&&	!Point.is_Equal(pNext->Get_Point(0, 0,  true)) ) )
				{
					bRemove	= true;
				}
			}

			if( bRemove )
			{
				Get_Node(pEdge->asInt(1)).Del_Edge(pEdge->asInt(0));
				Get_Node(pEdge->asInt(2)).Del_Edge(pEdge->asInt(0));

				pEdge->Set_Value(4, 1);
			}
		}
	}

	//-----------------------------------------------------
	do
	{
		for(n=0, iEdge=0; iEdge<m_Edges.Get_Count(); iEdge++)
		{
			CSG_Shape	*pEdge	= m_Edges.Get_Shape(iEdge);

			if( pEdge->asInt(3) == SHAPE_TYPE_Line && pEdge->asInt(4) == 0 )
			{
				if(	Get_Node(pEdge->asInt(1)).Get_Edge_Count() <= 1
				||	Get_Node(pEdge->asInt(2)).Get_Edge_Count() <= 1 )
				{
					Get_Node(pEdge->asInt(1)).Del_Edge(pEdge->asInt(0));
					Get_Node(pEdge->asInt(2)).Del_Edge(pEdge->asInt(0));

					pEdge->Set_Value(4, 1);

					n++;
				}
			}
		}
	}
	while( n > 0 );

	//-----------------------------------------------------
	for(iEdge=m_Edges.Get_Count()-1; iEdge>=0; iEdge--)
	{
		if( m_Edges[iEdge][4] )
		{
			m_Edges.Del_Shape(iEdge);
		}
	}

	//-----------------------------------------------------
	return( Update() );
}
コード例 #3
0
//---------------------------------------------------------
bool CPolygon_Shared_Edges::Get_Shared_Edges(CSG_Shape_Part *pA, CSG_Shape_Part *pB, double Epsilon)
{
	int	Edge_1st	= m_pEdges->Get_Count();

	CSG_Shape	*pEdge	= NULL;

	for(int iPoint=0, jPoint; iPoint<pA->Get_Count(); iPoint++)
	{
		CSG_Point	Point	= pA->Get_Point(iPoint);

		if( !pEdge )
		{
			for(jPoint=0; jPoint<pB->Get_Count(); jPoint++)
			{
				if( Point.is_Equal(pB->Get_Point(jPoint), Epsilon) )
				{
					pEdge	= m_pEdges->Add_Shape();
					pEdge	->Add_Point(Point);

					if( m_Field < 0 )
					{
						pEdge->Set_Value(0, pA->Get_Owner()->Get_Index());
						pEdge->Set_Value(1, pB->Get_Owner()->Get_Index());
					}
					else
					{
						pEdge->Set_Value(0, pA->Get_Owner()->asString(m_Field));
						pEdge->Set_Value(1, pB->Get_Owner()->asString(m_Field));
					}
					break;
				}
			}
		}
		else
		{
			int	j	= jPoint;

			if( Point.is_Equal(pB->Get_Point(jPoint = Get_Next_Vertex(pB, j, false)), Epsilon)
			||  Point.is_Equal(pB->Get_Point(jPoint = Get_Next_Vertex(pB, j, true )), Epsilon) )
			{
				pEdge->Add_Point(Point);
			}
			else
			{
				pEdge	= NULL;
			}
		}
	}

	//-----------------------------------------------------
	if( pEdge )
	{
		CSG_Shape	*pEdge_1st	= m_pEdges->Get_Shape(Edge_1st);

		if( pEdge != pEdge_1st && SG_Is_Equal(pA->Get_Point(0), pEdge_1st->Get_Point(0)) )
		{
			for(int i=0; i<pEdge_1st->Get_Point_Count(0); i++)
			{
				pEdge->Add_Point(pEdge_1st->Get_Point(i));
			}

			m_pEdges->Del_Shape(Edge_1st);
		}
	}

	//-----------------------------------------------------
	for(int iEdge=m_pEdges->Get_Count()-1; iEdge>=Edge_1st; iEdge--)
	{
		if( m_pEdges->Get_Shape(iEdge)->Get_Point_Count() <= 1 )	// touches at point
		{
			m_pEdges->Del_Shape(iEdge);
		}
	}

	//-----------------------------------------------------
	return( true );
}