Exemplo n.º 1
0
Graphics::VertexArray *Thruster::CreateGeometry()
{
	Graphics::VertexArray *verts =
		new Graphics::VertexArray(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0);

	//zero at thruster center
	//+x down
	//+y right
	//+z backwards (or thrust direction)
	const float w = 0.5f;

	vector3f one(0.f, -w, 0.f); //top left
	vector3f two(0.f,  w, 0.f); //top right
	vector3f three(0.f,  w, 1.f); //bottom right
	vector3f four(0.f, -w, 1.f); //bottom left

	//uv coords
	const vector2f topLeft(0.f, 1.f);
	const vector2f topRight(1.f, 1.f);
	const vector2f botLeft(0.f, 0.f);
	const vector2f botRight(1.f, 0.f);

	//add four intersecting planes to create a volumetric effect
	for (int i=0; i < 4; i++) {
		verts->Add(one, topLeft);
		verts->Add(two, topRight);
		verts->Add(three, botRight);

		verts->Add(three, botRight);
		verts->Add(four, botLeft);
		verts->Add(one, topLeft);

		one.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
		two.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
		three.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
		four.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
	}

	return verts;
}
Exemplo n.º 2
0
    void RunTests()
    {
        Solution s;
        TreeNode one(1);
        TreeNode two(2);
        TreeNode four(4);
        TreeNode four_2(4);
        TreeNode five(5);
        TreeNode seven(7);
        TreeNode eight(8);
        TreeNode eleven(11);
        TreeNode thirteen(13);

        // Simple problems
        _ASSERT(!s.hasPathSum(nullptr, 1));
        _ASSERT(s.hasPathSum(&one, 1));

        // Sample problem
        five.left = &four;
        five.right = &eight;
        four.left = &eleven;
        four.right = nullptr;
        eleven.left = &seven;
        eleven.right = &two;
        seven.left = nullptr;
        seven.right = nullptr;
        two.left = nullptr;
        two.right = nullptr;
        eight.left = &thirteen;
        eight.right = &four_2;
        thirteen.left = nullptr;
        thirteen.right = nullptr;
        four_2.left = nullptr;
        four_2.right = &one;
        one.left = nullptr;
        one.right = nullptr;
        _ASSERT(s.hasPathSum(&five, 22));
    }
Exemplo n.º 3
0
    vecN<vecN<OutputType, 2>, 3>
    quadratic_from_cubicT(c_array<const vecN<InputType, 2> > pts)
    {
      FASTUIDRAWassert(pts.size() == 4);

      vecN<IntermediateType, 2> p0(pts[0]), p1(pts[1]), p2(pts[2]), p3(pts[3]);
      IntermediateFloatType three(3), four(4);
      vecN<IntermediateFloatType, 2> q0(pts[0]), q1(pts[1]), q2(pts[2]), q3(pts[3]);
      vecN<IntermediateFloatType, 2> C;

      /* see the discussion at compute_quadratic_cubic_approximate_error()
       * for what the error between the returned quadratic and original
       * cubic is.
       */
      C = (three * q2 - q3 + three * q1 - q0) / four;

      vecN<vecN<OutputType, 2>, 3> return_value;
      return_value[0] = vecN<OutputType, 2>(pts[0]);
      return_value[1] = vecN<OutputType, 2>(C);
      return_value[2] = vecN<OutputType, 2>(pts[3]);

      return return_value;
    }
Exemplo n.º 4
0
void tst_QList::append() const
{
    /* test append(const QList<T> &) function */
    QString one("one");
    QString two("two");
    QString three("three");
    QString four("four");
    QList<QString> list1;
    QList<QString> list2;
    QList<QString> listTotal;
    list1.append(one);
    list1.append(two);
    list2.append(three);
    list2.append(four);
    list1.append(list2);
    qDebug() << list1;
    listTotal.append(one);
    listTotal.append(two);
    listTotal.append(three);
    listTotal.append(four);
    QCOMPARE(list1, listTotal);

}
Exemplo n.º 5
0
static void
PK_skip_specials P2C(FILE *, f,  struct font *, fontp)
{
  int i, j;
  do
    {
      PK_flag_byte = one (f);
      if (PK_flag_byte >= PK_CMD_START)
	{
	  switch (PK_flag_byte)
	    {
	    case PK_X1:
	    case PK_X2:
	    case PK_X3:
	    case PK_X4:
	      {
		i = 0;
		for (j = PK_CMD_START; j <= PK_flag_byte; j++)
		  i = (i * 256) + one (f);
		while (i--)
		  (void) one (f);
		break;
	      }
	    case PK_Y:
	      (void) four (f);
	    case PK_POST:
	    case PK_NOOP:
	      break;
	    default:
	      oops ("Unexpected %d in PK file %s", PK_flag_byte,
		    fontp->fontname);
	      break;
	    }
	}
    }
  while (PK_flag_byte != PK_POST && PK_flag_byte >= PK_CMD_START);
}
Exemplo n.º 6
0
void main()

