diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2011-01-09 04:35:10 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2011-01-09 04:35:10 +0100 |
commit | 2328058b46f8dd1f2a80b860e49f89ec0a80a660 (patch) | |
tree | 4308b5b8608dd6b01222c8deb828585a452a319c | |
parent | fe996324d365f3a35e59dda8e10db5327de444e8 (diff) | |
download | logdiag-2328058b46f8dd1f2a80b860e49f89ec0a80a660.tar.gz logdiag-2328058b46f8dd1f2a80b860e49f89ec0a80a660.tar.xz logdiag-2328058b46f8dd1f2a80b860e49f89ec0a80a660.zip |
Add ld_point_distance().
-rw-r--r-- | src/ld-types.c | 22 | ||||
-rw-r--r-- | src/ld-types.h | 1 |
2 files changed, 23 insertions, 0 deletions
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 <math.h> + #include <gtk/gtk.h> #include "config.h" @@ -71,6 +73,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. * diff --git a/src/ld-types.h b/src/ld-types.h index 6837f74..61a1a7d 100644 --- a/src/ld-types.h +++ b/src/ld-types.h @@ -48,6 +48,7 @@ GType ld_point_get_type (void) G_GNUC_CONST; LdPoint *ld_point_copy (const LdPoint *self); void ld_point_free (LdPoint *self); +gdouble ld_point_distance (LdPoint *self, gdouble x, gdouble y); /** |