예제 #1
0
파일: adg-dim.c 프로젝트: bert/adg
/**
 * adg_dim_set_pos_from_model:
 * @dim: an #AdgDim
 * @model: the source #AdgModel
 * @pos: a named pair in @model
 *
 * Binds #AdgDim:pos to the @pos named pair of @model. If @model
 * is <constant>NULL</constant>, the point will be unset. In any
 * case, the old point is silently discarded, unreferencing its
 * model if that point was bound to a named pair (hence,
 * possibly destroying the model if this was the last reference).
 *
 * The assignment is lazy so @pos could be not be present in @model.
 * Anyway, at the first access to this point an error will be raised
 * if the named pair is still missing.
 *
 * Since: 1.0
 **/
void
adg_dim_set_pos_from_model(AdgDim *dim, AdgModel *model, const gchar *pos)
{
    AdgPoint *point = adg_point_new();

    adg_point_set_pair_from_model(point, model, pos);
    adg_dim_set_pos(dim, point);

    adg_point_destroy(point);
}
예제 #2
0
파일: adg-dim.c 프로젝트: bert/adg
/**
 * adg_dim_set_pos_explicit:
 * @dim: an #AdgDim
 * @x: x coordinate of the position
 * @y: y coordinate of the position
 *
 * Sets the #AdgDim:pos property to the (@x, @y) explicit
 * coordinates. The old point is silently discarded,
 * unreferencing its model if that point was bound to a named
 * pair (hence, possibly destroying the model if this was the
 * last reference).
 *
 * Since: 1.0
 **/
void
adg_dim_set_pos_explicit(AdgDim *dim, gdouble x, gdouble y)
{
    AdgPoint *point = adg_point_new();

    adg_point_set_pair_explicit(point, x, y);
    adg_dim_set_pos(dim, point);

    adg_point_destroy(point);
}
예제 #3
0
파일: adg-adim.c 프로젝트: bert/adg
/**
 * adg_adim_set_org2_from_model:
 * @adim: an #AdgADim
 * @model: the source #AdgModel
 * @org2: a named pair in @model
 *
 * Binds #AdgADim:org2 to the @org2 named pair of @model. If @model
 * is <constant>NULL</constant>, the point will be unset. In any
 * case, the old point is silently discarded, unreferencing its
 * model if that point was bound to a named pair (hence, possibly
 * destroying the model if this was the last reference).
 *
 * The assignment is lazy so @org2 could be not be present in @model.
 * Anyway, at the first access to this point an error will be raised
 * if the named pair is still missing.
 *
 * Since: 1.0
 **/
void
adg_adim_set_org2_from_model(AdgADim *adim, AdgModel *model, const gchar *org2)
{
    AdgPoint *point = adg_point_new();

    adg_point_set_pair_from_model(point, model, org2);
    adg_adim_set_org2(adim, point);

    adg_point_destroy(point);
}
예제 #4
0
파일: adg-adim.c 프로젝트: bert/adg
/**
 * adg_adim_set_org2_explicit:
 * @adim: an #AdgADim
 * @x: x coordinate of the first reference point
 * @y: y coordinate of the first reference point
 *
 * Sets the #AdgADim:org2 property to the (@x, @y) explicit
 * coordinates. The old point is silently discarded,
 * unreferencing its model if that point was bound to a named
 * pair (hence, possibly destroying the model if this was the
 * last reference).
 *
 * Since: 1.0
 **/
void
adg_adim_set_org2_explicit(AdgADim *adim, gdouble x, gdouble y)
{
    AdgPoint *point = adg_point_new();

    adg_point_set_pair_explicit(point, x, y);
    adg_adim_set_org2(adim, point);

    adg_point_destroy(point);
}
예제 #5
0
int
main(int argc, char *argv[])
{
    adg_test_init(&argc, &argv);

    adg_test_add_boxed_checks("/adg/point/type/boxed", ADG_TYPE_POINT, adg_point_new());

    g_test_add_func("/adg/point/behavior/misc", _adg_behavior_misc);
    g_test_add_func("/adg/point/behavior/named-pair", _adg_behavior_named_pair);

    return g_test_run();
}
예제 #6
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);
}
예제 #7
0
static void
_adg_behavior_misc(void)
{
    AdgPoint *point, *dup_point;
    CpmlPair *pair,  *dup_pair;
    CpmlPair dummy_pair = { 3.4, 5.6 };

    point = adg_point_new();
    g_assert_nonnull(point);

    adg_point_set_pair_explicit(point, 1, 2);
    pair = (CpmlPair *) point;
    adg_assert_isapprox(pair->x, 1);
    adg_assert_isapprox(pair->y, 2);

    pair = adg_point_get_pair(point);
    g_assert_nonnull(pair);
    adg_assert_isapprox(pair->x, 1);
    adg_assert_isapprox(pair->y, 2);

    dup_point = adg_point_dup(point);
    g_assert_nonnull(dup_point);
    g_assert_true(dup_point != point);

    /* Should be a noop with explicit pairs */
    adg_point_invalidate(point);

    dup_pair = adg_point_get_pair(dup_point);
    g_assert_nonnull(dup_pair);
    g_assert_true(dup_pair != pair);

    adg_assert_isapprox(pair->x, dup_pair->x);
    adg_assert_isapprox(pair->y, dup_pair->y);
    g_assert_true(adg_point_equal(point, dup_point));

    g_free(dup_pair);
    adg_point_destroy(dup_point);

    dup_point = adg_point_new();
    adg_point_set_pair(dup_point, &dummy_pair);
    dup_pair = (CpmlPair *) dup_point;

    /* Should be a noop with explicit pairs */
    adg_point_invalidate(dup_point);

    adg_assert_isapprox(dup_pair->x, 3.4);
    adg_assert_isapprox(dup_pair->y, 5.6);
    g_assert_false(adg_point_equal(point, dup_point));

    adg_point_copy(dup_point, point);
    dup_pair = adg_point_get_pair(dup_point);
    g_assert_nonnull(dup_pair);
    g_assert_nonnull(dup_pair);

    adg_assert_isapprox(pair->x, dup_pair->x);
    adg_assert_isapprox(pair->y, dup_pair->y);
    g_assert_true(adg_point_equal(point, dup_point));

    g_free(pair);
    g_free(dup_pair);
    adg_point_destroy(point);
    adg_point_destroy(dup_point);
}
예제 #8
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);
}