{
    FILE*file;

    int cases;
    int i,j,k;
    char number[110];

    file=fopen("input.txt","r");

    fscanf(file,"%d",&cases);

    for(i=0; i<cases; i++)
    {
        fscanf(file,"%s",number);
        k=strlen(number);
        for(j=0; j<k; j++)
        {
            number[j]-='0';
        }
        printf("%d %d %d %d %d %d %d %d %d %d\n",two(number,k),three(number,k),four(number,k),five(number,k),six(number,k),seven(number,k),eight(number,k),nine(number,k),ten(number,k),eleven(number,k));
    }
}
Exemplo n.º 7
0
int level4()
{
	lcdFillWindow(0, 239, 0, 319, BACKGROUND_COLOUR);
	map m;
	m.putRectangle(1, 3, 1, 4, 2);
	m.putRectangle(3, 5, 1, 4, 2);
	m.putRectangle(5, 7, 1, 4, 2);
	m.putRectangle(7, 9, 1, 4, 2);
	m.putRectangle(9, 11, 1, 4, 2);
	m.putRectangle(11, 13, 1, 4, 2);
	m.putRectangle(1, 6, 4, 6, 2);
	m.putRectangle(6, 11, 4, 6, 2);
	m.putRectangle(1, 13, 6, 15, 2);
	m.putRectangle(4, 13, 6, 15, 2);
	m.putRectangle(1, 3, 15, 18, 2);
	m.putRectangle(3, 5, 15, 18, 2);
	m.putRectangle(5, 7, 15, 18, 2);
	m.putRectangle(7, 9, 15, 18, 2);
	m.putRectangle(9, 11, 15, 18, 2);
	m.putRectangle(11, 13, 15, 18, 2);

	m.putSpeedBonus(7, 2);
	m.putSpeedBonus(1, 10);
	m.putSpeedBonus(13, 18);
	m.putSpeedBonus(2, 1);
	m.putSpeedBonus(1, 3);
	m.setup();
	enemy one(1, 9, &m);
	enemy two(1, 12, &m);
	enemy three(4, 9, &m);
	enemy four(4, 12, &m);
	pacman five(1, 1, &m);
	wait(2000000);
	return mainLoop(&five, &m, "EVEN BETTER", "LEVEL 4",
			"SEHR SCHLECHT", "TRY AGAIN  ");
}
Exemplo n.º 8
0
void CALLBACK GamePhase::Blink(PVOID lpParameter, BOOLEAN TimerOrWaitFired)
{
	// player posun o 1, enemy++ a pokud % dif = 0, pak taky posun o 1 random smerem
	
	switch (GamePhase::direction) {
		case 0: // doprava
			GamePhase::player = make_pair(GamePhase::player.first + 1, GamePhase::player.second);
			if (GamePhase::player.first == windowWidthC - 8) GamePhase::player = make_pair(0, GamePhase::player.second);
			break;
		case 1: // nahoru
			GamePhase::player = make_pair(GamePhase::player.first, GamePhase::player.second - 1);
			if (GamePhase::player.second == -1) GamePhase::player = make_pair(GamePhase::player.first, windowHeightC - 9);
			break;
		case 2: // doleva
			GamePhase::player = make_pair(GamePhase::player.first - 1, GamePhase::player.second);
			if (GamePhase::player.first == -1) GamePhase::player = make_pair(windowWidthC - 9, GamePhase::player.second);
			break;
		case 3: // dolu
			GamePhase::player = make_pair(GamePhase::player.first, GamePhase::player.second + 1);
			if (GamePhase::player.second == windowHeightC - 8) GamePhase::player = make_pair(GamePhase::player.first, 0);
			break;
	}

	GamePhase::playerPath.push_back(GamePhase::player);
	if (GamePhase::playerPath.size() >= 100)
	{
		GamePhase::RemoveTail(*GamePhase::playerPath.begin());
		GamePhase::playerPath.erase(GamePhase::playerPath.begin());
	}

	switch (GamePhase::enemyDirection) {
	case 0: // doprava
		GamePhase::enemy = make_pair(GamePhase::enemy.first + 1, GamePhase::enemy.second);
		if (GamePhase::enemy.first == windowWidthC - 8) GamePhase::enemy = make_pair(0, GamePhase::enemy.second);
		break;
	case 1: // nahoru
		GamePhase::enemy = make_pair(GamePhase::enemy.first, GamePhase::enemy.second - 1);
		if (GamePhase::enemy.second == -1) GamePhase::enemy = make_pair(GamePhase::enemy.first, windowHeightC - 9);
		break;
	case 2: // doleva
		GamePhase::enemy = make_pair(GamePhase::enemy.first - 1, GamePhase::enemy.second);
		if (GamePhase::enemy.first == -1) GamePhase::enemy = make_pair(windowWidthC - 9, GamePhase::enemy.second);
		break;
	case 3: // dolu
		GamePhase::enemy = make_pair(GamePhase::enemy.first, GamePhase::enemy.second + 1);
		if (GamePhase::enemy.second == windowHeightC - 8) GamePhase::enemy = make_pair(GamePhase::enemy.first, 0);
		break;
	}

	GamePhase::enemyPath.push_back(GamePhase::enemy);
	if (GamePhase::enemyPath.size() >= 100)
	{
		GamePhase::RemoveTail(*GamePhase::enemyPath.begin());
		GamePhase::enemyPath.erase(GamePhase::enemyPath.begin());
	}

	GamePhase::enemyCounter++;
	if (GamePhase::enemyCounter == GamePhase::enemyNextMove)
	{
		GamePhase::enemyCounter = 0;

		random_device rd;
		mt19937 engine(rd());
		uniform_int_distribution<unsigned> dist(10, 20);
		GamePhase::enemyNextMove = dist(engine);

		uniform_int_distribution<unsigned> four(0, 1);

		GamePhase::enemyDirection += 1 - 2 * four(engine);
		if (GamePhase::enemyDirection < 0) GamePhase::enemyDirection = 3;
		else if (GamePhase::enemyDirection > 3) GamePhase::enemyDirection = 0;
	}

	GamePhase::Draw();

	GamePhase::CheckCollision();

}
Exemplo n.º 9
0
void GamePhase::InitGoodGame()
{
	// 3x 10x10 policka, ctvrte na vyber

	// width,height = 50, + borders: 52

	vector<vector<CHAR_INFO>> contentVector;
	vector<CHAR_INFO> rowVector;

	CHAR_INFO chInfo;

	
	chInfo.Attributes = backgroundColorBlackC | foregroundColorGrayC;


	for (size_t i = 0; i < 42; i++)
	{
		for (size_t j = 0; j < 42; j++)
		{
			chInfo.Char.AsciiChar = pieceOfEvilC;
			if (i == 0)
			{
				if (j == 0) chInfo.Char.AsciiChar = borderCornerLeftUpC;
				else if (j == 41) chInfo.Char.AsciiChar = borderCornerRightUpC;
				else chInfo.Char.AsciiChar = borderEdgeHorizontalC;
			}
			else if (i == 41)
			{
				if (j == 0) chInfo.Char.AsciiChar = borderCornerLeftDownC;
				else if (j == 41) chInfo.Char.AsciiChar = borderCornerRightDownC;
				else chInfo.Char.AsciiChar = borderEdgeHorizontalC;
			}
			else if (j == 0 || j == 41) chInfo.Char.AsciiChar = borderEdgeVerticalC;

			rowVector.push_back(chInfo);
		}
		contentVector.push_back(rowVector);
		rowVector.clear();
	}

	
	SMALL_RECT sr;
	sr.Bottom = 42;
	sr.Right = 42;

	for (size_t k = 0; k < 8; k++)
	{
		sr.Top = 5 + (k / 4) * 47;
		sr.Left = 51 + (k % 4) * 52;
	
		ScreenManager::ReplaceCharsAtRect(contentVector, sr);
	}


	//bool *rndStart = new bool[40, 40];

	bool *rndStart = new bool[1600];
	
	random_device rd;
	mt19937 engine(rd());
	uniform_int_distribution<unsigned> dist(0, 39);

	for (size_t i = 0; i < 40; i++)
	{
		for (size_t j = 0; j < 40; j++)
		{
			//rndStart.push_back(nope);
			rndStart[i * 40 + j] = nope;
		}
	}

	vector<pair<size_t, size_t>> bits;

	
	for (size_t i = 0; i < 50; i++)
	{
		bits.push_back(make_pair(dist(engine), dist(engine)));
		rndStart[bits[i].first * 40 + bits[i].second] = yep;
	}

	dist = uniform_int_distribution<unsigned>(0, 49);
	uniform_int_distribution<unsigned> fourty(0, 39);
	uniform_int_distribution<unsigned> four(0, 3);

	vector<pair<size_t, size_t>> chosenBits;
	for (size_t i = 0; i < 4 * monster.GetDifficulty(); i++)
	{
		chosenBits.push_back(make_pair(dist(engine), four(engine)));
	}



	// game panels

	size_t loc = four(engine);


	for (size_t k = 0; k < 8; k++)
	{
		contentVector.clear();
		rowVector.clear();

		if (k < 3)
		{

			for (size_t i = 0; i < 40; i++)
			{
				for (size_t j = 0; j < 40; j++)
				{
					chInfo.Attributes = backgroundColorBlackC | foregroundColorWhiteC;
					chInfo.Char.AsciiChar = rndStart[i * 40 + j] ? pieceOfGodC : pieceOfEvilC;
					rowVector.push_back(chInfo);
				}
				contentVector.push_back(rowVector);
				rowVector.clear();
			}
	
		} else if (k == 3) {
			
			for (size_t i = 0; i < 40; i++)
			{
				for (size_t j = 0; j < 40; j++)
				{
					chInfo.Attributes = backgroundColorBlackC | foregroundColorWhiteC;
					chInfo.Char.AsciiChar = (i + j) % 2 == 0 ? pieceOfEvilC : pieceOfGodC;
					rowVector.push_back(chInfo);
				}
				contentVector.push_back(rowVector);
				rowVector.clear();
			}
		}
		else if (k == 4 + loc) {
			
			for (size_t i = 0; i < 40; i++)
			{
				for (size_t j = 0; j < 40; j++)
				{
					chInfo.Attributes = backgroundColorBlackC | foregroundColorWhiteC;
					chInfo.Char.AsciiChar = rndStart[i * 40 + j] ? pieceOfGodC : pieceOfEvilC;
					rowVector.push_back(chInfo);
				}
				contentVector.push_back(rowVector);
				rowVector.clear();
			}
		} else {
			
			vector<pair<size_t, size_t>> rndBits;

			for (size_t i = 0; i < 50; i++)
			{
				rndStart[bits[i].first * 40 + bits[i].second] = nope;
			}

			for (size_t i = 0; i < 50; i++)
			{
				rndBits.push_back(make_pair(fourty(engine), fourty(engine)));
				rndStart[rndBits[i].first * 40 + rndBits[i].second] = yep;
			}
			
			for (size_t i = 0; i < 40; i++)
			{
				for (size_t j = 0; j < 40; j++)
				{
					chInfo.Attributes = backgroundColorBlackC | foregroundColorWhiteC;
					chInfo.Char.AsciiChar = rndStart[i * 40 + j] ? pieceOfGodC : pieceOfEvilC;
					rowVector.push_back(chInfo);
				}
				contentVector.push_back(rowVector);
				rowVector.clear();
			}
			
			for (size_t i = 0; i < 50; i++)
			{
				rndStart[rndBits[i].first * 40 + rndBits[i].second] = nope;
			}


			for (size_t i = 0; i < 50; i++)
			{
				rndStart[bits[i].first * 40 + bits[i].second] = yep;
			}
		}

		sr.Left = 51 + 1 + (k % 4) * 52;
		sr.Top = 5 + 1 + (k / 4) * 47;
		sr.Bottom = 40;
		sr.Right = 40;

		ScreenManager::ReplaceCharsAtRect(contentVector, sr);
		

		if (k < 3)
		{
			for (size_t i = 0; i < 50; i++)
			{
				rndStart[bits[i].first * 40 + bits[i].second] = nope;
			}

			for (size_t i = 0; i < chosenBits.size(); i++)
			{
				switch (chosenBits[i].second)
				{
				case 0: //+,0
				
					if (bits[chosenBits[i].first].first < 39) bits[chosenBits[i].first] = make_pair(bits[chosenBits[i].first].first + 1, bits[chosenBits[i].first].second);			
					break;
				case 1: //0,+
					if (bits[chosenBits[i].first].second < 39) bits[chosenBits[i].first] = make_pair(bits[chosenBits[i].first].first, bits[chosenBits[i].first].second - 1);			
					break;
				case 2: //-,0
					if (bits[chosenBits[i].first].first > 0) bits[chosenBits[i].first] = make_pair(bits[chosenBits[i].first].first - 1, bits[chosenBits[i].first].second);			
					break;
				case 3: //0,-
					if (bits[chosenBits[i].first].second > 0) bits[chosenBits[i].first] = make_pair(bits[chosenBits[i].first].first, bits[chosenBits[i].first].second + 1);			
					break;
				}
			}

			for (size_t i = 0; i < 50; i++)
			{
				rndStart[bits[i].first * 40 + bits[i].second] = yep;
			}
		}
	
	}

	vector<Key *> keys;

	keys.push_back(new Key('a'));
	keys.push_back(new Key('b'));
	keys.push_back(new Key('c'));
	keys.push_back(new Key('d'));


	vector<function<void()>> f;
	for (size_t i = 0; i < 4; i++)
	{
		if (i == loc) f.push_back(GamePhase::returnFunctionCorrect);
		else f.push_back(GamePhase::returnFunctionBad);
	}

	GamePhase::alertManager.CreateAndShowAlerts(keys, GamePhase::alertRect, backgroundColorBlackC | foregroundColorWhiteC, commonWaitingSpeedC, f, false);
	
	delete[] rndStart;

}
Exemplo n.º 10
0
void
read_PK_index(struct font *fontp, wide_bool hushcs)
{
    int hppp, vppp;
    long checksum;

    fontp->read_char = read_PK_char;
    if (debug & DBG_PK)
	Printf("Reading PK pixel file %s\n", fontp->filename);

    Fseek(fontp->file, (long)one(fontp->file), 1);	/* skip comment */

    (void)four(fontp->file);	/* skip design size */
    checksum = four(fontp->file);
    if (checksum != fontp->checksum && checksum != 0 && fontp->checksum != 0
	&& !hushcs)
	    Fprintf(stderr,
		    "Checksum mismatch (dvi = %lu, pk = %lu) in font file %s\n",
		    fontp->checksum, checksum, fontp->filename);
    hppp = sfour(fontp->file);
    vppp = sfour(fontp->file);
    if (hppp != vppp && (debug & DBG_PK))
	Printf("Font has non-square aspect ratio %d:%d\n", vppp, hppp);
    /*
     * Prepare glyph array.
     */
    fontp->glyph = xmalloc(256 * sizeof(struct glyph));
    bzero((char *)fontp->glyph, 256 * sizeof(struct glyph));
    /*
     * Read glyph directory (really a whole pass over the file).
     */
    for (;;) {
	int bytes_left, flag_low_bits;
	unsigned int ch;

	PK_skip_specials(fontp);
	if (PK_flag_byte == PK_POST)
	    break;
	flag_low_bits = PK_flag_byte & 0x7;
	if (flag_low_bits == 7) {
	    bytes_left = four(fontp->file);
	    ch = four(fontp->file);
	}
	else if (flag_low_bits > 3) {
	    bytes_left = ((flag_low_bits - 4) << 16) + two(fontp->file);
	    ch = one(fontp->file);
	}
	else {
	    bytes_left = (flag_low_bits << 8) + one(fontp->file);
	    ch = one(fontp->file);
	}
	fontp->glyph[ch].addr = ftell(fontp->file);
	fontp->glyph[ch].x2 = PK_flag_byte;
#ifdef linux
#ifndef SHORTSEEK
#define SHORTSEEK 2048
#endif
	/* A bug in Linux libc (as of 18oct94) makes a short read faster
	   than a short forward seek. Totally non-intuitive.  */
	if (bytes_left > 0 && bytes_left < SHORTSEEK) {
	    char *dummy = xmalloc(bytes_left);
	    Fread(dummy, 1, bytes_left, fontp->file);
	    free(dummy);
	}
	else
	    /* seek backward, or long forward */
#endif /* linux */
	    Fseek(fontp->file, (long)bytes_left, 1);
	if (debug & DBG_PK)
	    Printf("Scanning pk char %u, at %ld.\n", ch, fontp->glyph[ch].addr);
    }
}
Exemplo n.º 11
0
static void
read_PK_char(struct font *fontp, wide_ubyte ch)
{
    int i, j;
    int n;
    int row_bit_pos;
    Boolean paint_switch;
    BMUNIT *cp;
    struct glyph *g;
    FILE *fp = fontp->file;
    long fpwidth;
    BMUNIT word = 0;
    int word_weight, bytes_wide;
    int rows_left, h_bit, count;

    g = &fontp->glyph[ch];
    PK_flag_byte = g->x2;
    PK_dyn_f = PK_flag_byte >> 4;
    paint_switch = ((PK_flag_byte & 8) != 0);
    PK_flag_byte &= 0x7;
    if (PK_flag_byte == 7)
	n = 4;
    else if (PK_flag_byte > 3)
	n = 2;
    else
	n = 1;

    if (debug & DBG_PK)
	Printf("loading pk char %d, char type %d ", ch, n);

    /*
     * now read rest of character preamble
     */
    if (n != 4)
	fpwidth = num(fp, 3);
    else {
	fpwidth = sfour(fp);
	(void)four(fp);	/* horizontal escapement */
    }
    (void)num(fp, n);	/* vertical escapement */
    {
	unsigned long w, h;

	w = num(fp, n);
	h = num(fp, n);
	if (w > 0x7fff || h > 0x7fff)
	    oops("Character %d too large in file %s", ch, fontp->fontname);
	g->bitmap.w = w;
	g->bitmap.h = h;
    }
    g->x = snum(fp, n);
    g->y = snum(fp, n);

    g->dvi_adv = fontp->dimconv * fpwidth;

    if (debug & DBG_PK) {
	if (g->bitmap.w != 0)
	    Printf(", size=%dx%d, dvi_adv=%ld", g->bitmap.w, g->bitmap.h,
		   g->dvi_adv);
	Putchar('\n');
    }

    alloc_bitmap(&g->bitmap);
    cp = (BMUNIT *) g->bitmap.bits;

    /*
     * read character data into *cp
     */
    bytes_wide = ROUNDUP((int)g->bitmap.w, BMBITS) * BMBYTES;
    PK_bitpos = -1;
    if (PK_dyn_f == 14) {	/* get raster by bits */
	bzero(g->bitmap.bits, (int)g->bitmap.h * bytes_wide);
	for (i = 0; i < (int)g->bitmap.h; i++) {	/* get all rows */
	    cp = ADD(g->bitmap.bits, i * bytes_wide);
#ifndef	WORDS_BIGENDIAN
	    row_bit_pos = -1;
#else
	    row_bit_pos = BMBITS;
#endif
	    for (j = 0; j < (int)g->bitmap.w; j++) {	/* get one row */
		if (--PK_bitpos < 0) {
		    word = one(fp);
		    PK_bitpos = 7;
		}
#ifndef	WORDS_BIGENDIAN
		if (++row_bit_pos >= BMBITS) {
		    cp++;
		    row_bit_pos = 0;
		}
#else
		if (--row_bit_pos < 0) {
		    cp++;
		    row_bit_pos = BMBITS - 1;
		}
#endif
		if (word & (1 << PK_bitpos))
		    *cp |= 1 << row_bit_pos;
	    }
	}
    }
    else {	/* get packed raster */
	rows_left = g->bitmap.h;
	h_bit = g->bitmap.w;
	PK_repeat_count = 0;
	word_weight = BMBITS;
	word = 0;
	while (rows_left > 0) {
	    count = PK_packed_num(fp);
	    while (count > 0) {
		if (count < word_weight && count < h_bit) {
#ifndef	WORDS_BIGENDIAN
		    if (paint_switch)
			word |= bit_masks[count] << (BMBITS - word_weight);
#endif
		    h_bit -= count;
		    word_weight -= count;
#ifdef	WORDS_BIGENDIAN
		    if (paint_switch)
			word |= bit_masks[count] << word_weight;
#endif
		    count = 0;
		}
		else if (count >= h_bit && h_bit <= word_weight) {
		    if (paint_switch)
			word |= bit_masks[h_bit] <<
#ifndef	WORDS_BIGENDIAN
			    (BMBITS - word_weight);
#else
			    (word_weight - h_bit);
#endif
		    *cp++ = word;
		    /* "output" row(s) */
		    for (i = PK_repeat_count * bytes_wide / BMBYTES; i > 0; --i) {
			*cp = *SUB(cp, bytes_wide);
			++cp;
		    }
		    rows_left -= PK_repeat_count + 1;
		    PK_repeat_count = 0;
		    word = 0;
		    word_weight = BMBITS;
		    count -= h_bit;
		    h_bit = g->bitmap.w;
		}
		else {
		    if (paint_switch)
#ifndef	WORDS_BIGENDIAN
			word |= bit_masks[word_weight] <<
			    (BMBITS - word_weight);
#else
			word |= bit_masks[word_weight];
#endif
		    *cp++ = word;
		    word = 0;
		    count -= word_weight;
		    h_bit -= word_weight;
		    word_weight = BMBITS;
		}
	    }
	    paint_switch = 1 - paint_switch;
	}
	if (cp != ((BMUNIT *) (g->bitmap.bits + bytes_wide * g->bitmap.h)))
	    oops("Wrong number of bits stored:  char. %d, font %s", ch,
		 fontp->fontname);
	if (rows_left != 0 || h_bit != g->bitmap.w)
	    oops("Bad pk file (%s), too many bits", fontp->fontname);
    }
}
Exemplo n.º 12
0
int main()
{
	Node<std::string> six("6");
	Node<std::string> five("5");
	Node<std::string> four("4");
	Node<std::string> three("3");
	Node<std::string> two("2");
	Node<std::string> one("1");
	Node<std::string> zero("0");

	DAG<std::string> myGraph;

	myGraph.beginTransaction();

	myGraph.addEdge(four, one);
	myGraph.addEdge(two, three);
	myGraph.addEdge(three, one);
	myGraph.addEdge(five, two);
	myGraph.addEdge(five, zero);
	myGraph.addEdge(four, zero);

	myGraph.endTransaction();

	myGraph.report();

	Node<std::string> next;
	if (myGraph.next(next))
	{
		std::cout << "Next: " << next.value << std::endl;
		myGraph.remove(next);
	}
	if (myGraph.next(next))
	{
		std::cout << "Next: " << next.value << std::endl;
		myGraph.remove(next);
	}

	myGraph.addNode(six);

	if (myGraph.next(next))
	{
		std::cout << "Next: " << next.value << std::endl;
		myGraph.remove(next);
	}
	if (myGraph.next(next))
	{
		std::cout << "Next: " << next.value << std::endl;
		myGraph.remove(next);
	}
	if (myGraph.next(next))
	{
		std::cout << "Next: " << next.value << std::endl;
		myGraph.remove(next);
	}
	if (myGraph.next(next))
	{
		std::cout << "Next: " << next.value << std::endl;
		myGraph.remove(next);
	}
	if (myGraph.next(next))
	{
		std::cout << "Next: " << next.value << std::endl;
		myGraph.remove(next);
	}

	return 0;
}
Exemplo n.º 13
0
	GPL_NONE,		/* GF_CHAR_LOC */
	GPL_NONE,		/* GF_CHAR_LOC0 */
	GPL_NONE,		/* GF_PRE */
	GPL_NONE,		/* GF_POST */
	GPL_NONE,		/* GF_POSTPOST */
	six(GPL_NONE)		/* 250 through 255 */
};

