Example #1
0
static void
_cpml_method_put_pair_at(void)
{
    CpmlSegment segment;
    CpmlPrimitive primitive;
    CpmlPair pair;

    cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path());

    /* Line */
    cpml_primitive_from_segment(&primitive, &segment);
    cpml_primitive_put_pair_at(&primitive, 0, &pair);
    adg_assert_isapprox(pair.x, 0);
    adg_assert_isapprox(pair.y, 1);
    cpml_primitive_put_pair_at(&primitive, 1, &pair);
    adg_assert_isapprox(pair.x, 3);
    adg_assert_isapprox(pair.y, 1);
    cpml_primitive_put_pair_at(&primitive, 0.5, &pair);
    adg_assert_isapprox(pair.x, 1.5);
    adg_assert_isapprox(pair.y, 1);

    /* Arc */
    cpml_primitive_next(&primitive);
    cpml_primitive_put_pair_at(&primitive, 0, &pair);
    adg_assert_isapprox(pair.x, 3);
    adg_assert_isapprox(pair.y, 1);
    cpml_primitive_put_pair_at(&primitive, 1, &pair);
    adg_assert_isapprox(pair.x, 6);
    adg_assert_isapprox(pair.y, 7);
    cpml_primitive_put_pair_at(&primitive, 0.5, &pair);
    adg_assert_isapprox(pair.x, 3.669);
    adg_assert_isapprox(pair.y, 4.415);

    /* Close */
    cpml_primitive_next(&primitive);
    /* TODO: not yet implemented
     * cpml_primitive_put_pair_at(&primitive, 0, &pair);
     * adg_assert_isapprox(pair.x, 6);
     * adg_assert_isapprox(pair.y, 7);
     * cpml_primitive_put_pair_at(&primitive, 1, &pair);
     * adg_assert_isapprox(pair.x, -2);
     * adg_assert_isapprox(pair.y, 2);
     * cpml_primitive_put_pair_at(&primitive, 0.5, &pair);
     * adg_assert_isapprox(pair.x, 1);
     * adg_assert_isapprox(pair.y, 1); */

    /* Close */
    cpml_primitive_next(&primitive);
    cpml_primitive_put_pair_at(&primitive, 0, &pair);
    adg_assert_isapprox(pair.x, -2);
    adg_assert_isapprox(pair.y, 2);
    cpml_primitive_put_pair_at(&primitive, 1, &pair);
    adg_assert_isapprox(pair.x, 0);
    adg_assert_isapprox(pair.y, 1);
    cpml_primitive_put_pair_at(&primitive, 0.5, &pair);
    adg_assert_isapprox(pair.x, -1);
    adg_assert_isapprox(pair.y, 1.5);
}
Example #2
0
/**
 * cpml_segment_put_pair_at:
 * @segment: a #CpmlSegment
 * @pos:     the position value
 * @pair:    the destination #CpmlPair
 *
 * Gets the coordinates of the point lying on @segment at position
 * @pos. @pos is an homogeneous factor where 0 is the start point,
 * 1 the end point, 0.5 the mid point and so on.
 * The relation <constant>0 < @pos < 1</constant> should be satisfied,
 * although some cases accept value outside this range.
 *
 * <important>
 * <title>TODO</title>
 * <itemizedlist>
 * <listitem>The actual implementation returns only the start and end points,
 *           that is only when @pos is 0 or 1.</listitem>
 * </itemizedlist>
 * </important>
 *
 * Since: 1.0
 **/
void
cpml_segment_put_pair_at(const CpmlSegment *segment, double pos,
                         CpmlPair *pair)
{
    CpmlPrimitive primitive;

    cpml_primitive_from_segment(&primitive, (CpmlSegment *) segment);

    /* Handle the common cases: start and end points */
    if (pos == 0) {
        cpml_primitive_put_pair_at(&primitive, 0, pair);
    } if (pos == 1) {
        while (cpml_primitive_next(&primitive))
            ;
        cpml_primitive_put_pair_at(&primitive, 1, pair);
    }
}
Example #3
0
File: adg-path.c Project: 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);
}
Example #4
0
static void
_cpml_sanity_put_pair_at(gint i)
{
    CpmlSegment segment;
    CpmlPrimitive primitive;
    CpmlPair pair;

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

    switch (i) {
    case 1:
        cpml_primitive_put_pair_at(NULL, 1, &pair);
        break;
    case 2:
        cpml_primitive_put_pair_at(&primitive, 1, NULL);
        break;
    default:
        g_test_trap_assert_failed();
        break;
    }
}