1 package com.artifex.mupdf.fitz; 2 3 public class RectI 4 { 5 public int x0; 6 public int y0; 7 public int x1; 8 public int y1; 9 RectI()10 public RectI() 11 { 12 x0 = y0 = x1 = y1 = 0; 13 } 14 RectI(int x0, int y0, int x1, int y1)15 public RectI(int x0, int y0, int x1, int y1) { 16 this.x0 = x0; 17 this.y0 = y0; 18 this.x1 = x1; 19 this.y1 = y1; 20 } 21 RectI(RectI r)22 public RectI(RectI r) { 23 this(r.x0, r.y0, r.x1, r.y1); 24 } 25 RectI(Rect r)26 public RectI(Rect r) { 27 this.x0 = (int)Math.floor(r.x0); 28 this.y0 = (int)Math.ceil(r.y0); 29 this.x1 = (int)Math.floor(r.x1); 30 this.y1 = (int)Math.ceil(r.y1); 31 } 32 toString()33 public String toString() { 34 return "[" + x0 + " " + y0 + " " + x1 + " " + y1 + "]"; 35 } 36 transform(Matrix tm)37 public RectI transform(Matrix tm) { 38 float ax0 = x0 * tm.a; 39 float ax1 = x1 * tm.a; 40 41 if (ax0 > ax1) { 42 float t = ax0; 43 ax0 = ax1; 44 ax1 = t; 45 } 46 47 float cy0 = y0 * tm.c; 48 float cy1 = y1 * tm.c; 49 50 if (cy0 > cy1) { 51 float t = cy0; 52 cy0 = cy1; 53 cy1 = t; 54 } 55 ax0 += cy0 + tm.e; 56 ax1 += cy1 + tm.e; 57 58 float bx0 = x0 * tm.b; 59 float bx1 = x1 * tm.b; 60 61 if (bx0 > bx1) { 62 float t = bx0; 63 bx0 = bx1; 64 bx1 = t; 65 } 66 67 float dy0 = y0 * tm.d; 68 float dy1 = y1 * tm.d; 69 70 if (dy0 > dy1) { 71 float t = dy0; 72 dy0 = dy1; 73 dy1 = t; 74 } 75 bx0 += dy0 + tm.f; 76 bx1 += dy1 + tm.f; 77 78 x0 = (int)Math.floor(ax0); 79 x1 = (int)Math.ceil(ax1); 80 y0 = (int)Math.floor(bx0); 81 y1 = (int)Math.ceil(bx1); 82 83 return this; 84 } 85 contains(int x, int y)86 public boolean contains(int x, int y) 87 { 88 if (isEmpty()) 89 return false; 90 91 return (x >= x0 && x < x1 && y >= y0 && y < y1); 92 } 93 contains(Rect r)94 public boolean contains(Rect r) 95 { 96 if (isEmpty() || r.isEmpty()) 97 return false; 98 99 return (r.x0 >= x0 && r.x1 <= x1 && r.y0 >= y0 && r.y1 <= y1); 100 } 101 isEmpty()102 public boolean isEmpty() 103 { 104 return (x0 == x1 || y0 == y1); 105 } 106 union(RectI r)107 public void union(RectI r) 108 { 109 if (isEmpty()) 110 { 111 x0 = r.x0; 112 y0 = r.y0; 113 x1 = r.x1; 114 y1 = r.y1; 115 } 116 else 117 { 118 if (r.x0 < x0) 119 x0 = r.x0; 120 if (r.y0 < y0) 121 y0 = r.y0; 122 if (r.x1 > x1) 123 x1 = r.x1; 124 if (r.y1 > y1) 125 y1 = r.y1; 126 } 127 } 128 } 129