Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/docs/reference/c/fitz/math.md @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 # Math | |
| 2 | |
| 3 We obviously need to deal with lots of points, rectangles, and transformations | |
| 4 in MuPDF. | |
| 5 | |
| 6 ## fz_point | |
| 7 | |
| 8 Points are fairly self evident. The `fz_make_point` utility function is for use | |
| 9 with Visual Studio that doesn't yet support the C99 struct initializer syntax. | |
| 10 | |
| 11 typedef struct { | |
| 12 float x, y; | |
| 13 } fz_point; | |
| 14 | |
| 15 fz_point fz_make_point(float x, float y); | |
| 16 | |
| 17 ## fz_rect and fz_irect | |
| 18 | |
| 19 Rectangles are represented by two pairs of coordinates. The `x0`, `y0` pair | |
| 20 have the smallest values, and in the normal coordinate space used by MuPDF that | |
| 21 is the upper left corner. The `x1`, `y1` pair have the largest values, | |
| 22 typically the lower right corner. | |
| 23 | |
| 24 In order to represent an infinite unbounded area, we use an `x0` that is larger | |
| 25 than the `x1`. | |
| 26 | |
| 27 typedef struct { | |
| 28 float x0, y0; | |
| 29 float x1, y1; | |
| 30 } fz_rect; | |
| 31 | |
| 32 const fz_rect fz_infinite_rect = { 1, 1, -1, -1 }; | |
| 33 const fz_rect fz_empty_rect = { 0, 0, 0, 0 }; | |
| 34 const fz_rect fz_unit_rect = { 0, 0, 1, 1 }; | |
| 35 | |
| 36 fz_rect fz_make_rect(float x0, float y0, float x1, float y1); | |
| 37 | |
| 38 ## fz_matrix | |
| 39 | |
| 40 Our matrix structure is a row-major 3x3 matrix with the last column always | |
| 41 `[ 0 0 1 ]`. This is represented as a struct with six fields, in the same order as | |
| 42 in PDF and Postscript. The identity matrix is a global constant, for easy | |
| 43 access. | |
| 44 | |
| 45 / a b 0 \ | |
| 46 | c d 0 | | |
| 47 \ e f 1 / | |
| 48 | |
| 49 typedef struct { | |
| 50 float a, b, c, d, e, f; | |
| 51 } fz_matrix; | |
| 52 | |
| 53 const fz_matrix fz_identity = { 1, 0, 0, 1, 0, 0 }; | |
| 54 | |
| 55 fz_matrix fz_make_matrix(float a, float b, float c, float d, float e, float f); | |
| 56 | |
| 57 ## fz_quad | |
| 58 | |
| 59 Sometimes we need to represent a non-axis aligned rectangular-ish area, such as | |
| 60 the area covered by some rotated text. For this we use a quad representation, | |
| 61 using a points for each of the upper/lower/left/right corners as seen from the | |
| 62 reading direction of the text represented. | |
| 63 | |
| 64 typedef struct { | |
| 65 fz_point ul, ur, ll, lr; | |
| 66 } fz_quad; | |
| 67 | |
| 68 ## List of math functions | |
| 69 | |
| 70 These are simple mathematical operations that can not throw errors, so do not need a context argument. | |
| 71 | |
| 72 `float fz_abs(float f)` | |
| 73 : Abs for float. | |
| 74 | |
| 75 `float fz_min(float a, float b)` | |
| 76 : Min for float. | |
| 77 | |
| 78 `float fz_max(float a, float b)` | |
| 79 : Max for float. | |
| 80 | |
| 81 `float fz_clamp(float f, float min, float max)` | |
| 82 : Clamp for float. | |
| 83 | |
| 84 `int fz_absi(int i)` | |
| 85 : Abs for integer. | |
| 86 | |
| 87 `int fz_mini(int a, int b)` | |
| 88 : Min for integer. | |
| 89 | |
| 90 `int fz_maxi(int a, int b)` | |
| 91 : Max for integer. | |
| 92 | |
| 93 `int fz_clampi(int i, int min, int max)` | |
| 94 : Clamp for integer. | |
| 95 | |
| 96 `int fz_is_empty_rect(fz_rect r)` | |
| 97 : Returns whether the supplied `fz_rect` is empty. | |
| 98 | |
| 99 `int fz_is_infinite_rect(fz_rect r)` | |
| 100 : Returns whether the supplied `fz_rect` is infinite. | |
| 101 | |
| 102 `fz_matrix fz_concat(fz_matrix left, fz_matrix right)` | |
| 103 : Concat two matrices and returns a new matrix. | |
| 104 | |
| 105 `fz_matrix fz_scale(float sx, float sy)` | |
| 106 : Scale. | |
| 107 | |
| 108 `fz_matrix fz_shear(float sx, float sy)` | |
| 109 : Shear. | |
| 110 | |
| 111 `fz_matrix fz_rotate(float degrees)` | |
| 112 : Rotate. | |
| 113 | |
| 114 `fz_matrix fz_translate(float tx, float ty)` | |
| 115 : Translate. | |
| 116 | |
| 117 `fz_matrix fz_invert_matrix(fz_matrix matrix)` | |
| 118 : Invert a matrix. | |
| 119 | |
| 120 `fz_point fz_transform_point(fz_point point, fz_matrix m)` | |
| 121 : Transform a point according to the given matrix. | |
| 122 | |
| 123 `fz_point fz_transform_vector(fz_point vector, fz_matrix m)` | |
| 124 : Transform a vector according to the given matrix (ignores translation). | |
| 125 | |
| 126 `fz_rect fz_transform_rect(fz_rect rect, fz_matrix m)` | |
| 127 : Transform a `fz_rect` according to the given matrix. | |
| 128 | |
| 129 `fz_quad fz_transform_quad(fz_quad q, fz_matrix m)` | |
| 130 : Transform a `fz_quad` according to the given matrix. | |
| 131 | |
| 132 `int fz_is_point_inside_rect(fz_point p, fz_rect r)` | |
| 133 : Returns whether the point is inside the supplied `fz_rect`. | |
| 134 | |
| 135 `int fz_is_point_inside_quad(fz_point p, fz_quad q)` | |
| 136 : Returns whether the point is inside the supplied `fz_quad`. | |
| 137 | |
| 138 `fz_matrix fz_transform_page(fz_rect mediabox, float resolution, float rotate)` | |
| 139 : Create a transform matrix to draw a page at a given resolution and | |
| 140 rotation. The scaling factors are adjusted so that the page covers a | |
| 141 whole number of pixels. Resolution is given in dots per inch. Rotation | |
| 142 is expressed in 90 degree increments (`0`, `90`, `180`, and `270` are | |
| 143 valid values). |
