mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-23 20:30:15 +00:00
Improve precondition checks for path points
Add a helper function for checking that a path point is valid for a path, and use it.
This commit is contained in:
parent
2e24a9ece4
commit
5a3ed65ad8
@ -1401,10 +1401,8 @@ gsk_path_builder_add_segment (GskPathBuilder *self,
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
g_return_if_fail (start != NULL);
|
||||
g_return_if_fail (end != NULL);
|
||||
g_return_if_fail (start->contour < n_contours);
|
||||
g_return_if_fail (end->contour < n_contours);
|
||||
g_return_if_fail (gsk_path_point_valid (start, path));
|
||||
g_return_if_fail (gsk_path_point_valid (end, path));
|
||||
|
||||
current = self->current_point;
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "gskpathmeasure.h"
|
||||
|
||||
#include "gskpathbuilder.h"
|
||||
#include "gskpathpoint.h"
|
||||
#include "gskpathpointprivate.h"
|
||||
#include "gskcontourprivate.h"
|
||||
#include "gskpathprivate.h"
|
||||
|
||||
@ -312,9 +312,8 @@ gsk_path_point_get_distance (const GskPathPoint *point,
|
||||
const GskContour *contour;
|
||||
float contour_offset = 0;
|
||||
|
||||
g_return_val_if_fail (point != NULL, 0);
|
||||
g_return_val_if_fail (measure != NULL, 0);
|
||||
g_return_val_if_fail (point->contour < measure->n_contours, 0);
|
||||
g_return_val_if_fail (gsk_path_point_valid (point, measure->path), 0);
|
||||
|
||||
contour = gsk_path_get_contour (measure->path, point->contour);
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "gskpathpoint.h"
|
||||
#include "gskpathpointprivate.h"
|
||||
#include "gskcontourprivate.h"
|
||||
#include "gdk/gdkprivate.h"
|
||||
|
||||
@ -156,10 +156,9 @@ gsk_path_point_get_position (const GskPathPoint *point,
|
||||
{
|
||||
const GskContour *contour;
|
||||
|
||||
g_return_if_fail (point != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
g_return_if_fail (gsk_path_point_valid (point, path));
|
||||
g_return_if_fail (position != NULL);
|
||||
g_return_if_fail (point->contour < gsk_path_get_n_contours (path));
|
||||
|
||||
contour = gsk_path_get_contour (path, point->contour),
|
||||
gsk_contour_get_position (contour, point, position);
|
||||
@ -195,10 +194,9 @@ gsk_path_point_get_tangent (const GskPathPoint *point,
|
||||
{
|
||||
const GskContour *contour;
|
||||
|
||||
g_return_if_fail (point != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
g_return_if_fail (gsk_path_point_valid (point, path));
|
||||
g_return_if_fail (tangent != NULL);
|
||||
g_return_if_fail (point->contour < gsk_path_get_n_contours (path));
|
||||
|
||||
contour = gsk_path_get_contour (path, point->contour),
|
||||
gsk_contour_get_tangent (contour, point, direction, tangent);
|
||||
@ -228,9 +226,8 @@ gsk_path_point_get_rotation (const GskPathPoint *point,
|
||||
{
|
||||
graphene_vec2_t tangent;
|
||||
|
||||
g_return_val_if_fail (point != NULL, 0);
|
||||
g_return_val_if_fail (path != NULL, 0);
|
||||
g_return_val_if_fail (point->contour < gsk_path_get_n_contours (path), 0);
|
||||
g_return_val_if_fail (gsk_path_point_valid (point, path), 0);
|
||||
|
||||
gsk_path_point_get_tangent (point, path, direction, &tangent);
|
||||
|
||||
@ -279,9 +276,8 @@ gsk_path_point_get_curvature (const GskPathPoint *point,
|
||||
{
|
||||
const GskContour *contour;
|
||||
|
||||
g_return_val_if_fail (point != NULL, 0);
|
||||
g_return_val_if_fail (path != NULL, 0);
|
||||
g_return_val_if_fail (point->contour < gsk_path_get_n_contours (path), 0);
|
||||
g_return_val_if_fail (gsk_path_point_valid (point, path), 0);
|
||||
|
||||
contour = gsk_path_get_contour (path, point->contour);
|
||||
return gsk_contour_get_curvature (contour, point, direction, center);
|
||||
|
@ -7,5 +7,33 @@ G_BEGIN_DECLS
|
||||
|
||||
#define GSK_PATH_POINT_INIT(c,i,tt) ((GskPathPoint){ .contour=(c), .idx=(i), .t=(tt) })
|
||||
|
||||
static inline gboolean
|
||||
gsk_path_point_valid (const GskPathPoint *point,
|
||||
GskPath *path)
|
||||
{
|
||||
const GskContour *contour;
|
||||
gsize n_ops;
|
||||
|
||||
if (point == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (path == NULL)
|
||||
return TRUE;
|
||||
|
||||
if (point->contour >= gsk_path_get_n_contours (path))
|
||||
return FALSE;
|
||||
|
||||
contour = gsk_path_get_contour (path, point->contour);
|
||||
n_ops = gsk_contour_get_n_ops (contour);
|
||||
if ((n_ops > 1 && point->idx >= n_ops) ||
|
||||
(n_ops == 1 && point->idx > n_ops))
|
||||
return FALSE;
|
||||
|
||||
if (point->t < 0 || point->t > 1)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user