/*
 * Types of the various opcodes.
 */
char gf_gt[256] = {
	sixty_four(GT_PAINT0),	/* GF_PAINT_0 through GF_PAINT_63 */
	three(GT_PAINT),	/* GF_PAINT1 through GF_PAINT3 */
	GT_BOC,			/* GF_BOC */
	GT_BOC1,		/* GF_BOC1 */
	GT_EOC,			/* GF_EOC */
	GT_SKIP0,		/* GF_SKIP0 */
	three(GT_SKIP),		/* GF_SKIP1 through GF_SKIP3 */
	one_sixty_five(GT_NEW_ROW),/* GF_NEW_ROW_0 throgh GF_NEW_ROW_164 */
	four(GT_XXX),		/* GF_XXX1 through GF_XXX4 */
	GT_YYY,			/* GF_YYY */
	GT_NOP,			/* GF_NOP */
	GT_CHAR_LOC,		/* GF_CHAR_LOC */
	GT_CHAR_LOC0,		/* GF_CHAR_LOC0 */
	GT_PRE,			/* GF_PRE */
	GT_POST,		/* GF_POST */
	GT_POSTPOST,		/* GF_POSTPOST */
	six(GT_UNDEF)		/* 250 through 255 */
};
Exemplo n.º 14
0
Limbs::Limbs(Encoding &g)
  :genome(g)
{
  //create Traits
  Trait spindly(1, -3, 3, "spindly");
  Trait thin(1, -2, 1, "thin");
  Trait thick(-2, 3, 0, "thick");
  Trait round(3, -1, -1, "round");

  Trait zero(0, 0, 3, "0");
  Trait one(1, 1, 3, "1");
  Trait two(3, 1, -3, "2");
  Trait three(-1, 1, 3, "3");
  Trait four(3, 1, -3, "4");
  Trait five(-1, 1, 3, "5");
  Trait six(2, 1, -3, "6");
  Trait seven(-2, 2, 3, "7");
  Trait eight(0, 3, 2, "8");
  Trait nine(-3, 2, 3, "9");
  Trait ten(-2, 3, 2, "10");
  Trait eleven(-3, 2, 3, "11");
  Trait twelve(-3, 3, 2, "12");
  Trait thirteen(-3, 2, 3, "13");
  Trait fourteen(-3, 3, 3, "14");
  Trait fifteen(-3, 2, 3, "15");



  //create all maps
  if (thicknessK.empty() ) {

    thicknessK["spindly"] = 0;
    thicknessK["thin"] = 1;
    thicknessK["thick"] = 2;
    thicknessK["round"] = 3;

    thicknessM[0] = spindly;
    thicknessM[1] = thin;
    thicknessM[2] = thick;
    thicknessM[3] = round;

    numM[0] = zero;
    numM[1] = one;
    numM[2] = two;
    numM[3] = three;
    numM[4] = four;
    numM[5] = five;
    numM[6] = six;
    numM[7] = seven;
    numM[8] = eight;
    numM[9] = nine;
    numM[10] = ten;
    numM[11] = eleven;
    numM[12] = twelve;
    numM[13] = thirteen;
    numM[14] = fourteen;
    numM[15] = fifteen;
  }

  //decode the number of limbs so that there can
  //only be a non-zero even number of them
  number = decodeNumber();
  int numValue = std::stoi(number);
  if (numValue % 2 != 0) {
    encodeNumber(numValue + 1);
    number = decodeNumber();
  }
  if (numValue == 0) {
    encodeNumber(2);
    number = decodeNumber();
  }

  thickness = decodeThickness();


}
Exemplo n.º 15
0
void Projectile::BuildModel()
{
	//set up materials
	Graphics::MaterialDescriptor desc;
	desc.textures = 1;
	s_sideMat.reset(Pi::renderer->CreateMaterial(desc));
	s_glowMat.reset(Pi::renderer->CreateMaterial(desc));
	s_sideMat->texture0 = Graphics::TextureBuilder::Billboard("textures/projectile_l.png").GetOrCreateTexture(Pi::renderer, "billboard");
	s_glowMat->texture0 = Graphics::TextureBuilder::Billboard("textures/projectile_w.png").GetOrCreateTexture(Pi::renderer, "billboard");

	//zero at projectile position
	//+x down
	//+y right
	//+z forwards (or projectile direction)
	const float w = 0.5f;

	vector3f one(0.f, -w, 0.f); //top left
	vector3f two(0.f,  w, 0.f); //top right
	vector3f three(0.f,  w, -1.f); //bottom right
	vector3f four(0.f, -w, -1.f); //bottom left

	//uv coords
	const vector2f topLeft(0.f, 1.f);
	const vector2f topRight(1.f, 1.f);
	const vector2f botLeft(0.f, 0.f);
	const vector2f botRight(1.f, 0.f);

	s_sideVerts.reset(new Graphics::VertexArray(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0));
	s_glowVerts.reset(new Graphics::VertexArray(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0));

	//add four intersecting planes to create a volumetric effect
	for (int i=0; i < 4; i++) {
		s_sideVerts->Add(one, topLeft);
		s_sideVerts->Add(two, topRight);
		s_sideVerts->Add(three, botRight);

		s_sideVerts->Add(three, botRight);
		s_sideVerts->Add(four, botLeft);
		s_sideVerts->Add(one, topLeft);

		one.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
		two.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
		three.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
		four.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
	}

	//create quads for viewing on end
	float gw = 0.5f;
	float gz = -0.1f;

	for (int i=0; i < 4; i++) {
		s_glowVerts->Add(vector3f(-gw, -gw, gz), topLeft);
		s_glowVerts->Add(vector3f(-gw, gw, gz), topRight);
		s_glowVerts->Add(vector3f(gw, gw, gz), botRight);

		s_glowVerts->Add(vector3f(gw, gw, gz), botRight);
		s_glowVerts->Add(vector3f(gw, -gw, gz), botLeft);
		s_glowVerts->Add(vector3f(-gw, -gw, gz), topLeft);

		gw -= 0.1f; // they get smaller
		gz -= 0.2f; // as they move back
	}

	Graphics::RenderStateDesc rsd;
	rsd.blendMode = Graphics::BLEND_ALPHA_ONE;
	rsd.depthWrite = false;
	rsd.cullMode = Graphics::CULL_NONE;
	s_renderState = Pi::renderer->CreateRenderState(rsd);
}
Exemplo n.º 16
0
void test_epsilon_deleting()
{
	std::cout << "Testing epsilon deleting..." << std::endl << std::endl;

	State zero("0", state_type::NONFINAL);
	State one("1", state_type::NONFINAL);
	State two("2", state_type::FINAL);
	State three("3", state_type::NONFINAL);
	State four("4", state_type::FINAL);
	State five("5", state_type::NONFINAL);

	std::vector<State*> states;

	std::set<State*> zeroStatesEps;
	std::set<State*> oneStatesA;
	std::set<State*> twoStatesEps;
	std::set<State*> twoStatesA;
	std::set<State*> threeStatesEps;
	std::set<State*> fourStates;
	std::set<State*> fiveStatesEps;
	std::set<State*> fiveStatesB;

	states.push_back(&zero);
	states.push_back(&one);
	states.push_back(&two);
	states.push_back(&three);
	states.push_back(&four);
	states.push_back(&five);

	zeroStatesEps.insert(&one);
	zeroStatesEps.insert(&two);
	zeroStatesEps.insert(&three);
	oneStatesA.insert(&four);
	twoStatesEps.insert(&four);
	twoStatesA.insert(&five);
	threeStatesEps.insert(&five);
	fiveStatesEps.insert(&three);
	fiveStatesB.insert(&four);

	std::unordered_map<char , std::set<State*> > zeroTransitions;
	std::unordered_map<char , std::set<State*> > oneTransitions;
	std::unordered_map<char , std::set<State*> > twoTransitions;
	std::unordered_map<char , std::set<State*> > threeTransitions;
	std::unordered_map<char , std::set<State*> > fourTransitions;
	std::unordered_map<char , std::set<State*> > fiveTransitions;

	zeroTransitions[0] = zeroStatesEps;
	oneTransitions['a'] = oneStatesA;
	twoTransitions[0] = twoStatesEps;
	twoTransitions['a'] = twoStatesA;
	threeTransitions[0] = threeStatesEps;
	fiveTransitions[0] = fiveStatesEps;
	fiveTransitions['b'] = fiveStatesB;

	std::unordered_map< State*,  std::unordered_map<char , std::set<State*> > > transitions;

	transitions[&zero] = zeroTransitions;
	transitions[&one] = oneTransitions;
	transitions[&two] = twoTransitions;
	transitions[&three] = threeTransitions;
	transitions[&four] = fourTransitions;
	transitions[&five] = fiveTransitions;

	Automata automata(transitions);
	automata.setInitial(&zero);
	automata.setStates(states);

	std::cout << "Before:" << std::endl << automata << std::endl;

	std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
	
	automata.removeEpsilonTransitions();

	std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();

	std::cout << "After: " << std::endl << automata << std::endl;
	
	auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();
	std::cout << "Execution time: " << duration << " milliseconds." << std::endl << std::endl;
}
Exemplo n.º 17
0
Projectile::Projectile(): Body()
{
	m_orient = matrix4x4d::Identity();
	m_type = 1;
	m_age = 0;
	m_parent = 0;
	m_radius = 0;
	m_flags |= FLAG_DRAW_LAST;

	//set up materials
	m_sideMat.texture0 = Graphics::TextureBuilder::Billboard(projectileTextureFilename).GetOrCreateTexture(Pi::renderer, "billboard");
	m_sideMat.unlit = true;
	m_sideMat.twoSided = true;
	m_glowMat.texture0 = Graphics::TextureBuilder::Billboard(projectileGlowTextureFilename).GetOrCreateTexture(Pi::renderer, "billboard");
	m_glowMat.unlit = true;
	m_glowMat.twoSided = true;

	//zero at projectile position
	//+x down
	//+y right
	//+z forwards (or projectile direction)
	const float w = 0.5f;

	vector3f one(0.f, -w, 0.f); //top left
	vector3f two(0.f,  w, 0.f); //top right
	vector3f three(0.f,  w, -1.f); //bottom right
	vector3f four(0.f, -w, -1.f); //bottom left

	//uv coords
	const vector2f topLeft(0.f, 1.f);
	const vector2f topRight(1.f, 1.f);
	const vector2f botLeft(0.f, 0.f);
	const vector2f botRight(1.f, 0.f);

	m_sideVerts.Reset(new Graphics::VertexArray(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0));
	m_glowVerts.Reset(new Graphics::VertexArray(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0));

	//add four intersecting planes to create a volumetric effect
	for (int i=0; i < 4; i++) {
		m_sideVerts->Add(one, topLeft);
		m_sideVerts->Add(two, topRight);
		m_sideVerts->Add(three, botRight);

		m_sideVerts->Add(three, botRight);
		m_sideVerts->Add(four, botLeft);
		m_sideVerts->Add(one, topLeft);

		one.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
		two.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
		three.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
		four.ArbRotate(vector3f(0.f, 0.f, 1.f), DEG2RAD(45.f));
	}

	//create quads for viewing on end
	float gw = 0.5f;
	float gz = -0.1f;

	for (int i=0; i < 4; i++) {
		m_glowVerts->Add(vector3f(-gw, -gw, gz), topLeft);
		m_glowVerts->Add(vector3f(-gw, gw, gz), topRight);
		m_glowVerts->Add(vector3f(gw, gw, gz), botRight);

		m_glowVerts->Add(vector3f(gw, gw, gz), botRight);
		m_glowVerts->Add(vector3f(gw, -gw, gz), botLeft);
		m_glowVerts->Add(vector3f(-gw, -gw, gz), topLeft);

		gw -= 0.1f; // they get smaller
		gz -= 0.2; // as they move back
	}
}
Exemplo n.º 18
0
unsigned long
#else
void
#endif
read_VF_index(struct font *fontp, wide_bool hushcs)
{
    FILE *VF_file = fontp->file;
    ubyte cmnd;
    ubyte *avail, *availend;	/* available space for macros */
    long checksum;
#ifdef Omega
    struct macro *newmacro;
    unsigned long maxcc = 0;
    int i;
#endif
    Boolean dummy = False;
    
    fontp->read_char = NULL;
    fontp->flags |= FONT_VIRTUAL;
    fontp->set_char_p = set_vf_char;
    if (debug & DBG_PK)
	Printf("Reading VF file %s\n", fontp->filename);
/*
 *	Read preamble.
 */
    Fseek(VF_file, (long)one(VF_file), 1);	/* skip comment */
    checksum = four(VF_file);
    if (checksum != fontp->checksum && checksum != 0 && fontp->checksum != 0
	&& !hushcs)
	    Fprintf(stderr,
		    "Checksum mismatch (dvi = %lu, vf = %lu) in font file %s\n",
		    fontp->checksum, checksum, fontp->filename);
    (void)four(VF_file);	/* skip design size */
/*
 *	Read the fonts.
 */
    fontp->vf_table = xmalloc(VFTABLELEN * sizeof(struct font *));
    bzero((char *)fontp->vf_table, VFTABLELEN * sizeof(struct font *));
    fontp->vf_chain = NULL;
    fontp->first_font = NULL;

    while ((cmnd = one(VF_file)) >= FNTDEF1 && cmnd <= FNTDEF4) {
	struct font *newfontp = define_font(VF_file, cmnd, fontp,
					    fontp->vf_table, VFTABLELEN,
					    &fontp->vf_chain,
					    &dummy);
	if (fontp->first_font == NULL)
	    fontp->first_font = newfontp;
    }
/*
 *	Prepare macro array.
 */
#ifdef Omega
    fontp->maxchar = 65535;
    fontp->macro = xmalloc(65536 * sizeof(struct macro));
    bzero((char *)fontp->macro, 65536 * sizeof(struct macro));
#else
    fontp->macro = xmalloc(256 * sizeof(struct macro));
    bzero((char *)fontp->macro, 256 * sizeof(struct macro));
#endif
/*
 *	Read macros.
 */
    avail = availend = NULL;
    for (; cmnd <= LONG_CHAR; cmnd = one(VF_file)) {
	struct macro *m;
	int len;
	unsigned long cc;
	long width;

	if (cmnd == LONG_CHAR) {	/* long form packet */
	    len = four(VF_file);
	    cc = four(VF_file);
	    width = four(VF_file);
#ifdef Omega
	    if (cc >= 65536) {
#else
	    if (cc >= 256) {
#endif
		Fprintf(stderr,
			"Virtual character %lu in font %s ignored.\n",
			cc, fontp->fontname);
		Fseek(VF_file, (long)len, 1);
		continue;
	    }
	}
	else {	/* short form packet */
	    len = cmnd;
	    cc = one(VF_file);
	    width = num(VF_file, 3);
	}
#ifdef Omega
	maxcc = (cc > maxcc) ? cc : maxcc;
#endif
	m = &fontp->macro[cc];
	m->dvi_adv = width * fontp->dimconv;
	if (len > 0) {
	    if (len <= availend - avail) {
		m->pos = avail;
		avail += len;
	    }
	    else {
		m->free_me = True;
		if (len <= VF_PARM_1) {
		    m->pos = avail = xmalloc(VF_PARM_2);
		    availend = avail + VF_PARM_2;
		    avail += len;
		}
		else
		    m->pos = xmalloc((unsigned)len);
	    }
	    Fread((char *)m->pos, 1, len, VF_file);
	    m->end = m->pos + len;
	}
	if (debug & DBG_PK)
	    Printf("Read VF macro for character %lu; dy = %ld, length = %d\n",
		   cc, m->dvi_adv, len);
    }
    if (cmnd != POST)
	oops("Wrong command byte found in VF macro list:  %d", cmnd);

    Fclose(VF_file);
    fontp->file = NULL;
    n_files_left++;
#ifdef Omega
    newmacro = xmalloc((maxcc + 1) * sizeof(struct macro));
    for (i = 0; i <= maxcc; i++) {
	newmacro[i] = fontp->macro[i];
    }
    free(fontp->macro);
    fontp->macro = newmacro;
    fontp->maxchar = maxcc;
    return maxcc;
#endif
}
Exemplo n.º 19
0
void five(int size)
{
	four(size);
}
Exemplo n.º 20
0
int main()
{
    printf("== one() ==\n");
    one(3, 4);
    one(10, 10);


    printf("== two() ==\n");
    const char* a = "20";
    two(a);
    const char* b = "100";
    two(b);

    printf("== three() ==\n");
    three();


    printf("== four() ==\n");
    four(0.5);
    four(1.5);


    printf("== five() ==\n");
    const int num1 = 3;
    const int num2 = 3;
    five(&num1, &num2);

    const int num3 = 4;
    five(&num1, &num3);


    printf("== six() ==\n");
    float *p_six;
    int i4 = 4, i432 = 432;

    p_six = six(&i4);
    printf("%d == %f\n", i4, *p_six);
    free(p_six);

    p_six = six(&i432);
    printf("%d == %f\n", i432, *p_six);
    free(p_six);


    printf("== seven() ==\n");
    const char s = 'S';
    seven(&s);
    const char t = '_';
    seven(&t);


    printf("== eight() ==\n");
    eight();


    printf("== nine() ==\n");
    nine();


    printf("== ten() ==\n");
    int i_ten = 100;
    ten(&i_ten);
    printf("%d == 0?\n", i_ten);


    printf("== eleven() ==\n");
    eleven();


    printf("== twelve() ==\n");
    twelve();


    printf("== thirteen() ==\n");
    thirteen(10);


    printf("== fourteen() ==\n");
    fourteen("red");
    fourteen("orange");
    fourteen("blue");
    fourteen("green");


    printf("== fifteen() ==\n");
    fifteen(1);
    fifteen(2);
    fifteen(3);


    printf("== sixteen() ==\n");
    char *str = sixteen();
    printf("%s\n", str);
    free(str);


    printf("== seventeen() ==\n");
    seventeen(35);
    seventeen(20);


    printf("== eighteen() ==\n");
    eighteen(3);
    eighteen(5);


    printf("== clear_bits() ==\n");
    long int result;

    result = clear_bits(0xFF, 0x55);
    printf("%ld\n", result);

    result = clear_bits(0x00, 0xF0);
    printf("%ld\n", result);

    result = clear_bits(0xAB, 0x00);
    printf("%ld\n", result);

    result = clear_bits(0xCA, 0xFE);
    printf("%ld\n", result);

    result = clear_bits(0x14, 0x00);
    printf("%ld\n", result);

    result = clear_bits(0xBB, 0xBB);
    printf("%ld\n", result);


    return 0;
}
Exemplo n.º 21
0
static void tst1() {
    unsynch_mpq_manager nm;
    polynomial::manager m(nm);
    polynomial_ref x(m);
    x = m.mk_polynomial(m.mk_var());
    polynomial_ref p(m);
    p = 3*x - 2;

    algebraic_numbers::manager am(nm);
    scoped_anum_vector rs1(am);
    std::cout << "p: " << p << "\n";
    am.isolate_roots(p, rs1);
    display_anums(std::cout, rs1);
    SASSERT(rs1.size() == 1);
    std::cout.flush();

    p = (x^2) - 2;
    std::cout << "p: " << p << "\n";
    rs1.reset();
    am.isolate_roots(p, rs1);
    display_anums(std::cout, rs1);
    SASSERT(rs1.size() == 2);

    scoped_anum sqrt2(am);
    am.set(sqrt2, rs1[1]);

    scoped_mpq  q(nm);
    nm.set(q, 1, 3);
    scoped_anum aq(am);
    am.set(aq, q); // create algebraic number representing 1/3

    am.add(sqrt2, aq, aq);
    std::cout << "sqrt(2) + 1/3: ";
    am.display_decimal(std::cout, aq, 10); std::cout << " "; am.display_interval(std::cout, aq);
    std::cout << " "; am.display_root(std::cout, aq); std::cout << "\n";

    am.set(aq, q);
    am.add(rs1[0], aq, aq);
    std::cout << "-sqrt(2) + 1/3: ";
    am.display_decimal(std::cout, aq, 10); std::cout << " "; am.display_interval(std::cout, aq);
    std::cout << " "; am.display_root(std::cout, aq); std::cout << "\n";

    p = ((x^5) - x - 1)*(x-1)*(x-2);
    std::cout << "p: " << p << "\n";
    rs1.reset();
    am.isolate_roots(p, rs1);
    display_anums(std::cout, rs1);
    SASSERT(rs1.size() == 3);

    scoped_anum gauss(am);
    am.set(gauss, rs1[1]);

    std::cout << "compare(" << sqrt2 << ", " << gauss << "): " << am.compare(sqrt2, gauss) << "\n";

    statistics st;
    am.collect_statistics(st);
    st.display_smt2(std::cout);

    p = ((x^2) - 2)*((x^2) - 3);
    std::cout << "p: " << p << "\n";
    rs1.reset();
    am.isolate_roots(p, rs1);
    display_anums(std::cout, rs1);
    SASSERT(rs1.size() == 4);

    scoped_anum hidden_sqrt2(am);
    am.set(hidden_sqrt2, rs1[2]);

    std::cout << "compare(" << sqrt2 << ", " << hidden_sqrt2 << "): " << am.compare(sqrt2, hidden_sqrt2) << "\n";
    st.reset();
    am.collect_statistics(st);
    st.display_smt2(std::cout);

    std::cout << "sqrt(2)^4: " << (sqrt2^4) << "\n";

    SASSERT(is_int(power(sqrt2, 4)));
    SASSERT(power(sqrt2, 4) == 4);

    scoped_anum sqrt2_gauss(am);
    am.add(sqrt2, gauss, sqrt2_gauss);
    std::cout << "sqrt2 + gauss: " << sqrt2_gauss << " "; am.display_root(std::cout, sqrt2_gauss); std::cout << "\n";

    std::cout << "sqrt2*sqrt2: " << sqrt2*sqrt2 << "\n";
    std::cout << "sqrt2*sqrt2 == 2: " << (sqrt2*sqrt2 == 2) << std::endl;

    scoped_anum three(am);
    am.set(three, -3);

    std::cout << "(-3)^(1/5): " << root(three, 5) << "\n";
    std::cout << "sqrt(2)^(1/3): " << root(sqrt2, 3) << "\n";
    std::cout << "as-root-object(sqrt(2)^(1/3)): " << root_obj_pp(root(sqrt2, 3)) << "\n";
    std::cout << "(sqrt(2) + 1)^(1/3): " << root(sqrt2 + 1, 3) << "\n";
    std::cout << "as-root-object((sqrt(2) + 1)^(1/3)): " << root_obj_pp(root(sqrt2 + 1, 3)) << "\n";
    std::cout << "(sqrt(2) + gauss)^(1/5): " << root(sqrt2 + gauss, 5) << "\n";
    std::cout << "as-root-object(sqrt(2) + gauss)^(1/5): " << root_obj_pp(root(sqrt2 + gauss, 5)) << "\n";
    std::cout << "(sqrt(2) / sqrt(2)): " << sqrt2 / hidden_sqrt2 << "\n";
    std::cout << "(sqrt(2) / gauss): " << sqrt2 / gauss << "\n";
    std::cout << "(sqrt(2) / gauss) 30 digits: " << decimal_pp(sqrt2 / gauss, 30) << "\n";
    std::cout << "as-root-object(sqrt(2) / gauss): " << root_obj_pp(sqrt2 / gauss) << "\n";
    std::cout << "is_int(sqrt(2)^(1/3)): " << am.is_int(root(sqrt2, 3)) << "\n";

    scoped_anum tmp(am);
    scoped_anum four(am);
    am.set(four, 4);
    am.set(tmp, sqrt2);
    am.inv(tmp);
    std::cout << "1/sqrt(2): " << tmp << "\n";
    am.mul(tmp, four, tmp);
    std::cout << "4*1/sqrt(2): " << tmp << "  " << root_obj_pp(tmp) << "\n";
    am.mul(tmp, sqrt2, tmp);
    std::cout << "sqrt(2)*4*(1/sqrt2): " << tmp << "  " << root_obj_pp(tmp) << "\n";
    std::cout << "is_int(sqrt(2)*4*(1/sqrt2)): " << am.is_int(tmp) << ", after is-int: " << tmp << "\n";

    p = (998*x - 1414)*((x^2) - 15);
    std::cout << "p: " << p << "\n";
    rs1.reset();
    am.isolate_roots(p, rs1);

    std::cout << "is-rational(sqrt2): " << am.is_rational(sqrt2) << "\n";

    scoped_anum qr(am);
    am.set(qr, rs1[1]);

    std::cout << "qr: " << root_obj_pp(qr);
    std::cout << ", is-rational: " << am.is_rational(qr) << ", val: " << root_obj_pp(qr) << "\n";

    return;

    std::cout << "compare(" << sqrt2 << ", " << gauss << "): " << am.compare(sqrt2, gauss) << "\n";

    p = (x^16) - 136*(x^14) + 6476*(x^12) - 141912*(x^10) + 1513334*(x^8) - 7453176*(x^6) + 13950764*(x^4) - 5596840*(x^2) + 46225;
    std::cout << "p: " << p << "\n";
    rs1.reset();
    am.isolate_roots(p, rs1);
    display_anums(std::cout, rs1);
}
Exemplo n.º 22
0
	void DrawQuads()
	{
		if(g_DrawVertices->size() < 4 * 3)
			return;

		//Create verts to draw triangle
		std::vector<float> vertices;
		for(size_t i = 0; i < g_DrawVertices->size(); i += 12)
		{
			Vector3Df one((*g_DrawVertices)[i], (*g_DrawVertices)[i + 1], (*g_DrawVertices)[i + 2]);
			Vector3Df two((*g_DrawVertices)[i + 3], (*g_DrawVertices)[i + 4], (*g_DrawVertices)[i + 5]);
			Vector3Df three((*g_DrawVertices)[i + 6], (*g_DrawVertices)[i + 7], (*g_DrawVertices)[i + 8]);
			Vector3Df four((*g_DrawVertices)[i + 9], (*g_DrawVertices)[i + 10], (*g_DrawVertices)[i + 11]);

			AddToVector(vertices, one);
			AddToVector(vertices, two);
			AddToVector(vertices, three);
			AddToVector(vertices, one);
			AddToVector(vertices, three);
			AddToVector(vertices, four);
		}

		//Create verts to draw triangle
		std::vector<float> normals;
		for(size_t i = 0; i < g_DrawNormals->size(); i += 12)
		{
			Vector3Df one((*g_DrawNormals)[i], (*g_DrawNormals)[i + 1], (*g_DrawNormals)[i + 2]);
			Vector3Df two((*g_DrawNormals)[i + 3], (*g_DrawNormals)[i + 4], (*g_DrawNormals)[i + 5]);
			Vector3Df three((*g_DrawNormals)[i + 6], (*g_DrawNormals)[i + 7], (*g_DrawNormals)[i + 8]);
			Vector3Df four((*g_DrawNormals)[i + 9], (*g_DrawNormals)[i + 10], (*g_DrawNormals)[i + 11]);

			AddToVector(normals, one);
			AddToVector(normals, two);
			AddToVector(normals, three);
			AddToVector(normals, one);
			AddToVector(normals, three);
			AddToVector(normals, four);
		}

		std::vector<float> texCoord;
		//Create tex coords to draw triangle
		if(g_DrawTextureCoords->size() >= 4 * 2) //4 verts * 2 uv
		{
			for(size_t i = 0; i < g_DrawTextureCoords->size(); i += 8)
			{
				Vector2Df one((*g_DrawTextureCoords)[i], (*g_DrawTextureCoords)[i + 1]);
				Vector2Df two((*g_DrawTextureCoords)[i + 2], (*g_DrawTextureCoords)[i + 3]);
				Vector2Df three((*g_DrawTextureCoords)[i + 4], (*g_DrawTextureCoords)[i + 5]);
				Vector2Df four((*g_DrawTextureCoords)[i + 6], (*g_DrawTextureCoords)[i + 7]);

				AddToVector(texCoord, one);
				AddToVector(texCoord, two);
				AddToVector(texCoord, three);
				AddToVector(texCoord, one);
				AddToVector(texCoord, three);
				AddToVector(texCoord, four);
			}
		}

		DrawTriangles(vertices, texCoord, normals);
	}
Exemplo n.º 23
0
    DPL_NONE,		/* DVI_Z0 */
    SEQ_S,			/* DVI_Z1 through DVI_Z4 */
    sixty_four(DPL_NONE),	/* DVI_FNTNUM0 through DVI_FNTNUM63 */
    SEQ_U,			/* DVI_FNT1 through DVI_FNT4 */
    SEQ_U,			/* DVI_XXX1 through DVI_XXX4 */
    SEQ_U,			/* DVI_FNTDEF1 through DVI_FNTDEF4 */
    DPL_NONE,		/* DVI_PRE */
    DPL_NONE,		/* DVI_POST */
    DPL_NONE,		/* DVI_POSTPOST */
    six(DPL_NONE)		/* 250 through 255 */
};

