static void _cpml_sanity_put_intersections_with_segment(gint i) { CpmlPrimitive primitive; CpmlSegment segment; CpmlPair pair; /* Set primitive 1.1 and segment to 2 * so there is an intersection point in (1,1) */ cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()); cpml_primitive_from_segment(&primitive, &segment); cpml_segment_next(&segment); switch (i) { case 1: cpml_primitive_put_intersections_with_segment(NULL, &segment, 2, &pair); break; case 2: cpml_primitive_put_intersections_with_segment(&primitive, NULL, 2, &pair); break; case 3: cpml_primitive_put_intersections_with_segment(&primitive, &segment, 2, NULL); break; default: g_test_trap_assert_failed(); break; } }
/** * cpml_segment_put_intersections: * @segment: the first #CpmlSegment * @segment2: the second #CpmlSegment * @n_dest: maximum number of intersections to return * @dest: the destination vector of #CpmlPair * * Computes the intersections between @segment and @segment2 and * returns the found points in @dest. If the intersections are more * than @n_dest, only the first @n_dest pairs are stored in @dest. * * To get the job done, the primitives of @segment are sequentially * scanned for intersections with any primitive in @segment2. This * means @segment has a higher precedence over @segment2. * * Returns: the number of intersections found * * Since: 1.0 **/ size_t cpml_segment_put_intersections(const CpmlSegment *segment, const CpmlSegment *segment2, size_t n_dest, CpmlPair *dest) { CpmlPrimitive portion; size_t partial, total; cpml_primitive_from_segment(&portion, (CpmlSegment *) segment); total = 0; do { partial = cpml_primitive_put_intersections_with_segment(&portion, segment2, n_dest - total, dest + total); total += partial; } while (total < n_dest && cpml_primitive_next(&portion)); return total; }