示例#1
0
void CropFrame::paintEvent(QPaintEvent*)
{
    QPixmap bmp(this->width(), this->height());
    QPainter p;
    p.begin(&bmp);

    p.eraseRect(0, 0, this->width(), this->height());

    // draw the background pixmap
    p.drawPixmap(m_pixmapX, m_pixmapY, *m_pixmap);

    if (m_drawRec)
    {
        // draw the rectangle
        p.setPen(QPen(m_color, 2));
        p.drawRect(m_cropRegion);
        // draw the crosshairs
        int midX = m_cropRegion.left() + m_cropRegion.width() / 2;
        int midY = m_cropRegion.top()  + m_cropRegion.height() / 2;
        p.drawLine(midX - 10, midY, midX + 10, midY);
        p.drawLine(midX, midY - 10, midX, midY + 10);
    }
    p.end();

    QPainter newp(this);
    newp.drawPixmap(0, 0, bmp);
}
示例#2
0
/// 衝突点を入れ替える
/// @return 破棄する衝突点のインデックスを返す。
int Contact::Sort4ContactPoints(const Vector3 &newPoint, float newDistance){
	int maxPenetrationIndex = -1;
	float maxPenetration = newDistance;

	for (unsigned i = 0; i < m_numContacts; i++){
		if (m_contactPoints[i].distance < maxPenetration){
			maxPenetrationIndex = i;
			maxPenetration = m_contactPoints[i].distance;
		}
	}

	float res[4] = { 0.0f };

	//各点を除いた時の衝突点が作る面積のうち、もっとも大きいものを選択
	//p124(Tree)

	Vector3 newp(newPoint);
	Vector3 p[4] = {
		m_contactPoints[0].pointA,
		m_contactPoints[1].pointA,
		m_contactPoints[2].pointA,
		m_contactPoints[3].pointA,
	};

	if (maxPenetrationIndex != 0){
		res[0] = CalcArea4Points(newp, p[1], p[2], p[3]);
	}

	if (maxPenetrationIndex != 1) {
		res[1] = CalcArea4Points(newp, p[0], p[2], p[3]);
	}

	if (maxPenetrationIndex != 2) {
		res[2] = CalcArea4Points(newp, p[0], p[1], p[3]);
	}

	if (maxPenetrationIndex != 3) {
		res[3] = CalcArea4Points(newp, p[0], p[1], p[2]);
	}

	int maxIndex = 0;
	float maxValue = res[0];

	if (res[1] > maxValue){
		maxIndex = 1;
		maxValue = res[1];
	}

	if (res[2] > maxValue){
		maxIndex = 2;
		maxValue = res[2];
	}

	if (res[3] > maxValue){
		maxIndex = 3;
		maxValue = res[3];
	}

	return maxIndex;
}
示例#3
0
inline tps *build(int l, int r)
{
    tps *a = newp(null);
    if (l < r) {
	int mid = (l + r) >> 1;
	a->l = build(l, mid);
	a->r = build(mid + 1, r);
    }
示例#4
0
void TPZCartsys::RotateToReference (TPZVec<REAL> &point)
{
	TPZVec<REAL> newp(3,0.);
	newp[0] = fTr(0,0)*point[0] + fTr(1,0)*point[1] + fTr(2,0)*point[2];
	newp[1] = fTr(0,1)*point[0] + fTr(1,1)*point[1] + fTr(2,1)*point[2];
	newp[2] = fTr(0,2)*point[0] + fTr(1,2)*point[1] + fTr(2,2)*point[2];
	point[0] = newp[0];
	point[1] = newp[1];
	point[2] = newp[2];
}
示例#5
0
void add(tps *&a, int l, int r, int x)
{
    a = newp(a);
    ++a->s;
    if (l == r) return;
    else {
	int mid = (l + r) >> 1;
	if (x <= mid) add(a->l, l, mid, x);
	else add(a->r, mid + 1, r, x);
    }	
}
示例#6
0
tps *build(int l, int r)
{
    tps *A = newp(null);
    if (l == r) return A;
    else {
	int mid = (l + r) >> 1;
	if (l <= mid) A->l = build(l, mid);
	if (r > mid) A->r = build(mid + 1, r);
    }
    return A;
}
示例#7
0
文件: Box.cpp 项目: RuiVilares/TheBox
void Box::updateProgramDuration(string &programn)
{
	system("CLS");
	cout << "     _       _                               _ " << endl;
	cout << "    / \\   __| |_   ____ _ _ __   ___ ___  __| |" << endl;
	cout << "   / _ \\ / _` \\ \\ / / _` | '_ \\ / __/ _ \\/ _` |" << endl;
	cout << "  / ___ \\ (_| |\\ V / (_| | | | | (_|  __/ (_| |" << endl;
	cout << " /_/   \\_\\__,_| \\_/ \\__,_|_| |_|\\___\\___|\\__,_|" << endl << endl;
	cout << "\t \t Update a program" << endl << endl << endl;
	int channel_position = 0;
	int program_position = 0;
	int newdur;
	cout << "Insert a new duration to this program: ";
	cin >> newdur;
	for (channel_position; channel_position < channels.size(); channel_position++)
	{
		program_position = searchProgram(programn, channels[channel_position]);
		if (program_position != -1)
			break;
	}

	Channel * channel_pointer;
	channel_pointer = &channels[channel_position];
	Program oldp(channels[channel_position].getPrograms()[program_position]);
	Program newp(channels[channel_position].getPrograms()[program_position]);
	newp.setDuration(newdur);
	channels[channel_position].removeProgram(program_position);
	if (!checkProgramDate(oldp.getDate(), newdur, *channel_pointer))
	{
		channels[channel_position].addProgram(oldp);
		cout << endl << "Error. The exhibition time matches the exhibition time of an \n";
		cout << "already existing program.\n \nPlease enter different values\n";
		Sleep(3000);
	}
	else
	{
		channels[channel_position].addProgram(newp);
		cout << endl << endl << "The duration of the program \"" << newp.getName() << "\"";
		cout << " was change to \"" << newdur << "\"";
		Sleep(3000);
	}
	
}
示例#8
0
文件: Box.cpp 项目: RuiVilares/TheBox
void Box::updateProgramDate(string &programn)
{
	system("CLS");
	cout << "     _       _                               _ " << endl;
	cout << "    / \\   __| |_   ____ _ _ __   ___ ___  __| |" << endl;
	cout << "   / _ \\ / _` \\ \\ / / _` | '_ \\ / __/ _ \\/ _` |" << endl;
	cout << "  / ___ \\ (_| |\\ V / (_| | | | | (_|  __/ (_| |" << endl;
	cout << " /_/   \\_\\__,_| \\_/ \\__,_|_| |_|\\___\\___|\\__,_|" << endl << endl;
	cout << "\t \t Update a program" << endl << endl << endl;
	int channel_position = 0;
	int program_position = 0;
	int hour, min;
	string day;
	Date new_program_date = Date();
	//INSERIR HORA INÍCIO

	cout << "New starting hour: "; cin >> hour;
	while (cin.fail() || hour > 23 || hour < 0)
	{
		cin.clear();
		cin.ignore(10000, '\n');
		cout << "Wrong format. Please insert a number between 0 and 23.";
		cout << "\nNew starting hour : ";
		cin >> hour;
	}


	// INSERIR MINUTOS
	cout << "New starting minutes: "; cin >> min;
	while (cin.fail() || min > 59 || min < 0)
	{
		cin.clear();
		cin.ignore(10000, '\n');
		cout << "Wrong format. Please insert a number between 0 and 59.";
		cout << "\nNew starting minutes: ";
		cin >> min;
	}


	// INSERIR DIA DA SEMANA
	int option;
	cout << "\n1.Sunday\n2.Monday\n3.Tuesday\n4.Wednesday\n5.Thursday\n6.Friday\n7.Saturday\n";
	cout << "Choose a day of the week: ";
	cin >> option;

	while (cin.fail() || option < 1 || option > 7)
	{
		cin.clear();
		cin.ignore(10000, '\n');
		cout << "Option mismatch. Please choose a number between 1 and 7: ";
		cin >> option;
	}

	day = new_program_date.getStr(option);
	
	for (channel_position; channel_position < channels.size(); channel_position++)
	{
		program_position = searchProgram(programn, channels[channel_position]);
		if (program_position != -1)
			break;
	}
	Channel * channel_pointer;
	channel_pointer = &channels[channel_position];
	Program oldp(channels[channel_position].getPrograms()[program_position]);
	Program newp(channels[channel_position].getPrograms()[program_position]);
	newp.setDate(day, hour, min);
	channels[channel_position].removeProgram(program_position);
	if (!checkProgramDate(newp.getDate(), oldp.getDuration(), *channel_pointer))
	{
		channels[channel_position].addProgram(oldp);
		cout << endl << "Error. The exhibition time matches the exhibition time of an \n";
		cout << "already existing program.\n \nPlease enter different values\n";
		Sleep(3000);
	}
	else
	{
		channels[channel_position].addProgram(newp);
		cout << endl << endl << "The date of the program \"" << newp.getName() << "\"";
		cout << " was change to \"";
		newp.getDate().showDate();
		cout << "\"";
		Sleep(3000);
	}

}
示例#9
0
void GameHandler::cutline(float from, float to)
{
	float x0 = 0;
	float y0 = from;
	float x1 = gameopt.columns;
	float y1 = to;

	struct DeletePiece
	{
		std::list<polygon<float>> remainders;
		GamePiece * pgp;
		int originaltype;
		float x,y,rot;
#ifdef DEBUGAREALOSS
		std::list<polygon<float>> midremainders;
#endif
	};
	std::list<DeletePiece> deletelist;

	physichandler.getpieces_in_rect(x0, y0, x1, y1, [y0, y1, &deletelist](PhysicPiece * php){
		polygon<float> p (static_cast<GamePiece *>(php->getUserData())->p.getshape());
		struct DeletePiece dp;

		// Transform the piece coordinates from local to global
		for (auto & vertex: p)
		{
			vertex.rotate(php->getRot());
			vertex.translate(php->getX(), php->getY());
		}

#ifndef DEBUGAREALOSS
		struct
		{
			void push_back(const polygon<float> & p)
			{
				(void) p;
			}
		} midcontainer;
#else
		auto & midcontainer = dp.midremainders;
#endif

		// Here cutter uses the tolerance
		bool isinbetween = cutter(p, dp.remainders, dp.remainders, midcontainer, y0, y1, 0.1F);

		if (isinbetween)
		{
			dp.pgp = static_cast<GamePiece *>(php->getUserData());
			dp.originaltype = dp.pgp->p.getType();
			dp.x = php->getX();
			dp.y = php->getY();
			dp.rot = php->getRot();
			deletelist.push_back(std::move(dp));
		}
	});

	for (auto & dp: deletelist)
	{
		GamePiece * pgp = dp.pgp;
#ifdef DEBUGAREALOSS
		float prevarea = pgp->p.getshape().area(),
			newarea = 0;
#endif

		// Create remainders
		for (auto & pol: dp.remainders)
		{
			// Transform the piece coordinates from global to local again
			for (auto & vertex: pol)
			{
				vertex.translate(-dp.x, -dp.y);
				vertex.rotate(-dp.rot);
			}
			if (isugly(pol))
				continue;
			piece<float> newp (pol, dp.originaltype);
			if (!newp.empty())
				newpiece(newp, dp.x, dp.y, dp.rot, PhysicPiece::OLD_PIECE);
#ifdef DEBUGAREALOSS
			newarea += pol.area();
#endif
		}
#ifdef DEBUGAREALOSS
		for (auto & pol: dp.midremainders)
		{
			newarea += pol.area();
		}
		if (fabs(prevarea - newarea) > 1.0)
			raise(SIGTRAP);
#endif
		deletepiece(pgp);
	}
}