Exemplo n.º 1
0
static void
_cpml_method_get_length(void)
{
    CpmlSegment segment;
    CpmlPrimitive primitive;

    cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path());
    cpml_segment_next(&segment);
    cpml_primitive_from_segment(&primitive, &segment);

    adg_assert_isapprox(cpml_primitive_get_length(&primitive), 1);

    cpml_primitive_next(&primitive);
    adg_assert_isapprox(cpml_primitive_get_length(&primitive), 2);
}
Exemplo n.º 2
0
Arquivo: adg-path.c Projeto: bert/adg
static void
_adg_do_chamfer(AdgPath *path, CpmlPrimitive *current)
{
    AdgPathPrivate *data;
    CpmlPrimitive *last;
    gdouble delta1, delta2;
    gdouble len1, len2;
    CpmlPair pair;

    data = path->data;
    last = &data->last;
    delta1 = data->operation.data.chamfer.delta1;
    len1 = cpml_primitive_get_length(last);

    if (delta1 >= len1) {
        g_warning(_("%s: first chamfer delta of %lf is greather than the available %lf length"),
                  G_STRLOC, delta1, len1);
        return;
    }

    delta2 = data->operation.data.chamfer.delta2;
    len2 = cpml_primitive_get_length(current);

    if (delta2 >= len2) {
        g_warning(_("%s: second chamfer delta of %lf is greather than the available %lf length"),
                  G_STRLOC, delta1, len1);
        return;
    }

    /* Change the end point of the last primitive */
    cpml_primitive_put_pair_at(last, 1. - delta1 / len1, &pair);
    cpml_primitive_set_point(last, -1, &pair);

    /* Change the start point of the current primitive */
    cpml_primitive_put_pair_at(current, delta2 / len2, &pair);
    cpml_primitive_set_point(current, 0, &pair);

    /* Add the chamfer line */
    data->operation.action = ADG_ACTION_NONE;
    adg_path_append(path, CPML_LINE, &pair);
}
Exemplo n.º 3
0
static void
_cpml_sanity_get_length(gint i)
{
    switch (i) {
    case 1:
        cpml_primitive_get_length(NULL);
        break;
    default:
        g_test_trap_assert_failed();
        break;
    }
}
Exemplo n.º 4
0
/**
 * cpml_segment_get_length:
 * @segment: a #CpmlSegment
 *
 * Gets the whole length of @segment.
 *
 * Returns: the requested length
 *
 * Since: 1.0
 **/
double
cpml_segment_get_length(const CpmlSegment *segment)
{
    CpmlPrimitive primitive;
    double length;

    cpml_primitive_from_segment(&primitive, (CpmlSegment *) segment);
    length = 0;

    do {
        length += cpml_primitive_get_length(&primitive);
    } while (cpml_primitive_next(&primitive));

    return length;
}