/src/wrappers/cairo/library/cairo_matrix.e

http://github.com/tybor/Liberty · Specman e · 234 lines · 119 code · 34 blank · 81 comment · 3 complexity · de4a9fd1c01718d805adfc4d471b002a MD5 · raw file

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