summaryrefslogtreecommitdiff
path: root/base/base_rect.c
diff options
context:
space:
mode:
authorTor Andersson <tor@ghostscript.com>2005-03-30 08:30:22 +0200
committerTor Andersson <tor@ghostscript.com>2005-03-30 08:30:22 +0200
commitee154f16bd09a43359967f7e7b86c3677c09461d (patch)
tree08896cfa9ff55e05bfe7855965c620d45115d4d5 /base/base_rect.c
parent460ad7040d67a4a93a153f98095ff952a2b15d37 (diff)
downloadmupdf-ee154f16bd09a43359967f7e7b86c3677c09461d.tar.xz
rename part 1 -- files
Diffstat (limited to 'base/base_rect.c')
-rw-r--r--base/base_rect.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/base/base_rect.c b/base/base_rect.c
new file mode 100644
index 00000000..2efb11f7
--- /dev/null
+++ b/base/base_rect.c
@@ -0,0 +1,75 @@
+#include <fitz.h>
+
+fz_rect fz_infiniterect = { { 1, 1}, {-1, -1} };
+fz_rect fz_emptyrect = { { 0, 0}, {0, 0} };
+
+static fz_irect infinite = { { 1, 1}, {-1, -1} };
+static fz_irect empty = { { 0, 0}, {0, 0} };
+
+fz_irect
+fz_roundrect(fz_rect f)
+{
+ fz_irect i;
+ i.min.x = fz_floor(f.min.x);
+ i.min.y = fz_floor(f.min.y);
+ i.max.x = fz_ceil(f.max.x);
+ i.max.y = fz_ceil(f.max.y);
+ return i;
+}
+
+fz_rect
+fz_intersectrects(fz_rect a, fz_rect b)
+{
+ fz_rect r;
+ if (fz_isinfiniterect(a)) return b;
+ if (fz_isinfiniterect(b)) return a;
+ r.min.x = MAX(a.min.x, b.min.x);
+ r.min.y = MAX(a.min.y, b.min.y);
+ r.max.x = MIN(a.max.x, b.max.x);
+ r.max.y = MIN(a.max.y, b.max.y);
+ return (r.max.x < r.min.x || r.max.y < r.min.y) ? fz_emptyrect : r;
+}
+
+fz_rect
+fz_mergerects(fz_rect a, fz_rect b)
+{
+ fz_rect r;
+ if (fz_isinfiniterect(a) || fz_isinfiniterect(b))
+ return fz_infiniterect;
+ if (fz_isemptyrect(a)) return b;
+ if (fz_isemptyrect(b)) return a;
+ r.min.x = MIN(a.min.x, b.min.x);
+ r.min.y = MIN(a.min.y, b.min.y);
+ r.max.x = MAX(a.max.x, b.max.x);
+ r.max.y = MAX(a.max.y, b.max.y);
+ return r;
+}
+
+fz_irect
+fz_intersectirects(fz_irect a, fz_irect b)
+{
+ fz_irect r;
+ if (fz_isinfiniterect(a)) return b;
+ if (fz_isinfiniterect(b)) return a;
+ r.min.x = MAX(a.min.x, b.min.x);
+ r.min.y = MAX(a.min.y, b.min.y);
+ r.max.x = MIN(a.max.x, b.max.x);
+ r.max.y = MIN(a.max.y, b.max.y);
+ return (r.max.x < r.min.x || r.max.y < r.min.y) ? empty : r;
+}
+
+fz_irect
+fz_mergeirects(fz_irect a, fz_irect b)
+{
+ fz_irect r;
+ if (fz_isinfiniterect(a) || fz_isinfiniterect(b))
+ return infinite;
+ if (fz_isemptyrect(a)) return b;
+ if (fz_isemptyrect(b)) return a;
+ r.min.x = MIN(a.min.x, b.min.x);
+ r.min.y = MIN(a.min.y, b.min.y);
+ r.max.x = MAX(a.max.x, b.max.x);
+ r.max.y = MAX(a.max.y, b.max.y);
+ return r;
+}
+