int main() {
	int N;
	struct Point pt;
	while (scanf("%d", &N) == 1) {
		init(&A, 2), init(&B, 2);
		for (int i = 0; i < N; i++) {
			read(&pt, i);
			if (i)	printf("%d\n", s_closest(&B, pt));
			s_insert(&A, pt);
			read(&pt, i);
			printf("%d\n", s_closest(&A, pt));
			s_insert(&B, pt);
		}
	}
	return 0;
}
예제 #2
0
void SE_BipedController::interpolation(std::vector<SE_BipedKeyFrame*>::iterator &source,std::vector<SE_BipedKeyFrame*>::iterator &target,
                                       std::vector<SE_BipedKeyFrame*> &targetVector)
{
    SE_BipedKeyFrame* node_s = *source;
    SE_BipedKeyFrame* node_t = *target;

    //new frame counts,than push_back(node_s).For example:node_s = 3,node_t=0,
    //needGenerate 2 frames,then,push_back(node_s),now fullframe vector is 0,  1,2,  3
    int needGenerate = node_s->frameIndex - node_t->frameIndex - 1;

    for(int i = 0; i < needGenerate; ++i)
    {
        SE_Quat q_s = node_s->rotateQ;
        SE_Vector3f t_s = node_s->translate;

        SE_Quat q_t = node_t->rotateQ;
        SE_Vector3f t_t = node_t->translate;

        float t = (i+1.0) / (needGenerate+1.0);

        SE_Quat q_insert = SE_Quat::slerp(q_t,q_s,t);

        float x = SE_Lerp(t_t.x,t_s.x,t);
        float y = SE_Lerp(t_t.y,t_s.y,t);
        float z = SE_Lerp(t_t.z,t_s.z,t);

        SE_Vector3f t_insert(x,y,z);
        SE_Vector3f s_insert(1,1,1);//scale,not use

        SE_BipedKeyFrame* insertFrame = new SE_BipedKeyFrame();
        insertFrame->rotateQ = q_insert;
        insertFrame->translate = t_insert;
        insertFrame->scale = s_insert;
        insertFrame->frameIndex = node_t->frameIndex + i + 1;

        targetVector.push_back(insertFrame);
        target = targetVector.end();
        --target;
        
    }

    //push source node to target
    SE_BipedKeyFrame* insertSourceFrame = new SE_BipedKeyFrame();
    insertSourceFrame->rotateQ = node_s->rotateQ;
    insertSourceFrame->translate = node_s->translate;
    insertSourceFrame->scale = node_s->scale;
    insertSourceFrame->frameIndex = node_s->frameIndex;
    targetVector.push_back(insertSourceFrame);
    target = targetVector.end();
    --target;

    //don't increase source,next test will automatic increase

}
예제 #3
0
bool ParserInsertQuery::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
	Pos begin = pos;

	ParserWhiteSpaceOrComments ws;
	ParserString s_insert("INSERT", true, true);
	ParserString s_into("INTO", true, true);
	ParserString s_dot(".");
	ParserString s_id("ID");
	ParserString s_eq("=");
	ParserStringLiteral id_p;
	ParserString s_values("VALUES", true, true);
	ParserString s_format("FORMAT", true, true);
	ParserString s_select("SELECT", true, true);
	ParserString s_lparen("(");
	ParserString s_rparen(")");
	ParserIdentifier name_p;
	ParserList columns_p(std::make_unique<ParserCompoundIdentifier>(), std::make_unique<ParserString>(","), false);

	ASTPtr database;
	ASTPtr table;
	ASTPtr columns;
	ASTPtr format;
	ASTPtr select;
	ASTPtr id;
	/// Данные для вставки
	const char * data = nullptr;

	ws.ignore(pos, end);

	/// INSERT INTO
	if (!s_insert.ignore(pos, end, max_parsed_pos, expected)
		|| !ws.ignore(pos, end)
		|| !s_into.ignore(pos, end, max_parsed_pos, expected))
		return false;

	ws.ignore(pos, end);

	if (!name_p.parse(pos, end, table, max_parsed_pos, expected))
		return false;

	ws.ignore(pos, end);

	if (s_dot.ignore(pos, end, max_parsed_pos, expected))
	{
		database = table;
		if (!name_p.parse(pos, end, table, max_parsed_pos, expected))
			return false;

		ws.ignore(pos, end);
	}

	ws.ignore(pos, end);

	if (s_id.ignore(pos, end, max_parsed_pos, expected))
	{
		if (!s_eq.ignore(pos, end, max_parsed_pos, expected))
			return false;

		ws.ignore(pos, end);

		if (!id_p.parse(pos, end, id, max_parsed_pos, expected))
			return false;
	}

	ws.ignore(pos, end);

	/// Есть ли список столбцов
	if (s_lparen.ignore(pos, end, max_parsed_pos, expected))
	{
		ws.ignore(pos, end);

		if (!columns_p.parse(pos, end, columns, max_parsed_pos, expected))
			return false;

		ws.ignore(pos, end);

		if (!s_rparen.ignore(pos, end, max_parsed_pos, expected))
			return false;
	}

	ws.ignore(pos, end);

	Pos before_select = pos;

	/// VALUES или FORMAT или SELECT
	if (s_values.ignore(pos, end, max_parsed_pos, expected))
	{
		ws.ignore(pos, end);
		data = pos;
		pos = end;
	}
	else if (s_format.ignore(pos, end, max_parsed_pos, expected))
	{
		ws.ignore(pos, end);

		if (!name_p.parse(pos, end, format, max_parsed_pos, expected))
			return false;

		/// Данные начинаются после первого перевода строки, если такой есть, или после всех пробельных символов, иначе.
		ParserWhiteSpaceOrComments ws_without_nl(false);

		ws_without_nl.ignore(pos, end);
		if (pos != end && *pos == ';')
			throw Exception("You have excessive ';' symbol before data for INSERT.\n"
				"Example:\n\n"
				"INSERT INTO t (x, y) FORMAT TabSeparated\n"
				"1\tHello\n"
				"2\tWorld\n"
				"\n"
				"Note that there is no ';' in first line.", ErrorCodes::SYNTAX_ERROR);

		if (pos != end && *pos == '\n')
			++pos;

		data = pos;
		pos = end;
	}
	else if (s_select.ignore(pos, end, max_parsed_pos, expected))
	{
		pos = before_select;
		ParserSelectQuery select_p;
		select_p.parse(pos, end, select, max_parsed_pos, expected);
	}
	else
	{
		expected = "VALUES or FORMAT or SELECT";
		return false;
	}

	auto query = std::make_shared<ASTInsertQuery>(StringRange(begin, data ? data : pos));
	node = query;

	if (database)
		query->database = typeid_cast<ASTIdentifier &>(*database).name;

	query->table = typeid_cast<ASTIdentifier &>(*table).name;

	if (id)
		query->insert_id = safeGet<const String &>(typeid_cast<ASTLiteral &>(*id).value);

	if (format)
		query->format = typeid_cast<ASTIdentifier &>(*format).name;

	query->columns = columns;
	query->select = select;
	query->data = data != end ? data : NULL;
	query->end = end;

	if (columns)
		query->children.push_back(columns);
	if (select)
		query->children.push_back(select);

	return true;
}