Пример #1
0
void t_libraryEditor::drawPin(QPoint pos)
{
    pos.setX(roundNumber(pos.x()/scale));
    pos.setY(roundNumber(pos.y()/scale));
//    symbol->addPin(pos);
    
    if(mode == MOVE)
        pinPlacement = false;
}
Пример #2
0
// http://www.w3.org/TR/SVG11/coords.html#Units
QString Tools::convertUnitsToPx(const QString &text, qreal baseValue)
{
    QString unit;
    qreal number = 0;
    const QChar *str = text.constData();
    const QChar *end = str + text.size();
    while (str != end) {
        number = getNum(str);
        while ((str->isLetter() || *str == QLatin1Char('%')) && str != end) {
            unit += *str;
            ++str;
        }
    }

    if (unit == QL1S("px"))
        return roundNumber(number, Tools::ATTRIBUTE);

    // fix string parsing, getNum func detect 'e' char as exponent...
    if (unit == QL1S("x"))
        unit = QL1S("ex");
    else if (unit == QL1S("m"))
        unit = QL1S("em");

    // note that all relative units depends on users screen dpi
    // and cleaner use 90dpi as default

    if (unit == QL1S("pt"))
        number = number * 1.25;
    else if (unit == QL1S("pc"))
        number = number * 15;
    else if (unit == QL1S("mm"))
        number = number * 3.543307;
    else if (unit == QL1S("cm"))
        number = number * 35.43307;
    else if (unit == QL1S("in"))
        number = number * 90;
    else if (unit == QL1S("%"))
        number = number * baseValue / 100;
    else if (unit == QL1S("em"))
        number = number * baseValue;
    else if (unit == QL1S("ex"))
        number = number * baseValue / 2;
    else
        return text;

    return roundNumber(number, Tools::ATTRIBUTE);
}
Пример #3
0
void t_libraryEditor::drawWire(QPoint pos)
{
    pos.setX(roundNumber(pos.x()/scale));
    pos.setY(roundNumber(pos.y()/scale));

    if(!incompleteStage)
    {
        incompleteLine.setP1(pos);
        incompleteStage = true;
    }
    else if(incompleteStage)
    {
        incompleteLine.setP2(pos);
//        symbol->addLine(incompleteLine);
        incompleteStage = false;
    }
}
Пример #4
0
void StudentWorld::setDisplayText()
{
	int score = getScore();
	int round = roundNumber();
	double energyPercent = (double(m_player->currentEnergy()/50)*100);
	int torpedoes = m_player->numberOfTorpedoes();
	int shipsLeft = getLives();
	std::string s = FormatGameStatText(score, round, energyPercent, torpedoes, shipsLeft);
	setGameStatText(s);
}
	static Int2 getRotatedPoint(int posX, int posY, float angleRadians, int posRotationCenterX, int posRotationCenterY, int xDeformation)
	{
		//definition de la position du point dans le nouveau repere dont le centre est le point de rotation
		float newPosX = (float)(posX - posRotationCenterX);
		float newPosY = (float)(posY - posRotationCenterY);

		//calcul de la position du point apres rotation (toujours dans ce nouveau repere)
		float angleNewPos = atan2f(newPosY, newPosX);
#ifdef WIN32
		float moduleNewPos = 1.f / MathUtils::fastInverseSqrt(newPosX*newPosX + newPosY*newPosY);
#else
		float moduleNewPos = sqrt(newPosX*newPosX+newPosY*newPosY);
#endif
		float finalAngle = angleNewPos + angleRadians;
		float rotatedNewPosX = cos(finalAngle) * moduleNewPos;
		float rotatedNewPosY = sin(finalAngle) * moduleNewPos;

		//retour des valeurs en remettant les coordonnees dans le repere normal
		return Int2(roundNumber(rotatedNewPosX) + posRotationCenterX + xDeformation, roundNumber(rotatedNewPosY) + posRotationCenterY);
	}
