rect contour: Avoid nans in corner cases
The length of rect contours can be zero, so we much check before we divide.
This commit is contained in:
@@ -1467,6 +1467,8 @@ gsk_circle_contour_new (const graphene_point_t *center,
|
||||
{
|
||||
GskCircleContour *self;
|
||||
|
||||
g_assert (radius > 0);
|
||||
|
||||
self = g_new0 (GskCircleContour, 1);
|
||||
|
||||
self->contour.klass = &GSK_CIRCLE_CONTOUR_CLASS;
|
||||
@@ -1700,7 +1702,10 @@ gsk_rect_contour_get_closest_point (const GskContour *contour,
|
||||
if (gsk_rect_contour_closest_point (self, point, threshold, out_dist, &distance))
|
||||
{
|
||||
result->idx = 1;
|
||||
result->t = distance / self->length;
|
||||
if (self->length == 0)
|
||||
result->t = 0;
|
||||
else
|
||||
result->t = distance / self->length;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -1961,7 +1966,10 @@ gsk_rect_contour_get_point (const GskContour *contour,
|
||||
const GskRectContour *self = (const GskRectContour *) contour;
|
||||
|
||||
result->idx = 1;
|
||||
result->t = CLAMP (distance / self->length, 0, 1);
|
||||
if (self->length == 0)
|
||||
result->t = 0;
|
||||
else
|
||||
result->t = CLAMP (distance / self->length, 0, 1);
|
||||
}
|
||||
|
||||
static float
|
||||
|
||||
@@ -603,6 +603,7 @@ gsk_path_get_closest_point (GskPath *self,
|
||||
if (gsk_contour_get_closest_point (self->contours[i], point, threshold, res, &distance))
|
||||
{
|
||||
found = TRUE;
|
||||
g_assert (0 <= res->t && res->t <= 1);
|
||||
res->contour = i;
|
||||
threshold = distance;
|
||||
}
|
||||
|
||||
@@ -285,6 +285,9 @@ gsk_path_measure_get_point (GskPathMeasure *self,
|
||||
contour = gsk_path_get_contour (self->path, i);
|
||||
|
||||
gsk_contour_get_point (contour, self->measures[i].contour_data, distance, res);
|
||||
|
||||
g_assert (0 <= res->t && res->t <= 1);
|
||||
|
||||
res->contour = i;
|
||||
|
||||
return TRUE;
|
||||
|
||||
Reference in New Issue
Block a user