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