nautilus-3.6.3/eel/eel-art-extensions.c

No issues found

  1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
  2 
  3 /* eel-art-extensions.c - implementation of libart extension functions.
  4 
  5    Copyright (C) 2000 Eazel, Inc.
  6 
  7    The Gnome Library is free software; you can redistribute it and/or
  8    modify it under the terms of the GNU Library General Public License as
  9    published by the Free Software Foundation; either version 2 of the
 10    License, or (at your option) any later version.
 11 
 12    The Gnome Library is distributed in the hope that it will be useful,
 13    but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15    Library General Public License for more details.
 16 
 17    You should have received a copy of the GNU Library General Public
 18    License along with the Gnome Library; see the file COPYING.LIB.  If not,
 19    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 20    Boston, MA 02111-1307, USA.
 21 
 22    Authors: Darin Adler <darin@eazel.com>
 23             Ramiro Estrugo <ramiro@eazel.com>
 24 */
 25 
 26 #include <config.h>
 27 
 28 #include "eel-art-extensions.h"
 29 #include "eel-lib-self-check-functions.h"
 30 #include <math.h>
 31 
 32 const EelDRect eel_drect_empty = { 0.0, 0.0, 0.0, 0.0 };
 33 const EelIRect eel_irect_empty = { 0, 0, 0, 0 };
 34 
 35 void
 36 eel_irect_copy (EelIRect *dest, const EelIRect *src)
 37 {
 38 	dest->x0 = src->x0;
 39 	dest->y0 = src->y0;
 40 	dest->x1 = src->x1;
 41 	dest->y1 = src->y1;
 42 }
 43 
 44 void
 45 eel_irect_union (EelIRect *dest,
 46 		  const EelIRect *src1,
 47 		  const EelIRect *src2) {
 48 	if (eel_irect_is_empty (src1)) {
 49 		eel_irect_copy (dest, src2);
 50 	} else if (eel_irect_is_empty (src2)) {
 51 		eel_irect_copy (dest, src1);
 52 	} else {
 53 		dest->x0 = MIN (src1->x0, src2->x0);
 54 		dest->y0 = MIN (src1->y0, src2->y0);
 55 		dest->x1 = MAX (src1->x1, src2->x1);
 56 		dest->y1 = MAX (src1->y1, src2->y1);
 57 	}
 58 }
 59 
 60 void
 61 eel_irect_intersect (EelIRect *dest,
 62 		     const EelIRect *src1,
 63 		     const EelIRect *src2)
 64 {
 65 	dest->x0 = MAX (src1->x0, src2->x0);
 66 	dest->y0 = MAX (src1->y0, src2->y0);
 67 	dest->x1 = MIN (src1->x1, src2->x1);
 68 	dest->y1 = MIN (src1->y1, src2->y1);
 69 }
 70 
 71 gboolean
 72 eel_irect_is_empty (const EelIRect *src)
 73 {
 74 	return (src->x1 <= src->x0 ||
 75 		src->y1 <= src->y0);
 76 }
 77 
 78 /**
 79  * eel_irect_get_width:
 80  * 
 81  * @rectangle: An EelIRect.
 82  *
 83  * Returns: The width of the rectangle.
 84  * 
 85  */
 86 int
 87 eel_irect_get_width (EelIRect rectangle)
 88 {
 89 	return rectangle.x1 - rectangle.x0;
 90 }
 91 
 92 /**
 93  * eel_irect_get_height:
 94  * 
 95  * @rectangle: An EelIRect.
 96  *
 97  * Returns: The height of the rectangle.
 98  * 
 99  */
100 int
101 eel_irect_get_height (EelIRect rectangle)
102 {
103 	return rectangle.y1 - rectangle.y0;
104 }
105 
106 
107 static void
108 eel_drect_copy (EelDRect *dest,
109 		const EelDRect *src)
110 {
111 	dest->x0 = src->x0;
112 	dest->y0 = src->y0;
113 	dest->x1 = src->x1;
114 	dest->y1 = src->y1;
115 }
116 
117 static gboolean
118 eel_drect_is_empty (const EelDRect *src)
119 {
120 	return (src->x1 <= src->x0 || src->y1 <= src->y0);
121 }
122 
123 void
124 eel_drect_union (EelDRect *dest,
125 		 const EelDRect *src1,
126 		 const EelDRect *src2)
127 {
128 	if (eel_drect_is_empty (src1)) {
129 		eel_drect_copy (dest, src2);
130 	} else if (eel_drect_is_empty (src2)) {
131 		eel_drect_copy (dest, src1);
132 	} else {
133 		dest->x0 = MIN (src1->x0, src2->x0);
134 		dest->y0 = MIN (src1->y0, src2->y0);
135 		dest->x1 = MAX (src1->x1, src2->x1);
136 		dest->y1 = MAX (src1->y1, src2->y1);
137 	}
138 }
139 
140 
141 /**
142  * eel_irect_contains_point:
143  * 
144  * @rectangle: An EelIRect.
145  * @x: X coordinate to test.
146  * @y: Y coordinate to test.
147  *
148  * Returns: A boolean value indicating whether the rectangle 
149  *          contains the x,y coordinate.
150  * 
151  */
152 gboolean
153 eel_irect_contains_point (EelIRect rectangle,
154 			  int x,
155 			  int y)
156 {
157 	return x >= rectangle.x0
158 		&& x <= rectangle.x1
159 		&& y >= rectangle.y0
160 		&& y <= rectangle.y1;
161 }
162 
163 gboolean
164 eel_irect_hits_irect (EelIRect rectangle_a,
165 			  EelIRect rectangle_b)
166 {
167 	EelIRect intersection;
168 	eel_irect_intersect (&intersection, &rectangle_a, &rectangle_b);
169 	return !eel_irect_is_empty (&intersection);
170 }
171 
172 gboolean
173 eel_irect_equal (EelIRect rectangle_a,
174 		     EelIRect rectangle_b)
175 {
176 	return rectangle_a.x0 == rectangle_b.x0
177 		&& rectangle_a.y0 == rectangle_b.y0
178 		&& rectangle_a.x1 == rectangle_b.x1
179 		&& rectangle_a.y1 == rectangle_b.y1;
180 }
181 
182 EelIRect 
183 eel_irect_offset_by (EelIRect rectangle, int x, int y)
184 {
185 	rectangle.x0 += x;
186 	rectangle.x1 += x;
187 	rectangle.y0 += y;
188 	rectangle.y1 += y;
189 	
190 	return rectangle;
191 }
192 
193 EelIRect 
194 eel_irect_scale_by (EelIRect rectangle, double scale)
195 {
196 	rectangle.x0 *= scale;
197 	rectangle.x1 *= scale;
198 	rectangle.y0 *= scale;
199 	rectangle.y1 *= scale;
200 	
201 	return rectangle;
202 }