~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to libgimpbase/gimprectangle.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimprectangle.c
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <glib.h>
 
25
 
 
26
#include "gimprectangle.h"
 
27
 
 
28
 
 
29
/**
 
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)
 
43
 *
 
44
 * Calculates the intersection of two rectangles.
 
45
 *
 
46
 * Return value: %TRUE if the intersection is non-empty, %FALSE otherwise
 
47
 *
 
48
 * Since: GIMP 2.4
 
49
 */
 
50
gboolean
 
51
gimp_rectangle_intersect (gint  x1,
 
52
                          gint  y1,
 
53
                          gint  width1,
 
54
                          gint  height1,
 
55
                          gint  x2,
 
56
                          gint  y2,
 
57
                          gint  width2,
 
58
                          gint  height2,
 
59
                          gint *dest_x,
 
60
                          gint *dest_y,
 
61
                          gint *dest_width,
 
62
                          gint *dest_height)
 
63
{
 
64
  gint d_x, d_y;
 
65
  gint d_w, d_h;
 
66
 
 
67
  d_x = MAX (x1, x2);
 
68
  d_y = MAX (y1, y2);
 
69
  d_w = MIN (x1 + width1,  x2 + width2)  - d_x;
 
70
  d_h = MIN (y1 + height1, y2 + height2) - d_y;
 
71
 
 
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;
 
76
 
 
77
  return (d_w > 0 && d_h > 0);
 
78
}