Ejemplo n.º 1
0
Edge* Subdivision::Locate(const Point2d& x)
// Returns an edge e, s.t. either x is on e, or e is an edge of
// a triangle containing x. The search starts from startingEdge
// and proceeds in the general direction of x. Based on the
// pseudocode in Guibas and Stolfi (1985) p.121.
{
	Edge* e = startingEdge;

	while (TRUE) {
		if (x == e->Org2d() || x == e->Dest2d())
		    return e;
		else if (RightOf(x, e))
			 e = e->Sym();
		else if (!RightOf(x, e->Onext()))
			 e = e->Onext();
		else if (!RightOf(x, e->Dprev()))
			 e = e->Dprev();
		else
		    return e;
	}
}
Ejemplo n.º 2
0
////--------------------------
/// FFConfigParser::RightOfSet
//------------------------------
//
//
//	Parameters:
//
//	Returns:
//
const char* FFConfigParser::RightOfSet( const char *effectname )
{
	const char *s = effectname;

	// Check through all set names and test effectname against it
	for
	(	TMap::iterator itMap = mMap.begin()
	;	itMap != mMap.end() && s == effectname
	;	itMap++
	){
		s = RightOf( effectname, (*itMap).first.c_str() );
	}

	return s ? s : effectname;
}
Ejemplo n.º 3
0
void Subdivision::InsertSite(const Point2d& x)
// Inserts a new point into a subdivision representing a Delaunay
// triangulation, and fixes the affected edges so that the result
// is still a Delaunay triangulation. This is based on the
// pseudocode from Guibas and Stolfi (1985) p.120, with slight
// modifications and a bug fix.
{
	Edge* e = Locate(x);
	if ((x == e->Org2d()) || (x == e->Dest2d()))  // point is already in
	    return;
	else if (OnEdge(x, e)) {
		e = e->Oprev();
		DeleteEdge(e->Onext());
	}

	// Connect the new point to the vertices of the containing
	// triangle (or quadrilateral, if the new point fell on an
	// existing edge.)
	Edge* base = MakeEdge();
	base->EndPoints(e->Org(), new Point2d(x));
	Splice(base, e);
	startingEdge = base;
	do {
		base = Connect(e, base->Sym());
		e = base->Oprev();
	} while (e->Lnext() != startingEdge);

	// Examine suspect edges to ensure that the Delaunay condition
	// is satisfied.
	do {
		Edge* t = e->Oprev();
		if (RightOf(t->Dest2d(), e) &&
			InCircle(e->Org2d(), t->Dest2d(), e->Dest2d(), x)) {
				Swap(e);
				e = e->Oprev();
		}
		else if (e->Onext() == startingEdge)  // no more suspect edges
			return;
		else  // pop a suspect edge
		    e = e->Onext()->Lprev();
	} while (TRUE);
}
Ejemplo n.º 4
0
Direction _323500942_C::HandleFollowWall()
{
	if (AboutToFinishOrLittleBattery(m_oPos)
		|| m_nUnexploredOrDustyCellsCount == 0)	// finished cleaning
	{
		m_bIsCurrentPathInit = false;

		m_oCurrentState = AlgoState::AdvanceToD;
		return HandleAdvanceToD();
	}

	/*if(!m_bFirstStep)
	{
		m_oWallBeingFollowed = NeighbourTo(m_oWallBeingFollowed, m_oPrevStep);
	}
	else
	{
		m_bFirstStep = false;
	}*/

	if(m_oMatrix[m_oPos] >= '1' && m_oMatrix[m_oPos] <= '9')
	{
		return Direction::Stay;
	}

	if (!m_bIsCurrentPathInit)
	{

		m_oWallDirection = direction(m_oPos, m_oWallBeingFollowed);
		Direction oRightOf = RightOf(m_oWallDirection);
		Direction oLeftOf = LeftOf(m_oWallDirection);

		if(m_oMatrix[m_oWallBeingFollowed] != 'W')
		{

			m_oWallBeingFollowed = NeighbourTo(m_oWallBeingFollowed, oLeftOf);
			return m_oWallDirection;
		}

		if(m_oMatrix[NeighbourTo(m_oPos, oRightOf)] != 'W')
		{
			Point oTemp = m_oPos;
			m_nSteps2 = 0;

			do
			{
				oTemp = NeighbourTo(oTemp, reverseDir(m_oWallDirection));
				m_nSteps2++;
			}
			while(m_oMatrix.exists(oTemp) && m_oMatrix[oTemp] == '~');
			m_nSteps2--;

			if(m_nSteps2 > 0 && m_oMatrix.exists(oTemp) && m_oMatrix[oTemp] != '~'
					&& m_oMatrix.exists(NeighbourTo(oTemp, oRightOf)) && m_oMatrix[NeighbourTo(oTemp, oRightOf)] != '~')
			{
				m_bIsCurrentPathInit = true;

				m_oCurrentPath.ClearPath();
				for(int i = 0; i < m_nSteps2; i++)
				{
					m_oCurrentPath.addStep(reverseDir(m_oWallDirection));
				}

				m_bFirstPart = true;

			}
			else
			{
				m_oWallBeingFollowed = NeighbourTo(m_oWallBeingFollowed, oRightOf);
				return oRightOf;
			}

		}
		else
		{
			if(m_oMatrix[NeighbourTo(m_oPos, reverseDir(m_oWallDirection))] != 'W')
			{
				m_oWallBeingFollowed = NeighbourTo(m_oPos, oRightOf);
				m_oWallBeingFollowed = NeighbourTo(m_oWallBeingFollowed, reverseDir(m_oWallDirection));

				return reverseDir(m_oWallDirection);
			}
			else
			{
				m_oWallBeingFollowed = NeighbourTo(m_oPos, reverseDir(m_oWallDirection));
				m_oWallBeingFollowed = NeighbourTo(m_oWallBeingFollowed, oLeftOf);

				return LeftOf(m_oWallDirection);
			}
		}
		//}

		/*BFS::BFSResult result;
		BFS::run(result, m_oMatrix, m_oPos, { '~', '1' , '2', '3', '4', '5', '6', '7', '8', '9' }, m_oNonWallChars, { }, {'W'});

		if(!result.bfound)
		{
			m_bIsCurrentPathInit = false;

			m_oCurrentState = AlgoState::AdvanceToD;
			return HandleAdvanceToD();
		}

		BFS::getPath(m_oCurrentPath, result);

		m_bIsCurrentPathInit = true;*/

	}

	if (m_oCurrentPath.hasNext())
	{
		return m_oCurrentPath.nextStep();
	}
	else
	{
		if(m_bFirstPart)
		{
			Direction oRightOf = RightOf(m_oWallDirection);
			//Direction oLeftOf = LeftOf(m_oWallDirection);

			Point oTemp = m_oPos;
			bool isInSecondRow = false;

			for(int i = 0; i < m_nSteps2; i++)
			{
				Point NeighbourToRight = NeighbourTo(oTemp, RightOf(m_oWallDirection));
				if(!isInSecondRow && m_oMatrix[NeighbourToRight] == '~')
				{
					m_oCurrentPath.addStep(RightOf(m_oWallDirection));
					isInSecondRow = true;
				}

				if(isInSecondRow && m_oMatrix[NeighbourTo(NeighbourToRight, m_oWallDirection)] == 'W')
				{
					m_oCurrentPath.addStep(LeftOf(m_oWallDirection));
					isInSecondRow = false;
				}
				m_oCurrentPath.addStep(m_oWallDirection);

				oTemp = NeighbourTo(oTemp, m_oWallDirection);
			}

			if(!isInSecondRow)
			{
				m_oCurrentPath.addStep(RightOf(m_oWallDirection));
				isInSecondRow = true;
			}

			m_oWallBeingFollowed = NeighbourTo(m_oWallBeingFollowed, oRightOf);

			m_bFirstPart = false;
		}
		else
		{
			m_bIsCurrentPathInit = false;

			return HandleFollowWall();
		}

	}

	return Direction::Stay;
}