static void test_treatAsSprite(skiatest::Reporter* reporter) { const unsigned bilerBits = kSkSubPixelBitsForBilerp; SkMatrix mat; SkISize size; SkRandom rand; // assert: translate-only no-filter can always be treated as sprite for (int i = 0; i < 1000; ++i) { rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask); for (int j = 0; j < 1000; ++j) { rand_size(&size, rand); REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, 0)); } } // assert: rotate/perspect is never treated as sprite for (int i = 0; i < 1000; ++i) { rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask); for (int j = 0; j < 1000; ++j) { rand_size(&size, rand); REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, 0)); REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); } } size.set(500, 600); const SkScalar tooMuchSubpixel = 100.1f; mat.setTranslate(tooMuchSubpixel, 0); REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); mat.setTranslate(0, tooMuchSubpixel); REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); const SkScalar tinySubPixel = 100.02f; mat.setTranslate(tinySubPixel, 0); REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); mat.setTranslate(0, tinySubPixel); REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); const SkScalar twoThirds = SK_Scalar1 * 2 / 3; const SkScalar bigScale = (size.width() + twoThirds) / size.width(); mat.setScale(bigScale, bigScale); REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, false)); REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); const SkScalar oneThird = SK_Scalar1 / 3; const SkScalar smallScale = (size.width() + oneThird) / size.width(); mat.setScale(smallScale, smallScale); REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false)); REPORTER_ASSERT(reporter, !treat_as_sprite(mat, size, bilerBits)); const SkScalar oneFortyth = SK_Scalar1 / 40; const SkScalar tinyScale = (size.width() + oneFortyth) / size.width(); mat.setScale(tinyScale, tinyScale); REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, false)); REPORTER_ASSERT(reporter, treat_as_sprite(mat, size, bilerBits)); }
boost boost::rand_n(const int row, const int col) { if (row < 0 || col < 0) { throw std::invalid_argument("Column and row lengths must be non-negative integers"); } else { std::default_random_engine generator; std::normal_distribution<float> distribution(0, 1); bnu::matrix<float> rand_matrix(row, col); for (unsigned i = 0; i < rand_matrix.size1 (); ++ i){ for (unsigned j = 0; j < rand_matrix.size2 (); ++ j){ rand_matrix(i, j) = distribution(generator); } } matrix_data = rand_matrix; return *this; } }
int main(int argc, char *argv[]) { // Size of the matrix to be generated ramdomly // Matrix of size m*n and k*l or Lines and Columns int m, n, k, l; // Loop control variables int i, j; // Files where the matrices will be saved FILE *matFileOne; FILE *matFileTwo; // Open the two files in writing mode matFileOne = fopen("./in1.txt", "w"); // If file not oppened prints a message if (matFileOne == NULL) { printf("Couldn't open ./in1.txt\n"); return (0); } matFileTwo = fopen("./in2.txt", "w"); // If file not oppened prints a message if (matFileTwo == NULL) { printf("Couldn't open ./in2.txt\n"); return (0); } if (argc != 5) { printf("Insert the 4 dimensions for the Matrices!\n"); exit(1); } // Convert the parameters to int to give the matrix's dimensions m = atoi((const char *)argv[1]); n = atoi((const char *)argv[2]); k = atoi((const char *)argv[3]); l = atoi((const char *)argv[4]); // Matrix pointer int *mat; // Allocate memory to the matrix or exits in case of error if (!(mat = (int *)malloc(m * n * sizeof(int)))) { printf("Error occurred while allocating memory for the matrix!\n"); exit(1); } else // printf("Matrix allocated successfully!\n"); // Generates the Matrices // rand_matrix(m, n, mat); // show_matrix(m, n, mat); writeFileMat(mat, matFileOne, m, n); rand_matrix(m, n, mat); // show_matrix(k, l, mat); writeFileMat(mat, matFileTwo, k, l); // Identity matrix. Always with the dimensions m*n, the first two arguments identity_matrix(m, n); // Show matrix // show_matrix(m, n, mat); // frees the allocated space in memory for the matrix free(mat); // Close files fclose(matFileOne); fclose(matFileTwo); exit(0); }
static void test_treatAsSprite(skiatest::Reporter* reporter) { SkMatrix mat; SkISize size; SkRandom rand; SkPaint noaaPaint; SkPaint aaPaint; aaPaint.setAntiAlias(true); // assert: translate-only no-aa can always be treated as sprite for (int i = 0; i < 1000; ++i) { rand_matrix(&mat, rand, SkMatrix::kTranslate_Mask); for (int j = 0; j < 1000; ++j) { rand_size(&size, rand); REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint)); } } // assert: rotate/perspect is never treated as sprite for (int i = 0; i < 1000; ++i) { rand_matrix(&mat, rand, SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask); for (int j = 0; j < 1000; ++j) { rand_size(&size, rand); REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, noaaPaint)); REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint)); } } size.set(500, 600); const SkScalar tooMuchSubpixel = 100.1f; mat.setTranslate(tooMuchSubpixel, 0); REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint)); mat.setTranslate(0, tooMuchSubpixel); REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint)); const SkScalar tinySubPixel = 100.02f; mat.setTranslate(tinySubPixel, 0); REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint)); mat.setTranslate(0, tinySubPixel); REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint)); const SkScalar twoThirds = SK_Scalar1 * 2 / 3; const SkScalar bigScale = (size.width() + twoThirds) / size.width(); mat.setScale(bigScale, bigScale); REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, noaaPaint)); REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint)); const SkScalar oneThird = SK_Scalar1 / 3; const SkScalar smallScale = (size.width() + oneThird) / size.width(); mat.setScale(smallScale, smallScale); REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint)); REPORTER_ASSERT(reporter, !SkTreatAsSprite(mat, size, aaPaint)); const SkScalar oneFortyth = SK_Scalar1 / 40; const SkScalar tinyScale = (size.width() + oneFortyth) / size.width(); mat.setScale(tinyScale, tinyScale); REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, noaaPaint)); REPORTER_ASSERT(reporter, SkTreatAsSprite(mat, size, aaPaint)); }