Example #1
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, AssignmentOperator)
{
    FloatArray a0;

    FloatArray a1;
    a1.resize(2);
    a1[0] = 10;
    a1[1] = 11;

    {
        FloatArray a;
        a = a0;

        ASSERT_EQ(0u, a.size());
    }

    {
        FloatArray a;
        a = a1;

        ASSERT_EQ(2u, a.size());
        ASSERT_EQ(10, a[0]);
        ASSERT_EQ(11, a[1]);
    }
}
Example #2
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, SetSizeZero)
{
    FloatArray a;
    a.reserve(3);
    a.add(1.0f);
    a.add(3.3f);
    a.add(5.5f);

    float* before = a.ptr();
    a.setSizeZero();
    float* after = a.ptr();

    ASSERT_EQ(before, after);
    ASSERT_EQ(0u, a.size());
    ASSERT_TRUE(3 <= a.capacity());

    a.add(1.1f);
    a.add(3.4f);
    a.add(5.6f);

    ASSERT_EQ(3u, a.size());
    ASSERT_EQ(1.1f, a[0]);
    ASSERT_EQ(3.4f, a[1]);
    ASSERT_EQ(5.6f, a[2]);
}
Example #3
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, SqueezeEmptyArray)
{
    FloatArray a;
    a.reserve(5);

    ASSERT_EQ(0, a.size());
    ASSERT_TRUE(5 <= a.capacity());

    a.squeeze();
    ASSERT_EQ(0, a.size());
    ASSERT_EQ(0, a.capacity());
}
Example #4
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
void UniformFloat::setArray(const FloatArray& values)
{
    CVF_ASSERT(values.size() > 0);

    m_type = FLOAT;
    m_data = values;
}
Example #5
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, ReserveAndAdd)
{
    FloatArray a;
    a.reserve(5);
    a.add(1.0f);
    a.add(3.3f);
    a.add(5.5f);

    ASSERT_EQ(3u, a.size());
    ASSERT_TRUE(a.capacity() >= 5);
    ASSERT_EQ(1.0f, a[0]);
    ASSERT_EQ(3.3f, a[1]);
    ASSERT_EQ(5.5f, a[2]);

    // To test reuse of buffer
    float* before = a.ptr();

    a.reserve(3);
    ASSERT_TRUE(a.capacity() >= 5);

    float* after = a.ptr();

    // Check that no realloc has been done
    ASSERT_EQ(before, after);
    ASSERT_TRUE(a.capacity() >= 5);
}
Example #6
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, Squeeze)
{
    FloatArray a;
    a.reserve(5);
    a.add(1.0f);
    a.add(3.3f);
    a.add(5.5f);

    ASSERT_EQ(3u, a.size());
    ASSERT_TRUE(5 <= a.capacity());

    a.squeeze();
    ASSERT_EQ(3u, a.size());
    ASSERT_EQ(3u, a.capacity());
    ASSERT_EQ(1.0f, a[0]);
    ASSERT_EQ(3.3f, a[1]);
    ASSERT_EQ(5.5f, a[2]);
}
Example #7
0
CLabel::TEXTPOSINFO CLabel::GetTextPosition(const StringArray& lines) const
{
	TEXTPOSINFO result;

	FloatArray lineWidths = GetLineWidths(lines);
	result.linePosX.reserve(lineWidths.size());
	for(unsigned int i = 0; i < lineWidths.size(); i++)
	{
		float posX = 0;
		float lineWidth = lineWidths[i];
		switch(m_horizontalAlignment)
		{
			case HORIZONTAL_ALIGNMENT_LEFT:
				posX = 0;
				break;
			case HORIZONTAL_ALIGNMENT_RIGHT:
				posX = m_size.x - lineWidth;
				break;
			case HORIZONTAL_ALIGNMENT_CENTER:
				posX = static_cast<float>(static_cast<int>(m_size.x - lineWidth) / 2);
				break;
		}
		result.linePosX.push_back(posX);
	}

	float textHeight = GetTextHeight(lines);
	float posY = 0;
	switch(m_verticalAlignment)
	{
		case VERTICAL_ALIGNMENT_TOP:
			posY = 0;
			break;
		case VERTICAL_ALIGNMENT_BOTTOM:
			posY = m_size.y - textHeight;
			break;
		case VERTICAL_ALIGNMENT_CENTER:
			posY = static_cast<float>(static_cast<int>(m_size.y - textHeight) / 2);
			break;
	}
	result.posY = posY;

	return result;
}
Example #8
0
TEST(ArrayTest, testConstruction)
{

	// fundamental type
	typedef Poco::Array<float,6> FloatArray;
	FloatArray a = { { 42.f } };

	for (unsigned i=1; i<a.size(); ++i) {
		a[i] = a[i-1]+1.f;
	}

	// copy constructor and assignment operator
	FloatArray b(a);
	FloatArray c;
	c = a;
	EXPECT_TRUE (a==b && a==c);

	typedef Poco::Array<double,6> DArray;
	typedef Poco::Array<int,6> IArray;
	IArray ia = {{1, 2, 3, 4, 5, 6 }};
	DArray da;
	da = ia;
	da.assign(42);

	// user-defined type
	typedef Poco::Array<Element,10> ElementArray;
	ElementArray g;

	for (unsigned i=0; i<g.size(); ++i) {
		g[i]._data = i;
	}

	for (unsigned i=0; i<g.size(); ++i) {
		EXPECT_TRUE(g[i]._data == i);
	}


}
Example #9
0
//--------------------------------------------------------------------------------------------------
/// 
//--------------------------------------------------------------------------------------------------
TEST(ArrayTest, ReserveGrow)
{
    FloatArray a;
    a.resize(3);
    a.set(0, 1.0f);
    a.set(1, 3.3f);
    a.set(2, 5.5f);

    float* before = a.ptr();
    a.reserve(8);
    float* after = a.ptr();
    a.add(2.2f);
    a.add(2.5f);

    ASSERT_NE(before, after);

    ASSERT_EQ(5u, a.size());
    ASSERT_TRUE(a.capacity() >= 8);
    ASSERT_EQ(1.0f, a[0]);
    ASSERT_EQ(3.3f, a[1]);
    ASSERT_EQ(5.5f, a[2]);
    ASSERT_EQ(2.2f, a[3]);
    ASSERT_EQ(2.5f, a[4]);
}
Example #10
0
void DoAnim()
{
    static double time = 0.0; //Total time running.
    static double artTime = 0.0; //Total time with the current art.

    static DWORD lastTime = 0; //Time of last call.
    const double elapsed = double(GetTickCount() - lastTime) / 1000.0;

    if (lastTime)
    {
        lastTime = GetTickCount();
    }
    else
    {
        lastTime = GetTickCount();
        return;
    }

    time += elapsed;
    artTime += elapsed;

    //If we need new art, get it.
    static CKnot::AutoArt threads;
    static Arrays arrays;
    static FloatArray grid;


    if (!threads.get() || artTime > ResetTime)
    {
        CKnot::StrokeList sl = CreateSquareStrokes();
        sl = RemoveStrokes(sl);

        threads = CKnot::CreateThread(sl);
        artTime = 0.0;

        grid.clear();
        grid.reserve(sl.size() * 10);
        for (CKnot::StrokeList::const_iterator it = sl.begin(); it != sl.end(); ++it)
        {
            grid.push_back(it->a.x);
            grid.push_back(it->a.y);
            grid.push_back(it->type == CKnot::Cross ? 1.0 : 0.0);
            grid.push_back(it->type == CKnot::Glance ? 1.0 : 0.0);
            grid.push_back(it->type == CKnot::Bounce ? 1.0 : 0.0);

            grid.push_back(it->b.x);
            grid.push_back(it->b.y);
            grid.push_back(it->type == CKnot::Cross ? 1.0 : 0.0);
            grid.push_back(it->type == CKnot::Glance ? 1.0 : 0.0);
            grid.push_back(it->type == CKnot::Bounce ? 1.0 : 0.0);
        }

        for (size_t i = 0; i < arrays.size(); ++i)
            delete arrays[i];
        arrays.clear();

        const size_t threadCount = threads->GetThreadCount();

        for (size_t i = 0; i < threadCount; ++i)
        {
            const CKnot::Art::Thread* thread = threads->GetThread(i);
            const CKnot::Art::Z* z = threads->GetZ(i);

            const size_t segsPerKnot = 25;
            const size_t kc = thread->GetKnotCount();

            FloatArray* quads = new FloatArray;
            arrays.push_back(quads);


            const size_t target = kc * segsPerKnot;
            const size_t memSize = 12 * (target + 1);
            quads->reserve(memSize);

            const float scr = double(rand()) / RAND_MAX / 2;
            const float ecr = double(rand()) / RAND_MAX / 2 + .5;
            const float scg = double(rand()) / RAND_MAX / 2;
            const float ecg = double(rand()) / RAND_MAX / 2 + .5;
            const float scb = double(rand()) / RAND_MAX / 2;
            const float ecb = double(rand()) / RAND_MAX / 2 + .5;

            for (size_t i = 0; i <= target; ++i)
            {
                const double s = double(i) / double(target);
                const double t = s;

                const CKnot::vec2 cur = thread->Y(t);
                const CKnot::vec2 dcur = thread->Y(t + .00001);
                const CKnot::vec2 diff = dcur - cur;

                CKnot::vec2 normal(diff.y, -diff.x);
                normal = normal * (1.0 / normal.GetLength());
                normal = normal * .01;
                const CKnot::vec2 flip(-normal.x, -normal.y);

                const CKnot::vec2 start = cur + normal;
                const CKnot::vec2 end = cur + flip;

                const bool over = z->Y(t) > 0.0;

                //Coords
                quads->push_back(start.x);
                quads->push_back(start.y);
                quads->push_back(over ? 0.01 : .1);

                //Colors
                quads->push_back(scr);
                quads->push_back(scg);
                quads->push_back(scb);

                quads->push_back(end.x);
                quads->push_back(end.y);
                quads->push_back(over ? 0.01 : .1);

                quads->push_back(ecr);
                quads->push_back(ecg);
                quads->push_back(ecb);
            }

            assert(quads->size() == memSize);
        }
    }


    //Clear the background some nice color.
    glClearColor(   0.125f + std::sin(time / 2.0) / 8.0,
                    0.125f + std::sin(time / 3.0) / 8.0,
                    0.125f + std::sin(time / 5.0) / 8.0,
                    0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    for (size_t i = 0; i < arrays.size(); ++i)
    {
        FloatArray& quads = *arrays[i];

        glVertexPointer(3, GL_FLOAT, 24, &quads.front());
        glColorPointer(3, GL_FLOAT, 24, &quads.front() + 3);

        const size_t count = quads.size() / 6;
        const size_t progress = size_t(std::min(artTime / DrawTime, 1.0) * count / 2); //From 0 to .5 of vertices.
        assert(progress >= 0);
        assert(progress <= count / 2);

        size_t start = (count / 2) - progress;
        start += start % 2;

        glDrawArrays(GL_QUAD_STRIP, start, progress * 2);
    }

    //Draw graph
    if (DrawGraph)
    {
        glVertexPointer(2, GL_FLOAT, 20, &grid.front());
        glColorPointer(3, GL_FLOAT, 20, &grid.front() + 2);
        glDrawArrays(GL_LINES, 0, grid.size() / 5);
    }

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);

    glLoadIdentity();
}