From 2328058b46f8dd1f2a80b860e49f89ec0a80a660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Sun, 9 Jan 2011 04:35:10 +0100 Subject: Add ld_point_distance(). --- src/ld-types.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/ld-types.c') diff --git a/src/ld-types.c b/src/ld-types.c index 512bcef..5bed9dc 100644 --- a/src/ld-types.c +++ b/src/ld-types.c @@ -8,6 +8,8 @@ * */ +#include + #include #include "config.h" @@ -70,6 +72,26 @@ DEFINE_BOXED_TRIVIAL_COPY (LdPoint, ld_point) */ DEFINE_BOXED_TRIVIAL_FREE (LdPoint, ld_point) +/** + * ld_point_distance: + * @self: An #LdPoint structure. + * @x: The X coordinate of the second point. + * @y: The Y coordinate of the second point. + * + * Compute the distance between two points. + */ +gdouble +ld_point_distance (LdPoint *self, gdouble x, gdouble y) +{ + gdouble dx, dy; + + g_return_val_if_fail (self != NULL, -1); + + dx = self->x - x; + dy = self->y - y; + return sqrt (dx * dx + dy * dy); +} + /** * ld_point_array_new: * @num_points: The number of points the array can store. -- cgit v1.2.3