path: Handle degenerate paths without crashing

When calling get_point on a path which only contains
a move, we were crashing. Fix this by adding the same
special case handling that get_closest_point already
has.
This commit is contained in:
Matthias Clasen
2020-11-26 14:21:53 -05:00
parent 0ede4fd2fb
commit 06c866b99f

View File

@@ -1003,6 +1003,9 @@ gsk_standard_contour_measure_add_point (const graphene_point_t *from,
float seg_length;
seg_length = graphene_point_distance (from, to, NULL, NULL);
if (seg_length == 0)
return;
decomp->measure.end += seg_length;
decomp->measure.start_progress = from_progress;
decomp->measure.end_progress = to_progress;
@@ -1140,6 +1143,18 @@ gsk_standard_contour_get_point (const GskContour *contour,
float progress;
GskStandardContourMeasure *measure;
if (array->len == 0)
{
/* This is the special case for point-only */
if (pos)
*pos = self->points[0];
if (tangent)
*tangent = *graphene_vec2_x_axis ();
return;
}
if (!g_array_binary_search (array, &distance, gsk_standard_contour_find_measure, &index))
index = array->len - 1;
measure = &g_array_index (array, GskStandardContourMeasure, index);