/src/wrappers/cairo/library/cairo_matrix.e
Specman e | 234 lines | 119 code | 34 blank | 81 comment | 3 complexity | de4a9fd1c01718d805adfc4d471b002a MD5 | raw file
1note 2 description: "cairo_matrix_t -- Generic matrix operations." 3 copyright: "[ 4 Copyright (C) 2007-2017: Paolo Redaelli, 5 Soluciones Informaticas Libres S.A. (Except), 6 Cairo team 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public License 10 as published by the Free Software Foundation; either version 2.1 of 11 the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 21 02110-1301 USA 22 ]" 23 date: "$Date:$" 24 revision: "$Revision:$" 25 wrapped_version: "1.2.4" 26 27class CAIRO_MATRIX 28 -- CAIRO_MATRIX (cairo_matrix_t in C) is used throughout cairo to 29 -- convert between different coordinate spaces. A cairo_matrix_t 30 -- holds an affine transformation, such as a scale, rotation, 31 -- shear, or a combination of these. The transformation of a point 32 -- (x,y) is given by: 33 34 -- x_new = xx * x + xy * y + x0; 35 -- y_new = yx * x + yy * y + y0; 36 37 -- The current transformation matrix of a cairo_t, represented as a 38 -- cairo_matrix_t, defines the transformation from user-space 39 -- coordinates to device-space coordinates. See `matrix'() and 40 -- `set_matrix' in CAIRO_CONTEXT. 41 42inherit C_STRUCT 43 44insert 45 CAIRO_MATRIX_EXTERNALS 46 CAIRO_STATUS 47 48create {ANY} make, allocate, from_external_pointer 49 50feature {} -- Creation 51 make (an_xx, an_yx, an_xy, an_yy, an_x0, an_y0: REAL) 52 -- Create matrix to be the affine transformation given by xx, 53 -- yx, xy, yy, x0, y0. The transformation is given by: 54 55 -- x_new = xx * x + xy * y + x0; 56 -- y_new = yx * x + yy * y + y0; 57 58 -- xx : xx component of the affine transformation 59 -- yx : yx component of the affine transformation 60 -- xy : xy component of the affine transformation 61 -- yy : yy component of the affine transformation 62 -- x0 : X translation component of the affine transformation 63 -- y0 : Y translation component of the affine transformation 64 do 65 allocate 66 cairo_matrix_init(handle, xx, yx, xy, yy, x0, y0); 67 end 68 69 identity 70 -- Create a matrix for the identity transformation. 71 do 72 allocate 73 cairo_matrix_init_identity (handle) 74 end 75 76 translation (a_tx, a_ty: REAL) 77 -- Initializes matrix to a transformation that translates by 78 -- `a_tx' and `a_ty' in the X and Y dimensions, respectively. 79 do 80 allocate 81 cairo_matrix_init_translate (handle, a_tx, a_ty) 82 end 83 84 scaling (an_x_scale, an_y_scale: REAL) 85 -- Create matrix to a transformation that scales by 86 -- `an_x_scale' and `an_y_scale' in the X and Y dimensions, 87 -- respectively. 88 do 89 allocate 90 cairo_matrix_init_scale(handle,an_x_scale,an_y_scale) 91 end 92 93 rotation (some_radians: REAL) 94 -- Create matrix as a transformation that rotates by `some_radians'. 95 96 -- `some_radians': angle of rotation, in radians. The 97 -- direction of rotation is defined such that positive angles 98 -- rotate in the direction from the positive X axis toward 99 -- the positive Y axis. With the default axis orientation of 100 -- cairo, positive angles rotate in a clockwise direction. 101 do 102 allocate 103 cairo_matrix_init_rotate(handle,some_radians) 104 end 105 106feature {ANY} -- Access 107 xx: REAL 108 -- xx component of the affine transformation 109 do 110 Result := cairo_matrix_get_xx(handle) 111 end 112 113 yx: REAL 114 -- yx component of the affine transformation 115 do 116 Result := cairo_matrix_get_yx(handle) 117 end 118 119 xy: REAL 120 -- xy component of the affine transformation 121 do 122 Result := cairo_matrix_get_xy(handle) 123 end 124 125 yy: REAL 126 -- yy component of the affine transformation 127 do 128 Result := cairo_matrix_get_yy(handle) 129 end 130 131 x0: REAL 132 -- x0 component of the affine transformation 133 do 134 Result := cairo_matrix_get_x0(handle) 135 end 136 137 y0: REAL 138 -- y0 component of the affine transformation 139 do 140 Result := cairo_matrix_get_y0(handle) 141 end 142 143feature {ANY} 144 translate (a_tx, a_ty: REAL) 145 -- Applies a translation by `a_tx', `a_ty' to the 146 -- transformation in matrix. The effect of the new 147 -- transformation is to first translate the coordinates by 148 -- `a_tx' and `a_ty', then apply the original transformation 149 -- to the coordinates. 150 151 -- `a_tx' : amount to translate in the X direction 152 -- `a_ty' : amount to translate in the Y direction 153 do 154 cairo_matrix_translate(handle,a_tx,a_ty) 155 end 156 157 scale (an_sx, an_sy: REAL) 158 -- Applies scaling by `an_sx', `an_sy' to the transformation 159 -- in matrix. The effect of the new transformation is to 160 -- first scale the coordinates by `an_sx' and `an_sy', then 161 -- apply the original transformation to the coordinates. 162 163 -- `an_sx' : scale factor in the X direction 164 -- `an_sy' : scale factor in the Y direction 165 do 166 cairo_matrix_scale(handle,an_sx,an_sy) 167 end 168 169 rotate (some_radians: REAL) 170 -- Applies rotation by `some_radians' to the transformation 171 -- in matrix. The effect of the new transformation is to 172 -- first rotate the coordinates by radians, then apply the 173 -- original transformation to the coordinates. 174 175 -- `some_radians': angle of rotation, in radians. The 176 -- direction of rotation is defined such that positive angles 177 -- rotate in the direction from the positive X axis toward 178 -- the positive Y axis. With the default axis orientation of 179 -- cairo, positive angles rotate in a clockwise direction. 180 do 181 cairo_matrix_rotate(handle,some_radians) 182 end 183 184 inverse: CAIRO_MATRIX 185 -- The inverse of Current value. Void if Current does not 186 -- have inverse, i.e.: if the matrix collapses points 187 -- together (it is degenerate), then it has no inverse and 188 -- this function will fail. 189 local a_status: INTEGER 190 do 191 Result := twin 192 a_status := cairo_matrix_invert (Result.handle) 193 -- cairo_matrix_invert returns: If matrix has an inverse, 194 -- modifies matrix to be the inverse matrix and returns 195 -- CAIRO_STATUS_SUCCESS. Otherwise, 196 if a_status = cairo_status_invalid_matrix then 197 Result := Void 198 end 199 end 200 201 inverted: BOOLEAN 202 -- True if matrix could be changed into the inverse of it's 203 -- original value. 204 205 -- Not all transformation matrices have inverses; if the 206 -- matrix collapses points together (it is degenerate), then 207 -- it has no inverse and this feature will be False and 208 -- matrix will not be changed. 209 local a_status: INTEGER 210 do 211 Result:=(cairo_matrix_invert(handle) /= cairo_status_invalid_matrix) 212 end 213 214 infix "*" (another: like Current): like Current 215 -- A new matrix containing the multiplication of the affine 216 -- transformations of Current and `another' together. The 217 -- effect of the resulting transformation is to first apply 218 -- the transformation in Current to the coordinates and then 219 -- apply the transformation in `another' to the coordinates. 220 require another_not_void: another /= Void 221 do 222 create Result.allocate 223 cairo_matrix_multiply(Result.handle,handle,another.handle) 224 -- TODO: since it is allowable for result to be identical to either current or 225 -- another, it is good to provide `multiply' and `square'. 226 ensure not_void: Result/=Void 227 end 228 229feature {ANY} -- Memory handling 230 dispose 231 do 232 free(handle) 233 end 234end -- class CAIRO_MATRIX