From 1277b6eaaffc08076f9d9440693f201fb61072e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Mon, 7 Feb 2011 01:10:17 +0100 Subject: Add support for LdDiagramConnection to LdCanvas. Heavy LdCanvas refactoring, some modifications to ld-types. It just wasn't possible for me to further work with an old, 2000 lines long file without shuffling everything around at the same time. --- liblogdiag/ld-types.c | 52 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'liblogdiag/ld-types.c') diff --git a/liblogdiag/ld-types.c b/liblogdiag/ld-types.c index 7721e36..d7e3dfb 100644 --- a/liblogdiag/ld-types.c +++ b/liblogdiag/ld-types.c @@ -90,7 +90,7 @@ DEFINE_BOXED_TRIVIAL_FREE (LdPoint, ld_point) * Compute the distance between two points. */ gdouble -ld_point_distance (LdPoint *self, gdouble x, gdouble y) +ld_point_distance (const LdPoint *self, gdouble x, gdouble y) { gdouble dx, dy; @@ -292,38 +292,58 @@ DEFINE_BOXED_TRIVIAL_COPY (LdRectangle, ld_rectangle) DEFINE_BOXED_TRIVIAL_FREE (LdRectangle, ld_rectangle) /** - * ld_rectangle_contains: + * ld_rectangle_intersects: * @self: an #LdRectangle structure. - * @x: the X coordinate of the point to be checked. - * @y: the Y coordinate of the point to be checked. + * @rect: an #LdRectangle to be checked for intersection. * - * Return value: %TRUE if the rectangle contains the specified point. + * Return value: %TRUE if the two rectangles intersect. */ gboolean -ld_rectangle_contains (LdRectangle *self, gdouble x, gdouble y) +ld_rectangle_intersects (const LdRectangle *self, const LdRectangle *rect) { g_return_val_if_fail (self != NULL, FALSE); - return (x >= self->x && x <= self->x + self->width - && y >= self->y && y <= self->y + self->height); + g_return_val_if_fail (rect != NULL, FALSE); + + return !(self->x > rect->x + rect->width + || self->y > rect->y + rect->height + || self->x + self->width < rect->x + || self->y + self->height < rect->y); } /** - * ld_rectangle_intersects: + * ld_rectangle_contains: * @self: an #LdRectangle structure. - * @rect: an #LdRectangle to be checked for intersection. + * @rect: an #LdRectangle to be checked for containment. * - * Return value: %TRUE if the two rectangles intersect. + * Return value: %TRUE if @self fully contains @rect. */ gboolean -ld_rectangle_intersects (LdRectangle *self, LdRectangle *rect) +ld_rectangle_contains (const LdRectangle *self, const LdRectangle *rect) { g_return_val_if_fail (self != NULL, FALSE); g_return_val_if_fail (rect != NULL, FALSE); - return !(self->x > rect->x + rect->width - || self->y > rect->y + rect->height - || self->x + self->width < rect->x - || self->y + self->height < rect->y); + return (self->x <= rect->x + && self->y <= rect->y + && self->x + self->width >= rect->x + rect->width + && self->y + self->height >= rect->y + rect->height); +} + +/** + * ld_rectangle_contains_point: + * @self: an #LdRectangle structure. + * @point: the point to be checked. + * + * Return value: %TRUE if the rectangle contains the specified point. + */ +gboolean +ld_rectangle_contains_point (const LdRectangle *self, const LdPoint *point) +{ + g_return_val_if_fail (self != NULL, FALSE); + g_return_val_if_fail (point != NULL, FALSE); + + return (point->x >= self->x && point->x <= self->x + self->width + && point->y >= self->y && point->y <= self->y + self->height); } /** -- cgit v1.2.3