From f5f82c3b29df1f5bd07d9246e56dca25dbfe7b47 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Mon, 11 Mar 2013 12:20:20 +0100 Subject: [PATCH] cpml: return if a point exist in CpmlPrimitive Return a flag from cpml_primitive_{set,put}_point() indicating if the point is found. --- src/cpml/cpml-primitive.c | 28 +++++++++++++++++++++------- src/cpml/cpml-primitive.h | 4 ++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/cpml/cpml-primitive.c b/src/cpml/cpml-primitive.c index ecae1ca6..2c313c90 100644 --- a/src/cpml/cpml-primitive.c +++ b/src/cpml/cpml-primitive.c @@ -303,38 +303,52 @@ cpml_primitive_put_extents(const CpmlPrimitive *primitive, * of a close path is a valid operation and must returns the origin * of the segment. * + * Returns: (type gboolean): %1 if the point to be set is existent, %0 otherwise. + * * Since: 1.0 **/ -void +int cpml_primitive_set_point(CpmlPrimitive *primitive, int n_point, const CpmlPair *pair) { cairo_path_data_t *point = _cpml_get_point(primitive, n_point); - if (point != NULL && pair != NULL) + if (point == NULL) + return 0; + + if (pair != NULL) cpml_pair_to_cairo(pair, point); + + return 1; } /** * cpml_primitive_put_point: - * @primitive: a #CpmlPrimitive - * @n_point: the index of the point to retrieve - * @pair: (out caller-allocates): the destination #CpmlPair + * @primitive: a #CpmlPrimitive + * @n_point: the index of the point to retrieve + * @pair: (out caller-allocates) (allow-none): the destination #CpmlPair * * Gets the specified @n_point from @primitive and stores it into * @pair. The @n_point index is subject to the same rules explained * in the cpml_primitive_set_point() function. * + * Returns: (type gboolean): %1 if the point is found, %0 otherwise. + * * Since: 1.0 **/ -void +int cpml_primitive_put_point(const CpmlPrimitive *primitive, int n_point, CpmlPair *pair) { const cairo_path_data_t *point = _cpml_get_point(primitive, n_point); - if (point != NULL) + if (point == NULL) + return 0; + + if (pair != NULL) cpml_pair_from_cairo(pair, point); + + return 1; } /** diff --git a/src/cpml/cpml-primitive.h b/src/cpml/cpml-primitive.h index b5038dde..b35a8e1a 100644 --- a/src/cpml/cpml-primitive.h +++ b/src/cpml/cpml-primitive.h @@ -58,10 +58,10 @@ size_t cpml_primitive_get_n_points(const CpmlPrimitive *primitive); double cpml_primitive_get_length (const CpmlPrimitive *primitive); void cpml_primitive_put_extents (const CpmlPrimitive *primitive, CpmlExtents *extents); -void cpml_primitive_set_point (CpmlPrimitive *primitive, +int cpml_primitive_set_point (CpmlPrimitive *primitive, int n_point, const CpmlPair *pair); -void cpml_primitive_put_point (const CpmlPrimitive *primitive, +int cpml_primitive_put_point (const CpmlPrimitive *primitive, int n_point, CpmlPair *pair); void cpml_primitive_put_pair_at (const CpmlPrimitive *primitive, -- 2.11.4.GIT