Пример #6
0
QString Tools::roundNumber(qreal value, RoundType type)
{
    int precision;
    if (type == COORDINATE)
        precision = Keys::get().coordinatesPrecision();
    else if (type == ATTRIBUTE)
        precision = Keys::get().attributesPrecision();
    else
        precision = Keys::get().transformPrecision();
    return roundNumber(value, precision);
}
Пример #7
0
string Token::caseDigit(string str) {
	vector<string> v;
	split(v, str, separators_number);
	if (v.size() > 1) {
		if (v.size() == 2)
			if ((whatIsIt(v[0]) == INTEGER1)
					&& (whatIsIt(v[1]) == INTEGER1)
					&& (v[0].length() == 4))
				if (v[1].length() == 2)
					v[1] = completeYear(v);
		str = "";
		for (unsigned int i = 0; i < v.size(); i++) {
			if (v.size() == 2) //palabras compuestas
				str += v[i];
			candidates.push_back(v[i]);
		}
		str = removeCharacters(str, ".,"); // Elimino los separadores restantes.
		if (whatIsIt(str) != ALPHANUMERIC1)
			str = "";
	} else {
		str = removeCharacters(str, ","); // Elimino el separador de miles.
		string_type tipo = whatIsIt(str); //lo pongo para evaluar solo una vez
		if (tipo == FLOAT1)
			str = roundNumber(str);
		else {
			if (tipo == GARBAGE)
				str = "";
			else if (tipo == INTEGER1) {
				int entero = atoi(str.c_str());
				str = toString(entero);
			}
			str = removeCharacters(str, "."); // Caso de numero.palabra elimina el punto. Ej: "1.the"
		}
	}
	return str;
}
Пример #8
0
int StudentWorld::move()
{
	setDisplayText();
	double roundFactor = 0.9 + 0.1*roundNumber();
	if (testParamsProvided() == true)
	{
		if (m_actors.empty())
		{
			int whichActor = getTestParam(TEST_PARAM_ACTOR_INDEX);
			if (whichActor == TEST_PARAM_NACHLING)
				m_actors.push_back(new Nachling(this, int(5*roundFactor)));
			else if (whichActor == TEST_PARAM_WEALTHY_NACHLING)
				m_actors.push_back(new WealthyNachling(this, int(8*roundFactor)));
			else if (whichActor == TEST_PARAM_SMALLBOT)
				m_actors.push_back(new SmallBot(this, int(12*roundFactor)));
			else if (whichActor == TEST_PARAM_GOODIE_ENERGY)
				m_actors.push_back(new Goodie(IID_ENERGY_GOODIE, this, 15, 39));
			else if (whichActor == TEST_PARAM_GOODIE_TORPEDO)
				m_actors.push_back(new Goodie(IID_TORPEDO_GOODIE, this, 15, 39));
			else if (whichActor == TEST_PARAM_GOODIE_FREE_SHIP)
				m_actors.push_back(new Goodie(IID_FREE_SHIP_GOODIE, this, 15, 39));
		}		
	}
	else
	{
		int numActiveAliens = numberOfActiveAliens();
		m_nMaxAliens = maxAliensAllowed();
		if (numActiveAliens < m_nMaxAliens)
		{
			if (numActiveAliens < m_nNeeded)
			{
				
				int p1 = rand() % 100 + 1;
				if (p1 < 70)
				{
					int p2 = rand() % 100 + 1;
					if (p2 < 20)
						m_actors.push_back(new WealthyNachling(this, int(8*roundFactor)));
					else
						m_actors.push_back(new Nachling(this, int(5*roundFactor)));
				}
				else
					m_actors.push_back(new SmallBot(this, int(12*roundFactor)));
			}
		}
		if (rand() % 3 == 0) // There is a 1 in 3 chance that you will add a single Star to the space field
			m_actors.push_back(new Star(this));
	}
	
	m_player->doSomething();

	std::list<Actor*>::iterator position;
	std::list<Actor*>::iterator temp;
	position = m_actors.begin();
	while (position != m_actors.end())
	{
		(*position)->doSomething();
		if (!(*position)->isAlive())
		{
			temp = position;	
			position++;
			delete (*temp);
			m_actors.erase(temp);
			continue;
		}
		position++;
	}
	if (m_nNeeded <= 0)
	{
		m_roundNumber++;
		nextRound();
	}
	if (m_player->currentEnergy() > 0)
		return GWSTATUS_CONTINUE_GAME;
	else
	{
		decLives();
		return GWSTATUS_PLAYER_DIED;
	}
}
Пример #9
0
TQString const KNumber::toTQString(int width, int prec) const
{
  TQString tmp_str;

  if (*this == Zero) // important to avoid infinite loops below
    return "0";
  switch (type()) {
  case IntegerType:
    if (width > 0) { //result needs to be cut-off
      bool tmp_bool = _fraction_input; // stupid work-around
      _fraction_input = false;
      tmp_str = (KNumber("1.0")*(*this)).toTQString(width, -1);
      _fraction_input = tmp_bool;
    } else
      tmp_str = TQString(_num->ascii());
    break;
  case FractionType:
    if (_float_output) {
      bool tmp_bool = _fraction_input; // stupid work-around
      _fraction_input = false;
      tmp_str = (KNumber("1.0")*(*this)).toTQString(width, -1);
      _fraction_input = tmp_bool;
    } else { // _float_output == false
      if(_splitoffinteger_output) {
	// split off integer part
	KNumber int_part = this->integerPart();
	if (int_part == Zero)
	  tmp_str = TQString(_num->ascii());
	else if (int_part < Zero)
	  tmp_str = int_part.toTQString() + " " + (int_part - *this)._num->ascii();
	else
	  tmp_str = int_part.toTQString() + " " + (*this - int_part)._num->ascii();
      } else
	tmp_str = TQString(_num->ascii());

      if (width > 0  &&  tmp_str.length() > width) {
	//result needs to be cut-off
	bool tmp_bool = _fraction_input; // stupid work-around
	_fraction_input = false;
	tmp_str = (KNumber("1.0")*(*this)).toTQString(width, -1);
	_fraction_input = tmp_bool;
      }
    }

    break;
  case FloatType:
    if (width > 0)
      tmp_str = TQString(_num->ascii(width));
    else
      // rough estimate for  maximal decimal precision (10^3 = 2^10)
      tmp_str = TQString(_num->ascii(3*mpf_get_default_prec()/10));
    break;
  default:
    return TQString(_num->ascii());
  }
  
  if (prec >= 0)
    return roundNumber(tmp_str, prec);
  else
    return tmp_str;
}
Пример #10
0
void t_libraryEditor::moveItem(QPoint pos)
{
    bool selPos = false;
    pos.setX(roundNumber(pos.x()/scale));
    pos.setY(roundNumber(pos.y()/scale));

    std::vector<std::vector<t_symbolObject*>::iterator> closeItems;
/*    for(std::vector<t_symbolObject*>::iterator iter = symbol->items.begin(); iter != symbol->items.end(); ++iter)
    {
        QLine tmpLine = (*iter)->getData();
        if((*iter)->type == WIRE)
        {
            if(hitTest(tmpLine.p1(), tmpLine.p2(), pos) < 35)
            {
                closeItems.push_back(iter);
                if((*iter)->selected)
                {
                    selPos = true;
                    selectedPos = closeItems.size()-1;
                }
            }
        }
        else if((*iter)->type == PIN)
        {
            if(pos == tmpLine.p1())
            {
                closeItems.push_back(iter);
                if((*iter)->selected)
                {
                    selPos = true;
                    selectedPos = closeItems.size()-1;
                }
            }
        }
    }
*/
    if(closeItems.empty())
        return;
    else if(closeItems.size() == 1 || selPos == true)
    {
/*        QLine tmLine = (*closeItems.at(selectedPos))->getData();
        if((*closeItems.at(selectedPos))->type == WIRE)
        {
            if(tmLine.p1() == pos)
            {
                incompleteLine.setP1(tmLine.p2());;
                incompleteStage = true;
                symbol->items.erase(closeItems.at(selectedPos));
            }
            else if(tmLine.p2() == pos)
            {
                incompleteLine.setP1(tmLine.p1());;
                incompleteStage = true;
                symbol->items.erase(closeItems.at(selectedPos));
            }
        }
        else if((*closeItems.at(0))->type == PIN)
        {
            if(tmLine.p1() == pos)
            {
                pinPlacement = true;
                symbol->items.erase(closeItems.at(selectedPos));
            }
        }
        */
    }
    else
    {
        selectPin = true;
//        (*closeItems.at(0))->selected = true;
    }
}
Пример #11
0
void t_libraryEditor::mouseMoveEvent(QMouseEvent *event)
{
    incompleteLine.setP2(QPoint(roundNumber(event->x()/scale), roundNumber(event->y()/scale)));
    repaint();
    event->accept();
}