struct Cairo::Matrix
- Cairo::Matrix
- Struct
- Value
- Object
Overview
Wrapper for LibCairo::MatrixT
Matrix
is used throughout cairo to convert between different coordinate spaces.
A Matrix
holds an affine transformation, such as a scale, rotation, shear, or a combination of these.
Defined in:
cairo/matrix.crConstructors
- .new(xx : Float64, yx : Float64, xy : Float64, yy : Float64, x0 : Float64, y0 : Float64)
- .new(m : LibCairo::MatrixT)
- .new
Instance Method Summary
-
#init(xx : Float64, yx : Float64, xy : Float64, yy : Float64, x0 : Float64, y0 : Float64)
Sets matrix to be the affine transformation given by xx, yx, xy, yy, x0, y0.
-
#init_identity
Modifies matrix to be an identity transformation.
-
#init_rotate(radians : Float64)
Initialized matrix to a transformation that rotates by radians.
-
#init_scale(sx : Float64, sy : Float64)
Initializes matrix to a transformation that scales by sx and sy in the X and Y dimensions, respectively.
-
#init_translate(tx : Float64, ty : Float64)
Initializes matrix to a transformation that translates by tx and ty in the X and Y dimensions, respectively.
-
#invert : Status
Changes matrix to be the inverse of its original value.
-
#multiply(a : Matrix, b : Matrix)
Multiplies the affine transformations in a and b together and returns the result.
-
#rotate(radians : Float64)
Applies rotation by radians to the transformation in matrix.
-
#scale(sx : Float64, sy : Float64)
Applies scaling by sx, sy to the transformation in matrix.
-
#to_cairo_matrix : LibCairo::MatrixT
Returns the underlieing structure.
-
#to_unsafe : LibCairo::PMatrixT
Returns the pointer of the underlieing structure.
-
#transform_distance(d : Point) : Point
Transforms the distance vector (dx, dy) by matrix.
-
#transform_point(p : Point) : Point
Transforms the point (x, y) by matrix.
-
#translate(tx : Float64, ty : Float64)
Applies a translation by tx, ty to the transformation in matrix.
- #x0 : Float64
- #x0=(x0 : Float64)
- #xx : Float64
- #xx=(xx : Float64)
- #xy : Float64
- #xy=(xy : Float64)
- #y0 : Float64
- #y0=(y0 : Float64)
- #yx : Float64
- #yx=(yx : Float64)
- #yy : Float64
- #yy=(yy : Float64)
Constructor Detail
Instance Method Detail
Sets matrix to be the affine transformation given by xx, yx, xy, yy, x0, y0. The transformation is given by:
x_new = xx * x + xy * y + x0
y_new = yx * x + yy * y + y0
###Parameters
- xx xx component of the affine transformation
- yx yx component of the affine transformation
- xy xy component of the affine transformation
- yy yy component of the affine transformation
- x0 X translation component of the affine transformation
- y0 Y translation component of the affine transformation
Initialized matrix to a transformation that rotates by radians.
###Parameters
- radians angle of rotation, in radians. The direction of rotation is defined such that positive angles rotate in the direction from the positive X axis toward the positive Y axis. With the default axis orientation of cairo, positive angles rotate in a clockwise direction.
Initializes matrix to a transformation that scales by sx and sy in the X and Y dimensions, respectively.
###Parameters
- sx scale factor in the X direction
- sy scale factor in the Y direction
Initializes matrix to a transformation that translates by tx and ty in the X and Y dimensions, respectively.
###Parameters
- tx amount to translate in the X direction
- ty amount to translate in the Y direction
Changes matrix to be the inverse of its original value. Not all transformation matrices have inverses; if the matrix collapses points together (it is degenerate), then it has no inverse and this function will fail.
##Returns
If matrix has an inverse, modifies matrix to be the inverse matrix and returns
Status::Success
. Otherwise, returns Status::InvalidMatrix
.
Multiplies the affine transformations in a and b together and returns the result. The effect of the resulting transformation is to first apply the transformation in a to the coordinates and then apply the transformation in b to the coordinates.
It is allowable for result to be identical to either a or b.
###Parameters
Applies rotation by radians to the transformation in matrix. The effect of the new transformation is to first rotate the coordinates by radians, then apply the original transformation to the coordinates.
###Parameters
- radians angle of rotation, in radians. The direction of rotation is defined such that positive angles rotate in the direction from the positive X axis toward the positive Y axis. With the default axis orientation of cairo, positive angles rotate in a clockwise direction.
Applies scaling by sx, sy to the transformation in matrix. The effect of the new transformation is to first scale the coordinates by sx and sy, then apply the original transformation to the coordinates.
###Parameters
- sx scale factor in the X direction
- sy scale factor in the Y direction
Transforms the distance vector (dx, dy) by matrix.
This is similar to Matrix#transform_point
except that the translation components
of the transformation are ignored. The calculation of the returned vector is as follows:
dx2 = dx1 * a + dy1 * c
dy2 = dx1 * b + dy1 * d
Affine transformations are position invariant, so the same vector always transforms to the same vector. If (x1, y1) transforms to (x2, y2) then (x1 + dx1, y1 + dy1) will transform to (x1 + dx2, y1 + dy2) for all values of x1 and x2.
###Parameters
- dx X component of a distance vector.
- dy Y component of a distance vector.
###Returns Transformed vector.
Transforms the point (x, y) by matrix.
###Parameters
- x X position.
- y Y position.
###Returns Transformed vector.
Applies a translation by tx, ty to the transformation in matrix. The effect of the new transformation is to first translate the coordinates by tx and ty, then apply the original transformation to the coordinates.
###Parameters
- tx amount to translate in the X direction
- ty amount to translate in the Y direction