예제 #1
0
파일: adg-path.c 프로젝트: bert/adg
static void
_adg_dup_reverse_named_pairs(AdgModel *model, const cairo_matrix_t *matrix)
{
    AdgNamedPair *old_named_pair;
    AdgNamedPair named_pair;
    GSList *named_pairs;

    /* Populate named_pairs with all the named pairs of model */
    named_pairs = NULL;
    adg_model_foreach_named_pair(model, _adg_get_named_pair, &named_pairs);

    /* Readd the pairs applying the reversing transformation matrix to
     * their coordinates and prepending a "-" to their name */
    while (named_pairs) {
        old_named_pair = named_pairs->data;

        named_pair.name = g_strdup_printf("-%s", old_named_pair->name);
        named_pair.pair = old_named_pair->pair;
        cpml_pair_transform(&named_pair.pair, matrix);

        adg_model_set_named_pair(model, named_pair.name, &named_pair.pair);

        g_free((gpointer) named_pair.name);
        named_pairs = g_slist_delete_link(named_pairs, named_pairs);
    }
}
예제 #2
0
파일: adg-model.c 프로젝트: bert/adg
/**
 * adg_model_set_named_pair_explicit:
 * @model: an #AdgModel
 * @name: the name to associate to the pair
 * @x: the x coordinate of the point
 * @y: the y coordinate of the point
 *
 * <note><para>
 * This function is only useful in model definitions, such as
 * inside an #AdgTrailCallback function or while constructing
 * an #AdgPath instance.
 * </para></note>
 *
 * Convenient wrapper on adg_model_set_named_pair() that accepts
 * explicit coordinates.
 *
 * Since: 1.0
 **/
void
adg_model_set_named_pair_explicit(AdgModel *model, const gchar *name,
                                  gdouble x, gdouble y)
{
    CpmlPair pair;

    pair.x = x;
    pair.y = y;

    adg_model_set_named_pair(model, name, &pair);
}
예제 #3
0
static void
_adg_behavior_named_pair(void)
{
    CpmlPair p1 = { 123, 456 };
    AdgPoint *explicit_point, *explicit_point2, *model_point;
    AdgModel *model;
    CpmlPair *pair;

    explicit_point = adg_point_new();
    g_assert_nonnull(explicit_point);
    adg_point_set_pair(explicit_point, &p1);

    explicit_point2 = adg_point_new();
    g_assert_nonnull(explicit_point2);
    adg_point_set_pair_explicit(explicit_point2, p1.x, p1.y);

    /* Checking comparison APIs */
    g_assert_true(adg_point_equal(explicit_point, explicit_point2));
    adg_point_set_pair_explicit(explicit_point2, 78, 90);
    g_assert_false(adg_point_equal(explicit_point, explicit_point2));
    pair = (CpmlPair *) explicit_point2;
    adg_assert_isapprox(pair->x, 78);
    adg_assert_isapprox(pair->y, 90);

    pair = adg_point_get_pair(explicit_point);
    g_assert_true(cpml_pair_equal(pair, &p1));
    g_free(pair);

    model = ADG_MODEL(adg_path_new());
    g_assert_nonnull(model);
    adg_model_set_named_pair(model, "named-pair", &p1);

    model_point = adg_point_new();
    g_assert_nonnull(model_point);
    adg_point_set_pair_from_model(model_point, model, "named-pair");

    pair = adg_point_get_pair(model_point);
    g_assert_true(cpml_pair_equal(pair, &p1));
    g_free(pair);

    /* Ensure ADG does not consider an explicit point equals to
     * a point bound to a named pair with the same coordinates */
    g_assert_false(adg_point_equal(explicit_point, model_point));

    /* Check for lazy evaluation of named pairs */
    adg_point_set_pair_from_model(model_point, model, "unexistent-pair");
    pair = (CpmlPair *) model_point;
    adg_assert_isapprox(pair->x, p1.x);
    adg_assert_isapprox(pair->y, p1.y);

    /* Check behavior on undefined named pair */
    g_assert_false(adg_point_update(model_point));
    g_assert_null(adg_point_get_pair(model_point));

    adg_point_set_pair_from_model(model_point, model, "named-pair");
    g_assert_true(adg_point_update(model_point));

    /* Check for case sensitiveness */
    adg_point_set_pair_from_model(model_point, model, "Named-Pair");
    g_assert_null(adg_point_get_pair(model_point));
    g_assert_false(adg_point_update(model_point));

    /* Check if adg_point_get_pair() triggers an adg_point_update() */
    adg_point_set_pair_from_model(model_point, model, "named-pair");
    pair = adg_point_get_pair(model_point);
    g_assert_true(cpml_pair_equal(pair, &p1));
    g_free(pair);

    adg_point_destroy(explicit_point);
    adg_point_destroy(model_point);
    g_object_unref(model);
}
예제 #4
0
파일: test-adim.c 프로젝트: bert/adg
static void
_adg_property_org1(void)
{
    AdgADim *adim;
    AdgModel *model;
    AdgPoint *origin, *explicit_point, *model_point;
    AdgPoint *org1;

    adim = adg_adim_new();
    model = ADG_MODEL(adg_path_new());
    origin = adg_point_new();
    explicit_point = adg_point_new();
    model_point = adg_point_new();

    adg_point_set_pair_explicit(origin, 0, 0);
    adg_point_set_pair_explicit(explicit_point, 123, 321);
    adg_model_set_named_pair(model, "named-pair", (CpmlPair *) explicit_point);
    adg_point_set_pair_from_model(model_point, model, "named-pair");

    /* Ensure ADG does not consider an explicit point equals to
     * a point bound to a named pair with the same coordinates */
    g_assert_false(adg_point_equal(explicit_point, model_point));

    org1 = adg_adim_get_org1(adim);
    g_assert_null(org1);

    /* Using the public APIs */
    adg_adim_set_org1_explicit(adim, 0, 0);
    org1 = adg_adim_get_org1(adim);
    g_assert_true(adg_point_equal(org1, origin));

    adg_adim_set_org1(adim, NULL);
    org1 = adg_adim_get_org1(adim);
    g_assert_null(org1);

    adg_adim_set_org1(adim, explicit_point);
    org1 = adg_adim_get_org1(adim);
    g_assert_true(adg_point_equal(org1, explicit_point));

    adg_adim_set_org1_from_model(adim, model, "dummy");
    org1 = adg_adim_get_org1(adim);
    g_assert_nonnull(org1);

    adg_adim_set_org1_from_model(adim, model, "named-pair");
    org1 = adg_adim_get_org1(adim);
    g_assert_true(adg_point_equal(org1, model_point));

    /* Using GObject property methods */
    g_object_set(adim, "org1", origin, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_true(adg_point_equal(org1, origin));
    adg_point_destroy(org1);

    g_object_set(adim, "org1", NULL, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_null(org1);

    g_object_set(adim, "org1", explicit_point, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_true(adg_point_equal(org1, explicit_point));
    adg_point_destroy(org1);

    adg_adim_set_org1_from_model(adim, model, "dummy");
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_nonnull(org1);
    adg_point_destroy(org1);

    g_object_set(adim, "org1", model_point, NULL);
    g_object_get(adim, "org1", &org1, NULL);
    g_assert_true(adg_point_equal(org1, model_point));
    adg_point_destroy(org1);

    adg_point_destroy(origin);
    adg_point_destroy(explicit_point);
    adg_point_destroy(model_point);
    adg_entity_destroy(ADG_ENTITY(adim));
    g_object_unref(model);
}