Esempio n. 1
0
//---------------------------------------------------------
bool CSG_PRQuadTree::Create(CSG_Shapes *pShapes, int Attribute, bool bStatistics)
{
	Destroy();

	if( pShapes && pShapes->is_Valid() && Create(pShapes->Get_Extent(), bStatistics) )
	{
		for(int iShape=0; iShape<pShapes->Get_Count() && SG_UI_Process_Set_Progress(iShape, pShapes->Get_Count()); iShape++)
		{
			CSG_Shape	*pShape	= pShapes->Get_Shape(iShape);

			if( Attribute < 0 || !pShape->is_NoData(Attribute) )
			{
				double	z	= Attribute < 0 ? iShape : pShape->asDouble(Attribute);

				for(int iPart=0; iPart<pShape->Get_Part_Count(); iPart++)
				{
					for(int iPoint=0; iPoint<pShape->Get_Point_Count(iPart); iPoint++)
					{
						Add_Point(pShape->Get_Point(iPoint, iPart), z);
					}
				}
			}
		}

		return( Get_Point_Count() > 0 );
	}

	return( false );
}
Esempio n. 2
0
//---------------------------------------------------------
TSG_Point CSG_Shape_Points::Get_Centroid(void)
{
	int			n	= 0;
	CSG_Point	c(0.0, 0.0);

	for(int iPart=0; iPart<Get_Part_Count(); iPart++)
	{
		for(int iPoint=0; iPoint<Get_Point_Count(iPart); iPoint++)
		{
			c	+= Get_Point(iPoint, iPart);
			n	++;
		}
	}

	if( n > 0 )
	{
		c.Assign(c.Get_X() / n, c.Get_Y() / n);
	}

	return( c );
}
//---------------------------------------------------------
TSG_Intersection CSG_Shape_Line::On_Intersects(CSG_Shape *pShape)
{
	//-----------------------------------------------------
	if( pShape->Get_Type() == SHAPE_TYPE_Point || pShape->Get_Type() == SHAPE_TYPE_Points )
	{
		bool	bIn		= false;
		bool	bOut	= false;

		for(int iPart=0; iPart<m_nParts; iPart++)
		{
			for(int jPart=0; jPart<pShape->Get_Part_Count(); jPart++)
			{
				for(int jPoint=1; jPoint<pShape->Get_Point_Count(jPart); jPoint++)
				{
					TSG_Point	Point;

					if( Get_Distance(pShape->Get_Point(jPoint, jPart), Point, iPart) == 0.0 )
					{
						bIn		= true;
					}
					else
					{
						bOut	= true;
					}

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

		if( bIn )
		{
			return( INTERSECTION_Contained );
		}
	}

	//-----------------------------------------------------
	else if( pShape->Get_Type() == SHAPE_TYPE_Line )
	{
		TSG_Point	iA, iB, jA, jB, Crossing;

		for(int iPart=0; iPart<m_nParts; iPart++)
		{
			if( Get_Point_Count(iPart) > 1 )
			{
				iA	= Get_Point(0, iPart);

				for(int iPoint=1; iPoint<Get_Point_Count(iPart); iPoint++)
				{
					iB	= iA;
					iA	= Get_Point(iPoint, iPart);

					for(int jPart=0; jPart<pShape->Get_Part_Count(); jPart++)
					{
						if( pShape->Get_Point_Count(jPart) > 1 )
						{
							jA	= pShape->Get_Point(0, jPart);

							for(int jPoint=1; jPoint<pShape->Get_Point_Count(jPart); jPoint++)
							{
								jB	= jA;
								jA	= pShape->Get_Point(jPoint, jPart);

								if( SG_Get_Crossing(Crossing, iA, iB, jA, jB) )
								{
									return( INTERSECTION_Overlaps );
								}
							}
						}
					}
				}
			}
		}
	}

	return( INTERSECTION_None );
}