Ejemplo n.º 1
0
void test_add_point_with_stamp_outside()
{
    static float expected[] = {
        0.0f, 0.0f, 0.0f,
        0.0f, 0.0f, 0.0f,
        0.0f, 0.0f, 0.0f,
    };

    heatmap_t* hm = heatmap_new(3, 3);
    heatmap_add_point_with_stamp(hm, 3, 2, &g_3x3_stamp);
    heatmap_add_point_with_stamp(hm, 2, 3, &g_3x3_stamp);
    heatmap_add_point_with_stamp(hm, 3, 3, &g_3x3_stamp);

    ENSURE_THAT("no point outside the map got added", heatmap_eq(hm, expected));
    ENSURE_THAT("the max of the heatmap is zero", hm->max == 0.0f);

    heatmap_add_weighted_point_with_stamp(hm, 3, 2, 1.5f, &g_3x3_stamp);
    heatmap_add_weighted_point_with_stamp(hm, 2, 3, 1.5f, &g_3x3_stamp);
    heatmap_add_weighted_point_with_stamp(hm, 3, 3, 1.5f, &g_3x3_stamp);

    ENSURE_THAT("no weighted point outside the map got added", heatmap_eq(hm, expected));
    ENSURE_THAT("the max of the heatmap is zero", hm->max == 0.0f);

    heatmap_free(hm);
}
Ejemplo n.º 2
0
void test_render_to_saturating()
{
    static unsigned char expected1[] = {
                0, 0, 0, 0,   255, 255, 255, 255,   0, 0, 0, 0,
        255, 255, 255, 255,   255, 255, 255, 255,   255, 255, 255, 255,
                0, 0, 0, 0,   255, 255, 255, 255,   0, 0, 0, 0,
    };

    static unsigned char expected2[] = {
                0, 0, 0, 0,   191, 191, 191, 255,   0, 0, 0, 0,
        191, 191, 191, 255,   255, 255, 255, 255,   191, 191, 191, 255,
                0, 0, 0, 0,   191, 191, 191, 255,   0, 0, 0, 0,
    };

    heatmap_t* hm = heatmap_new(3, 3);
    heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp);
    heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp);
    heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp);

    unsigned char img[3*3*4] = {1};
    heatmap_render_saturated_to(hm, heatmap_cs_b2w, 1.0f, img);
    ENSURE_THAT("saturated (1) rendered 3x3 heatmap is correct", 0 == memcmp(img, expected1, 3*3*4));

    heatmap_render_saturated_to(hm, heatmap_cs_b2w, 2.0f, img);
    ENSURE_THAT("saturated (2) rendered 3x3 heatmap is correct", 0 == memcmp(img, expected2, 3*3*4));

    heatmap_free(hm);
    // TODO: (Also try negative and non-one-max stamps?)
}
Ejemplo n.º 3
0
void test_add_point_with_stamp_center()
{
    heatmap_t* hm = heatmap_new(3, 3);
    heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp);

    ENSURE_THAT("the heatmap equals the stamp", heatmap_eq(hm, g_3x3_stamp.buf));
    ENSURE_THAT("the max of the heatmap is one", hm->max == 1.0f);

    heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp);

    static float expected[] = {
        0.0f, 1.0f, 0.0f,
        1.0f, 2.0f, 1.0f,
        0.0f, 1.0f, 0.0f,
    };

    ENSURE_THAT("the heatmap equals double the stamp", heatmap_eq(hm, expected));
    ENSURE_THAT("the max of the heatmap is two", hm->max == 2.0f);

    heatmap_t* hm2 = heatmap_new(3, 3);
    heatmap_add_weighted_point_with_stamp(hm2, 1, 1, 2.0f, &g_3x3_stamp);

    ENSURE_THAT("a point with weight 2.0 generates the same heatmap.", heatmaps_eq(hm2, hm));

    heatmap_free(hm);
    heatmap_free(hm2);
}
Ejemplo n.º 4
0
void test_add_point_with_stamp_botright()
{
    static float expected[] = {
        0.0f, 0.0f, 0.0f,
        0.0f, 0.0f, 0.5f,
        0.0f, 0.5f, 1.0f,
    };

    heatmap_t* hm = heatmap_new(3, 3);
    heatmap_add_point_with_stamp(hm, 2, 2, &g_3x3_stamp);

    ENSURE_THAT("bot-right point is correct", heatmap_eq(hm, expected));
    ENSURE_THAT("the max of the heatmap is one", hm->max == 1.0f);

    heatmap_t* hm2 = heatmap_new(3, 3);
    heatmap_add_point_with_stamp(hm, 2, 2, &g_3x3_stamp);
    heatmap_add_weighted_point_with_stamp(hm2, 2, 2, 2.0f, &g_3x3_stamp);

    ENSURE_THAT("a point with weight 2.0 generates the same heatmap as two regular ones.", heatmaps_eq(hm2, hm));

    heatmap_free(hm);
    heatmap_free(hm2);
}
Ejemplo n.º 5
0
void test_render_to_normalizing()
{
    static unsigned char expected[] = {
                0, 0, 0, 0,   127, 127, 127, 255,   0, 0, 0, 0,
        127, 127, 127, 255,   255, 255, 255, 255,   127, 127, 127, 255,
                0, 0, 0, 0,   127, 127, 127, 255,   0, 0, 0, 0,
    };

    heatmap_t* hm = heatmap_new(3, 3);
    heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp);

    unsigned char img[3*3*4] = {1};
    heatmap_render_to(hm, heatmap_cs_b2w, img);

    ENSURE_THAT("simple rendered 3x3 heatmap is correct", 0 == memcmp(img, expected, 3*3*4));

    heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp);
    heatmap_render_to(hm, heatmap_cs_b2w, img);

    ENSURE_THAT("two points on one spot don't change the outcome, due to normalization.", 0 == memcmp(img, expected, 3*3*4));

    heatmap_free(hm);
    // TODO: (Also try negative and non-one-max stamps?)
}
Ejemplo n.º 6
0
void test_render_to_creation()
{
    static unsigned char expected[] = {
                0, 0, 0, 0,   127, 127, 127, 255,   0, 0, 0, 0,
        127, 127, 127, 255,   255, 255, 255, 255,   127, 127, 127, 255,
                0, 0, 0, 0,   127, 127, 127, 255,   0, 0, 0, 0,
    };

    heatmap_t* hm = heatmap_new(3, 3);
    heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp);

    unsigned char* img = heatmap_render_to(hm, heatmap_cs_b2w, nullptr);

    ENSURE_THAT("simple rendered 3x3 heatmap is correct", 0 == memcmp(img, expected, 3*3*4));

    heatmap_free(hm);
    free(img);
}
Ejemplo n.º 7
0
void heatmap_add_point(heatmap_t* h, unsigned x, unsigned y)
{
    heatmap_add_point_with_stamp(h, x, y, &stamp_default_4);
}