Ejemplo n.º 1
0
int main(){
   window w( 128, 64, 2 );
   filled_rectangle square(w, 20, 20, 60, 60);
   filled_rectangle square2(w, 10, 10, 80, 15);
   square2.draw();
   square.draw();
   return 0;
}
Ejemplo n.º 2
0
/* Main program: Using the various functions */
int main (void) {
   square1();    /* Calling the square1 function */
   square2(7);   /* Calling the square2 function using 7 as actual
		    parameter corresponding to the formal parameter i */
   printf("The value of square3() is %d\n", square3()); /* Ysing the square3
							   function */
   printf("The value of square4(5) is %d\n", square4(5)); /* Using the square4
		 function with 5 as actual parameter corresponding to i */
   printf("The value of area(3,7) is %d\n", area(3,7)); /* Using the area
                 function with 3, 7 as actual parameters corresponding 
		 to b, h respectively */
}
Ejemplo n.º 3
0
int main(int argc, char const *argv[])
{
	square1();
	square2(7);

    printf("The value of square3() is %d\n", square3());

    printf("The value of square4(5) is %d\n", square4(5));

    printf("The value of area(3, 7) is %d\n", area(3, 7));

	return 0;
}
Ejemplo n.º 4
0
TEST_F(PolygonMergerTest, TwoSquaresTest){
    std::vector<int> square1Points = {0,1,2,3};
    std::vector<int> square2Points = {1,5,6,2};

    std::vector<int> expected = {2,3,0,1,5,6};

    Polygon square1 (square1Points, points);
    Polygon square2 (square2Points, points);

    SimplePolygonMerger merger;
    Polygon p = merger.mergePolygons(square1, square2, points);

    EXPECT_EQ(p, Polygon(expected, points));
}
Ejemplo n.º 5
0
int main()
{
   Rectangle square1( 1,  100, 100, 3, 4 );
   printRectange( square1 );

   Rectangle square2( 2,  50, 50, 0, 4 );
   printRectange( square2 );

   Rectangle square3( square1 );
   printRectange( square3 );

   square1 = square2;
   printRectange( square1 );

   Rectangle* pFoo = Foo();
   printRectange( *pFoo );

   return 0;
}
Ejemplo n.º 6
0
static void fill_audio(void *udata, Uint8 *stream, int len)
{
    sample_t *samples = (sample_t*)stream;
	audio_t *audio = (audio_t*)udata;
    int num_samples = len / (sizeof(sample_t));
    for(int i = 0; i < num_samples; i++)
    {
        float t = audio->buffer_pos / (float)FREQUENCY;
        int16_t val_l = 0;
        int16_t val_r = 0;
        uint8_t channels[4];
#if 1
        if(audio->sq1.en)
        {
            channels[0] = square1(t, audio);
        }

        if(audio->sq2.en)
        {
            channels[1] = square2(t, audio);
        }

        if(audio->wave.en && audio->wave.power)
        {
            channels[2] = wave(t, audio);
        }
#endif

#if 1
		if (audio->noise.en)
		{
			channels[3] = noise(t, audio);
		}
#endif

        for(int i = 0; i < 4; i++)
        {
            int16_t v = DAC(channels[i]) / 4;
            if(BIT_N(audio->control.r_en, i))
            {
                val_r += v;
            }
            if(BIT_N(audio->control.l_en, i))
            {
                val_l += v;
            }
        }

		samples[i] = (sample_t) { .left = val_l / 4, .right = val_r / 4 };
		audio->buffer_pos = (audio->buffer_pos + 1) % FREQUENCY;
    }
}

static void init_wave_table(audio_t *audio)
{
	const uint8_t wave_default_table[32] =
	{
		0x4, 0x8, 0x0, 0x4, 0x3, 0x4,0xA, 0xA,
		0xD, 0x2, 0x8, 0x7, 0x2, 0x9,0xC, 0x3,
		0x0, 0x6, 0x9, 0x5, 0x9, 0x5,0x0, 0xB,
		0x4, 0x3, 0x8, 0xB, 0xE, 0x2,0xA, 0xD,
	};
	memcpy(audio->wave_table, wave_default_table, sizeof(audio->wave_table));
}

