Пример #1
0
void CowichanTBB::life(BoolMatrix input, BoolMatrix output) {
  GameOfLife game(input, output, nr, nc);

  for (index_t i = 0; i < LIFE_ITERATIONS; ++i) {

    // update CA simulation
    parallel_reduce(Range2D(0, nr, 0, nc), game, auto_partitioner());

    // check if there are alive cells
    if (!game.isAlive()) {
      no_cells_alive();
    }

    // swap arrays (ping-pong approach)
    game.swap();

  }

  // final result is in input - copy to output
  if (LIFE_ITERATIONS % 2 == 0) {
    for (index_t r = 0; r < nr; r++) {
      for (index_t c = 0; c < nc; c++) {
        MATRIX_RECT(output, r, c) = MATRIX_RECT(input, r, c);
      }
    }
  }
}
void HarfBuzzFontGLTest::layout() {
    HarfBuzzFont font;
    CORRADE_VERIFY(font.openFile(Utility::Directory::join(FREETYPEFONT_TEST_DIR, "Oxygen.ttf"), 16.0f));

    /* Fill the cache with some fake glyphs */
    GlyphCache cache(Vector2i(256));
    cache.insert(font.glyphId(U'W'), {25, 34}, {{0, 8}, {16, 128}});
    cache.insert(font.glyphId(U'e'), {25, 12}, {{16, 4}, {64, 32}});

    std::unique_ptr<AbstractLayouter> layouter = font.layout(cache, 0.5f, "Wave");
    CORRADE_VERIFY(layouter);
    CORRADE_COMPARE(layouter->glyphCount(), 4);

    Vector2 cursorPosition;
    Range2D rectangle, position, textureCoordinates;

    /* Difference between this and FreeTypeFont should be _only_ in advances */

    /* 'W' */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(0, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D({0.78125f, 1.0625f}, {1.28125f, 4.8125f}));
    CORRADE_COMPARE(textureCoordinates, Range2D({0, 0.03125f}, {0.0625f, 0.5f}));
    CORRADE_COMPARE(cursorPosition, Vector2(0.51123f, 0.0f));

    /* 'a' (not in cache) */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(1, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D());
    CORRADE_COMPARE(textureCoordinates, Range2D());
    CORRADE_COMPARE(cursorPosition, Vector2(0.258301f, 0.0f));

    /* 'v' (not in cache) */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(2, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D());
    CORRADE_COMPARE(textureCoordinates, Range2D());
    CORRADE_COMPARE(cursorPosition, Vector2(0.25f, 0.0f));

    /* 'e' */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(3, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D({0.78125f, 0.375f}, {2.28125f, 1.25f}));
    CORRADE_COMPARE(textureCoordinates, Range2D({0.0625f, 0.015625f}, {0.25f, 0.125f}));
    CORRADE_COMPARE(cursorPosition, Vector2(0.260742f, 0.0f));
}
Пример #3
0
void MagnumFontGLTest::layout() {
    MagnumFont font;
    CORRADE_VERIFY(font.openFile(Utility::Directory::join(MAGNUMFONT_TEST_DIR, "font.conf"), 0.0f));

    /* Fill the cache with some fake glyphs */
    GlyphCache cache(Vector2i(256));
    cache.insert(font.glyphId(U'W'), {25, 34}, {{0, 8}, {16, 128}});
    cache.insert(font.glyphId(U'e'), {25, 12}, {{16, 4}, {64, 32}});

    auto layouter = font.layout(cache, 0.5f, "Wave");
    CORRADE_VERIFY(layouter);
    CORRADE_COMPARE(layouter->glyphCount(), 4);

    Range2D rectangle;
    Range2D position;
    Range2D textureCoordinates;

    /* 'W' */
    Vector2 cursorPosition;
    std::tie(position, textureCoordinates) = layouter->renderGlyph(0, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D({0.78125f, 1.0625f}, {1.28125f, 4.8125f}));
    CORRADE_COMPARE(textureCoordinates, Range2D({0, 0.03125f}, {0.0625f, 0.5f}));
    CORRADE_COMPARE(cursorPosition, Vector2(0.71875f, 0.0f));

    /* 'a' (not found) */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(1, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D());
    CORRADE_COMPARE(textureCoordinates, Range2D());
    CORRADE_COMPARE(cursorPosition, Vector2(0.25f, 0.0f));

    /* 'v' (not found) */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(2, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D());
    CORRADE_COMPARE(textureCoordinates, Range2D());
    CORRADE_COMPARE(cursorPosition, Vector2(0.25f, 0.0f));

    /* 'e' */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(3, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D({0.78125f, 0.375f}, {2.28125f, 1.25f}));
    CORRADE_COMPARE(textureCoordinates, Range2D({0.0625f, 0.015625f}, {0.25f, 0.125f}));
    CORRADE_COMPARE(cursorPosition, Vector2(0.375f, 0.0f));
}
Пример #4
0
void RangeTest::deprecated() {
    typedef Geometry::Rectangle<Float> Rectangle;
    typedef Geometry::Rectangle<Int> Rectanglei;

    Rectanglei a({45, 23}, {-17, 35});
    CORRADE_COMPARE(Rectanglei(), Range2Di({0, 0}, {0, 0}));
    CORRADE_COMPARE(a, Range2Di({45, 23}, {-17, 35}));
    CORRADE_COMPARE(Rectanglei(a), Range2Di({45, 23}, {-17, 35}));
    CORRADE_COMPARE(Rectangle(a), Range2D({45.0f, 23.0f}, {-17.0f, 35.0f}));

    CORRADE_COMPARE(a.width(), -62);
    CORRADE_COMPARE(a.height(), 12);

    CORRADE_VERIFY(!(std::is_convertible<Rectangle, Rectanglei>::value));

    Corrade::Utility::Configuration c;
    Rectangle rect({3.0f, 3.125f}, {9.0f, 9.55f});
    std::string value("3 3.125 9 9.55");

    c.setValue("rectangle", rect);
    CORRADE_COMPARE(c.value("rectangle"), value);
    CORRADE_COMPARE(c.value<Rectangle>("rectangle"), rect);
}
void StbTrueTypeFontGLTest::layout() {
    StbTrueTypeFont font;
    CORRADE_VERIFY(font.openFile(Utility::Directory::join(FREETYPEFONT_TEST_DIR, "Oxygen.ttf"), 16.0f));

    /* Fill the cache with some fake glyphs */
    GlyphCache cache(Vector2i(256));
    cache.insert(font.glyphId(U'W'), {25, 34}, {{0, 8}, {16, 128}});
    cache.insert(font.glyphId(U'e'), {25, 12}, {{16, 4}, {64, 32}});

    std::unique_ptr<AbstractLayouter> layouter = font.layout(cache, 0.5f, "Wave");
    CORRADE_VERIFY(layouter);
    CORRADE_COMPARE(layouter->glyphCount(), 4);

    Vector2 cursorPosition;
    Range2D rectangle, position, textureCoordinates;

    /* 'W' */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(0, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D({0.78125f, 1.0625f}, {1.28125f, 4.8125f}));
    CORRADE_COMPARE(textureCoordinates, Range2D({0, 0.03125f}, {0.0625f, 0.5f}));
    {
        CORRADE_EXPECT_FAIL("Font properties don't match FreeType with the same font size.");
        CORRADE_COMPARE(cursorPosition, Vector2(0.53125f, 0.0f));
    } {
        /* Test that we are at least consistently wrong */
        CORRADE_COMPARE(cursorPosition, Vector2(0.595917f, 0.0f));
    }

    /* 'a' (not in cache) */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(1, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D());
    CORRADE_COMPARE(textureCoordinates, Range2D());
    {
        CORRADE_EXPECT_FAIL("Font properties don't match FreeType with the same font size.");
        CORRADE_COMPARE(cursorPosition, Vector2(0.25f, 0.0f));
    } {
        /* Test that we are at least consistently wrong */
        CORRADE_COMPARE(cursorPosition, Vector2(0.295582f, 0.0f));
    }

    /* 'v' (not in cache) */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(2, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D());
    CORRADE_COMPARE(textureCoordinates, Range2D());
    {
        CORRADE_EXPECT_FAIL("Font properties don't match FreeType with the same font size.");
        CORRADE_COMPARE(cursorPosition, Vector2(0.25f, 0.0f));
    } {
        /* Test that we are at least consistently wrong */
        CORRADE_COMPARE(cursorPosition, Vector2(0.289709f, 0.0f));
    }

    /* 'e' */
    std::tie(position, textureCoordinates) = layouter->renderGlyph(3, cursorPosition = {}, rectangle);
    CORRADE_COMPARE(position, Range2D({0.78125f, 0.375f}, {2.28125f, 1.25f}));
    CORRADE_COMPARE(textureCoordinates, Range2D({0.0625f, 0.015625f}, {0.25f, 0.125f}));
    {
        CORRADE_EXPECT_FAIL("Font properties don't match FreeType with the same font size.");
        CORRADE_COMPARE(cursorPosition, Vector2(0.28125f, 0.0f));
    } {
        /* Test that we are at least consistently wrong */
        CORRADE_COMPARE(cursorPosition, Vector2(0.298658f, 0.0f));
    }
}