1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this library; if not, write to the
18
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
* Boston, MA 02111-1307, USA.
26
#include "gimprectangle.h"
30
* gimp_rectangle_intersect:
31
* @x1: origin of first rectangle
32
* @y1: origin of first rectangle
33
* @width1: width of first rectangle
34
* @height1: height of first rectangle
35
* @x2: origin of second rectangle
36
* @y2: origin of second rectangle
37
* @width2: width of second rectangle
38
* @height2: height of second rectangle
39
* @dest_x: return location for origin of intersection (may be %NULL)
40
* @dest_y: return location for origin of intersection (may be %NULL)
41
* @dest_width: return location for width of intersection (may be %NULL)
42
* @dest_height: return location for height of intersection (may be %NULL)
44
* Calculates the intersection of two rectangles.
46
* Return value: %TRUE if the intersection is non-empty, %FALSE otherwise
51
gimp_rectangle_intersect (gint x1,
69
d_w = MIN (x1 + width1, x2 + width2) - d_x;
70
d_h = MIN (y1 + height1, y2 + height2) - d_y;
72
if (dest_x) *dest_x = d_x;
73
if (dest_y) *dest_y = d_y;
74
if (dest_width) *dest_width = d_w;
75
if (dest_height) *dest_height = d_h;
77
return (d_w > 0 && d_h > 0);