audio_t *audio_init(cpu_state_t *state)
{
	audio_t *out = CALLOC(1, sizeof(audio_t));
	out->state   = state;

	init_wave_table(out);

#if AUDIO
	SDL_AudioSpec wanted;
	/* Set the audio format */
	wanted.freq     = FREQUENCY;
	wanted.format   = AUDIO_S16;
	wanted.channels = NUM_CHANNELS;
	wanted.samples  = NUM_SAMPLES;
	wanted.callback = fill_audio;
	wanted.userdata = out;

	/* Open the audio device, forcing the desired format */
	if ( SDL_OpenAudio(&wanted, NULL) < 0 )
	{
        log_error("Couldn't open audio: %s\n", SDL_GetError());
	}
	SDL_PauseAudio(0);
#endif
	return out;
}
Ejemplo n.º 7
0
// double square2(float value) { return (double)value * value; }
double test3()
{
    double sq = square2(2.0);
    return sq;
}
Ejemplo n.º 8
0
void TestStelSphericalGeometry::testContains()
{
	Vec3d p0(1,0,0);
	Vec3d p1(1,1,1);
	p1.normalize();

	Vec3d v0;
	Vec3d v1;
	Vec3d v2;
	Vec3d v3;

	// Triangle polygons
	QVERIFY2(triangle.contains(p1), "Triangle contains point failure");
	Vec3d vt(-1, -1, -1);
	vt.normalize();
	QVERIFY2(!triangle.contains(vt), "Triangle not contains point failure");

	foreach(const SphericalCap& h, triangle.getBoundingSphericalCaps())
	{
		QVERIFY(h.contains(p1));
	}

	// polygons-point intersect
	double deg5 = 5.*M_PI/180.;
	double deg2 = 2.*M_PI/180.;
	StelUtils::spheToRect(-deg5, -deg5, v3);
	StelUtils::spheToRect(+deg5, -deg5, v2);
	StelUtils::spheToRect(+deg5, +deg5, v1);
	StelUtils::spheToRect(-deg5, +deg5, v0);
	//qDebug() << v0.toString() << v1.toString() << v2.toString() << v3.toString();
	SphericalConvexPolygon square1(v0, v1, v2, v3);
	QVERIFY(square1.checkValid());
	QVERIFY2(square1.contains(p0), "Square contains point failure");
	QVERIFY2(!square1.contains(p1), "Square not contains point failure");

	// polygons-polygons intersect
	StelUtils::spheToRect(-deg2, -deg2, v3);
	StelUtils::spheToRect(+deg2, -deg2, v2);
	StelUtils::spheToRect(+deg2, +deg2, v1);
	StelUtils::spheToRect(-deg2, +deg2, v0);
	SphericalConvexPolygon square2(v0, v1, v2, v3);
	QVERIFY(square2.checkValid());
	QVERIFY2(square1.contains(square2), "Square contains square failure");
	QVERIFY2(!square2.contains(square1), "Square not contains square failure");
	QVERIFY2(square1.intersects(square2), "Square intersect square failure");
	QVERIFY2(square2.intersects(square1), "Square intersect square failure");

	// Check when the polygons are far appart
	QVERIFY(!square1.intersects(opositeSquare));
	QVERIFY(!square2.intersects(opositeSquare));
	QVERIFY(!holySquare.intersects(opositeSquare));
	QVERIFY(!bigSquare.intersects(opositeSquare));
	QVERIFY(opositeSquare.intersects(opositeSquare));

	// Test the tricky case where 2 polygons intersect without having point within each other
	StelUtils::spheToRect(-deg5, -deg2, v3);
	StelUtils::spheToRect(+deg5, -deg2, v2);
	StelUtils::spheToRect(+deg5, +deg2, v1);
	StelUtils::spheToRect(-deg5, +deg2, v0);
	SphericalConvexPolygon squareHoriz(v0, v1, v2, v3);
	QVERIFY(squareHoriz.checkValid());

	StelUtils::spheToRect(-deg2, -deg5, v3);
	StelUtils::spheToRect(+deg2, -deg5, v2);
	StelUtils::spheToRect(+deg2, +deg5, v1);
	StelUtils::spheToRect(-deg2, +deg5, v0);
	SphericalConvexPolygon squareVerti(v0, v1, v2, v3);
	QVERIFY(squareVerti.checkValid());
	QVERIFY2(!squareHoriz.contains(squareVerti), "Special intersect contains failure");
	QVERIFY2(!squareVerti.contains(squareHoriz), "Special intersect contains failure");
	QVERIFY2(squareHoriz.intersects(squareVerti), "Special intersect failure");
	QVERIFY2(squareVerti.intersects(squareHoriz), "Special intersect failure");
}