char dvi_dt[256] = {
    one_twenty_eight(DT_CHAR),
    /* characters 0 through 127 */
    four(DT_SET),		/* DVI_SET1 through DVI_SET4 */
    DT_SETRULE,		/* DVI_SETRULE */
    four(DT_PUT),		/* DVI_PUT1 through DVI_PUT4 */
    DT_PUTRULE,		/* DVI_PUTRULE */
    DT_NOP,			/* DVI_NOP */
    DT_BOP,			/* DVI_BOP */
    DT_EOP,			/* DVI_EOP */
    DT_PUSH,		/* DVI_PUSH */
    DT_POP,			/* DVI_POP */
    four(DT_RIGHT),		/* DVI_RIGHT1 through DVI_RIGHT4 */
    DT_W0,			/* DVI_W0 */
    four(DT_W),		/* DVI_W1 through DVI_W4 */
    DT_X0,			/* DVI_X0 */
    four(DT_X),		/* DVI_X1 through DVI_X4 */
    four(DT_DOWN),		/* DVI_DOWN1 through DVI_DOWN4 */
    DT_Y0,			/* DVI_Y0 */
void * cbFunc(gpointer data)
{
	Shared *shared = static_cast<Shared*>(data);

	if(!shared)
	{
		throw std::runtime_error("Could not cast shared object.");
	}

	vector<DictionaryList<string> > insertList;

	while(1)
	{
		DBObject* obj = shared->queue.pop();

		if( obj->quit )
		{
			delete obj;
			break;
		}

		DictionaryList<string> dict;

		NameValuePair<string> one("key", obj->key);
		NameValuePair<string> two("value", obj->value);
		NameValuePair<string> three("source", obj->source);
		NameValuePair<string> four("time", boost::lexical_cast<string>(obj->time));
		NameValuePair<string> five("sequence", boost::lexical_cast<string>(obj->sequence));

		dict.push_back(one);
		dict.push_back(two);
		dict.push_back(three);
		dict.push_back(four);
		dict.push_back(five);

		insertList.push_back(dict);

		if(insertList.size() > bufferLength)
		{
			shared->db->exec("BEGIN IMMEDIATE TRANSACTION");
			for(int i=0; i< insertList.size(); i++)
			{
				DictionaryList<string> d = insertList[i];
				shared->db->insert(d);
			}
			shared->db->exec("END TRANSACTION");
			insertList.clear();
		}
		delete obj;
	}

	/// final flush of whatever is still in the queue:

	shared->db->exec("BEGIN IMMEDIATE TRANSACTION");
	for(int i=0; i< insertList.size(); i++)
	{
		DictionaryList<string> d = insertList[i];
		shared->db->insert(d);
	}
	shared->db->exec("END TRANSACTION");

	return NULL;
}
Exemplo n.º 25
0
static void
demoUnicodeStringStorage() {
    // These sample code lines illustrate how to use UnicodeString, and the
    // comments tell what happens internally. There are no APIs to observe
    // most of this programmatically, except for stepping into the code
    // with a debugger.
    // This is by design to hide such details from the user.
    int32_t i;

    printf("\n* demoUnicodeStringStorage() ------- ***\n\n");

    // * UnicodeString with internally stored contents
    // instantiate a UnicodeString from a single code point
    // the few (2) UChars will be stored in the object itself
    UnicodeString one((UChar32)0x24001);
    // this copies the few UChars into the "two" object
    UnicodeString two=one;
    printf("length of short string copy: %d\n", two.length());
    // set "one" to contain the 3 UChars from readonly
    // this setTo() variant copies the characters
    one.setTo(readonly, UPRV_LENGTHOF(readonly));

    // * UnicodeString with allocated contents
    // build a longer string that will not fit into the object's buffer
    one+=UnicodeString(writeable, UPRV_LENGTHOF(writeable));
    one+=one;
    one+=one;
    printf("length of longer string: %d\n", one.length());
    // copying will use the same allocated buffer and increment the reference
    // counter
    two=one;
    printf("length of longer string copy: %d\n", two.length());

    // * UnicodeString using readonly-alias to a const UChar array
    // construct a string that aliases a readonly buffer
    UnicodeString three(FALSE, readonly, UPRV_LENGTHOF(readonly));
    printUnicodeString("readonly-alias string: ", three);
    // copy-on-write: any modification to the string results in
    // a copy to either the internal buffer or to a newly allocated one
    three.setCharAt(1, 0x39);
    printUnicodeString("readonly-aliasing string after modification: ", three);
    // the aliased array is not modified
    for(i=0; i<three.length(); ++i) {
        printf("readonly buffer[%d] after modifying its string: 0x%lx\n",
               i, readonly[i]);
    }
    // setTo() readonly alias
    one.setTo(FALSE, writeable, UPRV_LENGTHOF(writeable));
    // copying the readonly-alias object with fastCopyFrom() (new in ICU 2.4)
    // will readonly-alias the same buffer
    two.fastCopyFrom(one);
    printUnicodeString("fastCopyFrom(readonly alias of \"writeable\" array): ", two);
    printf("verify that a fastCopyFrom(readonly alias) uses the same buffer pointer: %d (should be 1)\n",
        one.getBuffer()==two.getBuffer());
    // a normal assignment will clone the contents (new in ICU 2.4)
    two=one;
    printf("verify that a regular copy of a readonly alias uses a different buffer pointer: %d (should be 0)\n",
        one.getBuffer()==two.getBuffer());

    // * UnicodeString using writeable-alias to a non-const UChar array
    UnicodeString four(writeable, UPRV_LENGTHOF(writeable), UPRV_LENGTHOF(writeable));
    printUnicodeString("writeable-alias string: ", four);
    // a modification writes through to the buffer
    four.setCharAt(1, 0x39);
    for(i=0; i<four.length(); ++i) {
        printf("writeable-alias backing buffer[%d]=0x%lx "
               "after modification\n", i, writeable[i]);
    }
    // a copy will not alias any more;
    // instead, it will get a copy of the contents into allocated memory
    two=four;
    two.setCharAt(1, 0x21);
    for(i=0; i<two.length(); ++i) {
        printf("writeable-alias backing buffer[%d]=0x%lx after "
               "modification of string copy\n", i, writeable[i]);
    }
    // setTo() writeable alias, capacity==length
    one.setTo(writeable, UPRV_LENGTHOF(writeable), UPRV_LENGTHOF(writeable));
    // grow the string - it will not fit into the backing buffer any more
    // and will get copied before modification
    one.append((UChar)0x40);
    // shrink it back so it would fit
    one.truncate(one.length()-1);
    // we still operate on the copy
    one.setCharAt(1, 0x25);
    printf("string after growing too much and then shrinking[1]=0x%lx\n"
           "                          backing store for this[1]=0x%lx\n",
           one.charAt(1), writeable[1]);
    // if we need it in the original buffer, then extract() to it
    // extract() does not do anything if the string aliases that same buffer
    // i=min(one.length(), length of array)
    if(one.length()<UPRV_LENGTHOF(writeable)) {
        i=one.length();
    } else {
        i=UPRV_LENGTHOF(writeable);
    }
    one.extract(0, i, writeable);
    for(i=0; i<UPRV_LENGTHOF(writeable); ++i) {
        printf("writeable-alias backing buffer[%d]=0x%lx after re-extract\n",
               i, writeable[i]);
    }
}
Exemplo n.º 26
0
int main(void) {
    
    i=EEPROM_read(Address); // de vazut adresele cum sunt puse!
    
    //timer_1(1000); // set value in ms
    
    DDRD = 0xf8;
    DDRB = 0xff;
    
    // set external interrupt on digital PIN 2
    cli();
    
    PORTD |= (1 << PORTD2);    // turn On the Pull-up
    
    EICRA |= (1 << ISC00);    //
    EICRA |= (1 << ISC01);    // set INT0 to trigger on rising edge
    
    EIMSK |= (1 << INT0);     // Turns on INT0 - external interrupt mask register
    
    sei();
    
    clear(2);
    clear(1);
    
    while(1){
        
            if(i<100 && i>=1){
    
                nr_2=i%10;
                nr_1=i/10;
                
                if(nr_1>=1){
                    if(nr_1==0){
                        zero(1);
                    }
                    if(nr_1==1){
                        one(1);
                    }
                    if(nr_1==2){
                        two(1);
                    }
                    if(nr_1==3){
                        three(1);
                    }
                    if(nr_1==4){
                        four(1);
                    }
                    if(nr_1==5){
                        five(1);
                    }
                    if(nr_1==6){
                        six(1);
                    }
                    if(nr_1==7){
                        seven(1);
                    }
                    if(nr_1==8){
                        eight(1);
                    }
                    if(nr_1==9){
                        nine(1);
                    }
                }
                
                if(nr_2==0){
                    zero(2);
                }
                if(nr_2==1){
                    one(2);
                }
                if(nr_2==2){
                    two(2);
                }
                if(nr_2==3){
                    three(2);
                }
                if(nr_2==4){
                    four(2);
                }
                if(nr_2==5){
                    five(2);
                }
                if(nr_2==6){
                    six(2);
                }
                if(nr_2==7){
                    seven(2);
                }
                if(nr_2==8){
                    eight(2);
                }
                if(nr_2==9){
                    nine(2);
                }
                
            }
            else{
                i=0;
                clear(2);
                clear(1);
                
            }
        
            EEPROM_write(Address, i);
        
    }
    
	return 0;     
}
Exemplo n.º 27
0
int main()
{
	/* part1.c  */
	printf("== one() ==\n");
	one(3, 4);
	one(10, 10);


	printf("== two() ==\n");
	two(50);
	two(100);


	printf("== three() ==\n");
	three();


	printf("== four() ==\n");
	four(0.5);
	four(1.5);


	printf("== five() ==\n");
	five(3, 3);
	five(3, 4);


	/* part2.c */
	printf("== six() ==\n");
	float *p_six;
	int i4 = 4, i432 = 432;

	p_six = six(&i4);
	printf("%d == %f\n", i4, *p_six);
	free(p_six);

	p_six = six(&i432);
	printf("%d == %f\n", i432, *p_six);
	free(p_six);


	printf("== seven() ==\n");
	seven(2, 12);
	seven(14, 20);


	printf("== eight() ==\n");
	eight();


	printf("== nine() ==\n");
	nine();


	printf("== ten() ==\n");
	int i_ten = 100;
	ten(&i_ten);
	printf("%d == 0?\n", i_ten);


	/* part3.c */
	printf("== eleven() ==\n");
	eleven();


	printf("== twelve() ==\n");
	twelve();


	printf("== thirteen() ==\n");
	thirteen();


	printf("== fourteen() ==\n");
	fourteen("red");
	fourteen("orange");
	fourteen("blue");
	fourteen("green");


	printf("== fifteen() ==\n");
	fifteen(1);
	fifteen(2);
	fifteen(3);


	/* part4.c */
	printf("== sixteen() ==\n");
	char *str = sixteen();
	printf("%s\n", str);
	free(str);


	printf("== seventeen() ==\n");
	seventeen(35);
	seventeen(20);


	printf("== eighteen() ==\n");
	eighteen(3);
	eighteen(5);


	printf("== clear_bits() ==\n");
	long int result;
	
	result = clear_bits(0xFF, 0x55);
	printf("%ld\n", result);

	result = clear_bits(0x00, 0xF0);
	printf("%ld\n", result);

	result = clear_bits(0xAB, 0x00);
	printf("%ld\n", result);

	result = clear_bits(0xCA, 0xFE);
	printf("%ld\n", result);

	result = clear_bits(0x14, 0x00);
	printf("%ld\n", result);

	result = clear_bits(0xBB, 0xBB);
	printf("%ld\n", result);


	return 0;
}
Exemplo n.º 28
0
void CriticalCurves::setParameters(double radius_1, double radius_2, Arrangements_2 insets_1, Arrangements_2 insets_2)
{
    Arrangement_2_iterator inset_1 = insets_1.begin();
    Arrangement_2_iterator inset_2 = insets_2.begin();

    while (inset_1 != insets_1.end() && inset_2 != insets_2.end())
    {
        Arrangement_2 arrangement;

        // Add the curves of the inset.
        for (Edge_iterator edge = inset_1->edges_begin(); edge != inset_1->edges_end(); ++edge)
        {
            insert(arrangement, edge->curve());
        }

        // Add the critical curves of type I.
        for (Edge_iterator edge = inset_2->edges_begin(); edge != inset_2->edges_end(); ++edge)
        {
            if (CGAL::COLLINEAR == edge->curve().orientation())
            {
                // Displaced a segment.
                Nt_traits nt_traits;
                Algebraic_ft factor = nt_traits.convert(Rational(radius_1) + Rational(radius_2));
                Conic_point_2 source = edge->curve().source();
                Conic_point_2 target = edge->curve().target();
                Algebraic_ft delta_x = target.x() - source.x();
                Algebraic_ft delta_y = target.y() - source.y();
                Algebraic_ft length = nt_traits.sqrt(delta_x * delta_x + delta_y * delta_y);
                Algebraic_ft translation_x = factor * delta_y / length;
                Algebraic_ft translation_y = - factor * delta_x / length;
                Conic_point_2 point_1(source.x() + translation_x, source.y() + translation_y);
                Conic_point_2 point_2(target.x() + translation_x, target.y() + translation_y);
                Algebraic_ft a = - delta_y;
                Algebraic_ft b = delta_x;
                Algebraic_ft c = factor * length - (source.y() * target.x() - source.x() * target.y());
                X_monotone_curve_2 x_monotone_curve(a, b, c, point_1, point_2);
                insert(arrangement, x_monotone_curve);
            }
            else
            {
                // Displaces an arc.
                Rational two(2);
                Rational four(4);

                Rational r = edge->curve().r();
                Rational s = edge->curve().s();
                Rational t = edge->curve().t();
                Rational u = edge->curve().u();
                Rational v = edge->curve().v();
                Rational w = edge->curve().w();

                Nt_traits nt_traits;
                Rational x_center = - u / (two * r);
                Rational y_center = - v / (two * r);
                Rat_point_2 rat_center(x_center, y_center);
                Conic_point_2 center(nt_traits.convert(x_center), nt_traits.convert(y_center));

                Rational radius = Rational(radius_1) + two * Rational(radius_2);

                Algebraic_ft coefficient = nt_traits.convert(radius / Rational(radius_2));

                Conic_point_2 source_1 = edge->curve().source();
                Algebraic_ft x_source_2 = center.x() + coefficient * (source_1.x() - center.x());
                Algebraic_ft y_source_2 = center.y() + coefficient * (source_1.y() - center.y());
                Conic_point_2 source_2(x_source_2, y_source_2);

                Conic_point_2 target_1 = edge->curve().target();
                Algebraic_ft x_target_2 = center.x() + coefficient * (target_1.x() - center.x());
                Algebraic_ft y_target_2 = center.y() + coefficient * (target_1.y() - center.y());
                Conic_point_2 target_2(x_target_2, y_target_2);

                Rat_circle_2 circle(rat_center, radius * radius);

                Conic_arc_2 conic_arc(circle, CGAL::COUNTERCLOCKWISE, source_2, target_2);

                insert(arrangement, conic_arc);
            }
        }

        // Add the critical curves of type II.
        for (Edge_iterator edge = inset_2->edges_begin(); edge != inset_2->edges_end(); ++edge)
        {
            double x = CGAL::to_double(edge->curve().source().x());
            double y = CGAL::to_double(edge->curve().source().y());
            double radius = radius_1 + radius_2;
            Rat_point_2 center(x, y);
            Rat_circle_2 circle(center, radius * radius);
            Conic_arc_2 conic_arc(circle);
            insert(arrangement, conic_arc);
        }

        // Remove the curves which are not include in the inset.
        Objects objects;
        Face_handle face;
        for (Edge_iterator edge = arrangement.edges_begin(); edge != arrangement.edges_end(); ++edge)
        {
            CGAL::zone(*inset_1, edge->curve(), std::back_inserter(objects));
            for (Object_iterator object = objects.begin(); object != objects.end(); ++object)
            {
                if (assign(face, *object))
                {
                    if (face->is_unbounded())
                    {
                        remove_edge(arrangement, edge);
                        break;
                    }
                }
            }
            objects.clear();
        }

        // Print essential information on the standard input.
        std::cout << "Arrangement:" << std::endl;
        std::cout << "  Number of vertices: " << arrangement.number_of_vertices() << std::endl;
        std::cout << "  Number of edges   : " << arrangement.number_of_edges() << std::endl;
        std::cout << "  Number of face    : " << arrangement.number_of_faces() << std::endl;

        this->critical_curves.push_back(arrangement);

        ++inset_1;
        ++inset_2;
    }

    // Commit changes.
    emit(criticalCurvesChanged());
    return;
}
Exemplo n.º 29
0
Arquivo: vf.cpp Projeto: KDE/okular
void TeXFontDefinition::read_VF_index()
{
#ifdef DEBUG_FONTS
  qCDebug(OkularDviDebug) << "font::read_VF_index()";
#endif
  FILE *VF_file = file;
  unsigned char        cmnd;
  // available space for macros
  unsigned char        *avail, *availend;

  flags      |= FONT_VIRTUAL;
  set_char_p  = &dviRenderer::set_vf_char;
#ifdef DEBUG_FONTS
  qCDebug(OkularDviDebug) << "TeXFontDefinition::read_VF_index: reading VF pixel file " << filename;
#endif
  // Read preamble.
  fseek(VF_file, (long) one(VF_file), 1);        /* skip comment */
  quint32 const file_checksum = four(VF_file);

  if (file_checksum && checksum && file_checksum != checksum)
    qCCritical(OkularDviDebug) << "Checksum mismatch dvi = " << checksum << "u, vf = " << file_checksum <<
      "u) in font file" << filename << endl;
  (void) four(VF_file);                /* skip design size */

  // Read the fonts.
  first_font = NULL;
  while ((cmnd = one(VF_file)) >= FNTDEF1 && cmnd <= FNTDEF4) {
    int   TeXnumber = num(VF_file, (int) cmnd - FNTDEF1 + 1);
    quint32 checksum  = four(VF_file);
    quint32 scale     = four(VF_file);
    quint32 design    = four(VF_file);
    Q_UNUSED(design);
    quint16 len       = one(VF_file) + one(VF_file); /* sequence point in the middle */
    char *fontname  = new char[len + 1];
    fread(fontname, sizeof(char), len, VF_file);
    fontname[len] = '\0';

#ifdef DEBUG_FONTS
    qCDebug(OkularDviDebug) << "Virtual font defines subfont \"" << fontname << "\" scale=" << scale << " design=" << design;
#endif

    // According to Knuth's documentation found in the web source code
    // of the "vftovp" program (which seems to be the standard
    // definition of virtual fonts), the "scale" is a fixed point
    // number which describes extra enlargement that the virtual font
    // imposes. One obtains the enlargement by dividing 2^20.
    double enlargement_factor = double(scale)/(1<<20) * enlargement;

    //    TeXFontDefinition *newfontp = font_pool->appendx(fontname, checksum, (quint32)(scaled_size_in_DVI_units*enlargement_factor), enlargement_factor);
    TeXFontDefinition *newfontp = font_pool->appendx(QString::fromLocal8Bit(fontname), checksum, (quint32)((double(scale)/(1<<20))*scaled_size_in_DVI_units), enlargement_factor);

    // Insert font in dictionary and make sure the dictionary is big
    // enough.
    if (vf_table.capacity()-2 <= vf_table.count())
      // Not quite optimal. The size of the dictionary should be a
      // prime. I don't care.
      vf_table.reserve(vf_table.capacity()*2);
    vf_table.insert(TeXnumber, newfontp);

    if (first_font == NULL)
      first_font = newfontp;
  }

  // Prepare macro array.
  macrotable = new macro[max_num_of_chars_in_font];
  if (macrotable == 0) {
    qCCritical(OkularDviDebug) << "Could not allocate memory for a macro table.";
    exit(0);
  }

  // Read macros.
  avail = availend = NULL;
  for (; cmnd <= LONG_CHAR; cmnd = one(VF_file)) {
    macro *m;
    int len;
    unsigned long cc;
    long width;

    if (cmnd == LONG_CHAR) {        /* long form packet */
      len = four(VF_file);
      cc = four(VF_file);
      width = four(VF_file);
      if (cc >= 256) {
        qCCritical(OkularDviDebug) << "Virtual character" << cc << "in font"
                  << fontname << "ignored.";
        fseek(VF_file, (long) len, 1);
        continue;
      }
    } else {        /* short form packet */
      len = cmnd;
      cc = one(VF_file);
      width = num(VF_file, 3);
    }
    m = &macrotable[cc];

    m->dvi_advance_in_units_of_design_size_by_2e20 = width;
    if (len > 0) {
      if (len <= availend - avail) {
        m->pos = avail;
        avail += len;
      } else {
        m->free_me = true;
        if (len <= VF_PARM_1) {
          m->pos = avail = new unsigned char [VF_PARM_2];
          availend = avail + VF_PARM_2;
          avail += len;
        } else
          m->pos = new unsigned char[len];
      }
      fread((char *) m->pos, 1, len, VF_file);
      m->end = m->pos + len;
    }
  }
  if (cmnd != POST)
    oops(i18n("Wrong command byte found in VF macro list: %1", cmnd));

  fclose (VF_file);
  file = NULL;
}