Example #1
0
void SelectNodesOP::RectQueryVisitor::
visit(Object* object, bool& bFetchNext)
{
	ChainShape* chain = static_cast<ChainShape*>(object);

	if (Math::isRectIntersectRect(chain->getRect(), m_rect))
	{
		ChainSelectedNodes* result = new ChainSelectedNodes;
		result->chain = chain;

		const std::vector<Vector>& vertices = chain->getVertices();
		for (size_t i = 0, n = vertices.size(); i < n; ++i)
		{
			if (Math::isPointInRect(vertices[i], m_rect))
				result->selectedNodes.push_back(vertices[i]);
		}

		if (result->selectedNodes.empty())
			delete result;
		else
			m_result.push_back(result);
	}

	bFetchNext = true;
}
Example #2
0
void SelectNodesOP::PosQueryVisitor::
visit(Object* object, bool& bFetchNext)
{
	ChainShape* chain = static_cast<ChainShape*>(object);

	if (Math::isRectIntersectRect(chain->getRect(), m_rect))
	{
		const std::vector<Vector>& vertices = chain->getVertices();
		for (size_t i = 0, n = vertices.size(); i < n; ++i)
		{
			if (Math::getDistance(m_pos, vertices[i]) < SelectNodesOP::getThreshold())
			{
				ChainSelectedNodes* result = new ChainSelectedNodes;
				result->chain = chain;
				result->selectedNodes.push_back(vertices[i]);
				*m_result = result;

				bFetchNext = false;
				return;
			}
		}
	}

	bFetchNext = true;
}