TEST(SharedBufferTest, getAsBytesLargeSegments) { Vector<char> vector0(0x4000); for (size_t i = 0; i < vector0.size(); ++i) vector0[i] = 'a'; Vector<char> vector1(0x4000); for (size_t i = 0; i < vector1.size(); ++i) vector1[i] = 'b'; Vector<char> vector2(0x4000); for (size_t i = 0; i < vector2.size(); ++i) vector2[i] = 'c'; RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::adoptVector(vector0); sharedBuffer->append(vector1); sharedBuffer->append(vector2); const size_t size = sharedBuffer->size(); std::unique_ptr<char[]> data = wrapArrayUnique(new char[size]); sharedBuffer->getAsBytes(data.get(), size); ASSERT_EQ(0x4000U + 0x4000U + 0x4000U, size); int position = 0; for (int i = 0; i < 0x4000; ++i) { EXPECT_EQ('a', data[position]); ++position; } for (int i = 0; i < 0x4000; ++i) { EXPECT_EQ('b', data[position]); ++position; } for (int i = 0; i < 0x4000; ++i) { EXPECT_EQ('c', data[position]); ++position; } }
void GLKernel::PushLine(float32 x0, float32 y0, float32 x1, float32 y1) { Vector4 vector0(x0, y0, 1.0f, 1.0f); Vector4 vector1(x1, y1, 1.0f, 1.0f); if(m_Transformed) { vector0 = m_CurrentMatrix * vector0; vector1 = m_CurrentMatrix * vector1; } vector0.PopulateArray(m_Vertices); vector1.PopulateArray(m_Vertices); }
void NormalsFinder::execute() { assert ( _mesh != NULL ); for ( unsigned int i = 0; i < _mesh->face_count(); i++ ) { Face face = _mesh->get_face ( i ); Vertex middle = _mesh->get_vertex( face[1] ); Vertex first = _mesh->get_vertex( face[0] ); Vertex last = _mesh->get_vertex( face[2] ); Vector < float > vector0 ( middle, first ); Vector < float > vector1 ( middle, last ); Vector < float > normal; normal = vector1 * vector0; normal /= normal.length(); _mesh->add_normals_coord ( normal[0] ); _mesh->add_normals_coord ( normal[1] ); _mesh->add_normals_coord ( normal[2] ); } }
void Weights::calculateWeights() { mCoefficientNumber = (mTwoDim ? ((size_t)mPolynomeOrder + 1) * ((size_t)mPolynomeOrder + 1) : (size_t)mPolynomeOrder + 1); size_t ix, iy, i, j; int x, y; // Determine coordinates of pixels to be sampled if (mTwoDim) { int iPolynomeOrder = (int) mPolynomeOrder; //lets avoid signed/unsigned comparison warnings int iHeight = (int) height(); int iWidth = (int) width(); for (y = -iPolynomeOrder; y < iHeight + iPolynomeOrder; ++y) { for (x = -iPolynomeOrder; x < iWidth + iPolynomeOrder; ++x) { if ((x < 0 && y < 0 && -x - y < iPolynomeOrder + 2) || (x < 0 && y >= iHeight && -x + y - iHeight < iPolynomeOrder + 1) || (x >= iWidth && y < 0 && x - y - iWidth < iPolynomeOrder + 1) || (x >= iWidth && y >= iHeight && x + y - iWidth - iHeight < iPolynomeOrder) || (x < 0 && y >= 0 && y < iHeight) || (x >= iWidth && y >= 0 && y < iHeight) || (y < 0 && x >= 0 && x < iWidth ) || (y >= iHeight && x >= 0 && x < iWidth)) { QPoint position(x,y); mPositions.append(position); } } } } else { // In the one-dimensional case, only the y coordinate and y size is used. */ for (y = (-1)*mPolynomeOrder; y < 0; ++y) { QPoint position(0,y); mPositions.append(position); } for (y = (int) height(); y < (int) height() + (int) mPolynomeOrder; ++y) { QPoint position(0,y); mPositions.append(position); } } // Allocate memory. QScopedArrayPointer<double> matrix (new double[mCoefficientNumber * mCoefficientNumber]); QScopedArrayPointer<double> vector0(new double[mPositions.count() * mCoefficientNumber]); QScopedArrayPointer<double> vector1(new double[mPositions.count() * mCoefficientNumber]); // Calculate coefficient matrix and vectors for (iy = 0; iy < mCoefficientNumber; ++iy) { for (ix = 0; ix < mCoefficientNumber; ++ix) { matrix [iy* mCoefficientNumber+ix] = 0.0; } for (j = 0; j < (size_t)mPositions.count(); ++j) { vector0 [iy * mPositions.count() + j] = polyTerm (iy, mPositions.at(j).x(), mPositions.at(j).y(), mPolynomeOrder); for (ix = 0; ix < mCoefficientNumber; ++ix) { matrix [iy* mCoefficientNumber + ix] += (vector0 [iy * mPositions.count() + j] * polyTerm (ix, mPositions.at(j).x(), mPositions.at(j).y(), mPolynomeOrder)); } } } // Invert matrix. matrixInv (matrix.data(), mCoefficientNumber); // Multiply inverse matrix with vector. for (iy = 0; iy < mCoefficientNumber; ++iy) { for (j = 0; j < (size_t)mPositions.count(); ++j) { vector1 [iy * mPositions.count() + j] = 0.0; for (ix = 0; ix < mCoefficientNumber; ++ix) { vector1 [iy * mPositions.count() + j] += matrix [iy * mCoefficientNumber + ix] * vector0 [ix * mPositions.count() + j]; } } } // Store weights // Allocate mPositions.count() matrices. mWeightMatrices = new double** [mPositions.count()]; for (i=0 ; i < (size_t)mPositions.count() ; ++i) { // Allocate mHeight rows on each position mWeightMatrices[i] = new double*[mHeight]; for (j=0 ; j < mHeight ; ++j) { // Allocate mWidth columns on each row mWeightMatrices[i][j] = new double[mWidth]; } } for (y = 0; y < (int) mHeight; ++y) { for (x = 0; x < (int) mWidth; ++x) { for (j = 0; j < (size_t)mPositions.count(); ++j) { mWeightMatrices [j][y][x] = 0.0; for (iy = 0; iy < mCoefficientNumber; ++iy) { mWeightMatrices [j][y][x] += vector1 [iy * mPositions.count() + j] * polyTerm (iy, x, y, mPolynomeOrder); } mWeightMatrices [j][y][x] *= (double) mPositions.count(); } } } }