1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/* Copyright (C) 1992, 1993 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this software; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ir.h"
int
xx_IRencloses (xx_IntRectangle r1, xx_IntRectangle r2)
{
return (xx_IRhits_point (r1, xx_IRllx (r2), xx_IRlly (r2))
&& (!xx_IRw (r2) || !xx_IRh (r2)
|| (xx_IRhits_point (r1, xx_IRurx (r2), xx_IRlly (r2))
&& xx_IRhits_point (r1, xx_IRllx (r2), xx_IRury (r2))
&& xx_IRhits_point (r1, xx_IRurx (r2), xx_IRury (r2)))));
}
int
xx_IRencloses_width (xx_IntRectangle r1, xx_IntRectangle r2)
{
return (xx_IRhits_point (r1, xx_IRllx (r2), xx_IRlly (r1))
&& (!xx_IRw (r2)
|| (xx_IRhits_point (r1, xx_IRurx (r2), xx_IRlly (r1)))));
}
int
xx_IRequiv (xx_IntRectangle r1, xx_IntRectangle r2)
{
return (xx_IRllx (r2) == xx_IRllx (r1) &&
xx_IRlly (r2) == xx_IRlly (r1) &&
xx_IRurx (r2) == xx_IRurx (r1) &&
xx_IRury (r2) == xx_IRury (r1));
}
#define MAX(A,B) ((A) > (B) ? (A) : (B))
#define MIN(A,B) ((A) < (B) ? (A) : (B))
#define ROUND(F) (int)((F) + 0.5)
void
xx_IRbound (xx_IntRectangle r1, xx_IntRectangle r2)
{
int x, y;
int X, Y;
x = MIN (xx_IRllx (r1), xx_IRllx (r2));
y = MIN (xx_IRlly (r1), xx_IRlly (r2));
X = MAX (xx_IRurx (r1), xx_IRurx (r2));
Y = MAX (xx_IRury (r1), xx_IRury (r2));
r1->x = x;
r1->y = y;
r1->w = X - x + 1;
r1->h = Y - y + 1;
}
int
xx_IRarea (xx_IntRectangle r)
{
return r->w * r->h;
}
int
xx_IRhits_point (xx_IntRectangle rect, int x, int y)
{
return (x >= rect->x
&& y >= rect->y
&& x < rect->x + rect->w
&& y < rect->y + rect->h);
}
void
xx_IRclip (xx_IntRectangle r1, xx_IntRectangle r2)
{
int x = MAX (r1->x, r2->x);
int y = MAX (r1->y, r2->y);
int X = MIN (xx_IRurx (r1), xx_IRurx (r2));
int Y = MIN (xx_IRury (r1), xx_IRury (r2));
int t;
r1->x = x;
r1->y = y;
t = X - x + 1;
if (t < 0)
r1->w = 0;
else
r1->w = t;
t = Y - y + 1;
if (t < 0)
r1->h = 0;
else
r1->h = t;
}
int
xx_IRsubtract (xx_IntRectangle outv, xx_IntRectangle a, xx_IntRectangle b)
{
struct xx_sIntRectangle arect;
struct xx_sIntRectangle brect;
int outp = 0;
if (!(a->w && a->h))
return 0;
if (!(b->w && b->h))
{
*outv = *a;
return 1;
}
arect = *a;
brect = *b;
xx_IRclip (&brect, &arect);
if (xx_IRhits_point (&arect,
xx_IRllx (&brect),
xx_IRlly (&brect)))
{
/*
-----------------.
| |//////brect
| |////////|
| |---------
| I | II |
| | |
----------------- arect
*/
/* I */
outv[outp] = arect;
outv[outp].w = xx_IRllx (&brect) - xx_IRllx (&arect);
if (outv[outp].w)
++outp;
/* II */
outv[outp] = arect;
outv[outp].x = xx_IRllx (&brect);
outv[outp].w = xx_IRurx (&arect) - xx_IRllx (&brect) + 1;
outv[outp].h = xx_IRlly (&brect) - xx_IRlly (&arect);
if (outv[outp].h)
++outp;
arect.w = xx_IRurx (&arect) - xx_IRllx (&brect) + 1;
arect.h = xx_IRury (&arect) - xx_IRlly (&brect) + 1;
arect.x = xx_IRllx (&brect);
arect.y = xx_IRlly (&brect);
}
if (xx_IRhits_point (&arect,
xx_IRurx (&brect),
xx_IRury (&brect)))
{
/*
--------------
| I | arect
|--------------|
|////////| |
|////////| II |
--------------
brect
*/
/* I */
outv[outp] = arect;
outv[outp].h = xx_IRury (&arect) - xx_IRury (&brect);
outv[outp].y = xx_IRury (&brect) + 1;
if (outv[outp].h)
++outp;
/* II */
outv[outp] = arect;
outv[outp].h = xx_IRury (&brect) - xx_IRlly (&arect) + 1;
outv[outp].w = xx_IRurx (&arect) - xx_IRurx (&brect);
outv[outp].x = xx_IRurx (&brect) + 1;
if (outv[outp].w)
++outp;
}
return outp;
}
|