java.lang.Object
io.github.jwharm.cairobindings.Proxy
org.freedesktop.cairo.Matrix
Generic matrix operations.
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. The transformation of a point (x,y) is given by:
xNew = xx * x + xy * y + x0; yNew = yx * x + yy * y + y0;The current transformation matrix of a
Context, represented as a
Matrix, defines the transformation from user-space coordinates to
device-space coordinates. See Context.getMatrix(org.freedesktop.cairo.Matrix) and
Context.setMatrix(Matrix).- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionMatrix(MemorySegment address) Constructor used internally to instantiate a java Matrix object for a nativecairo_matrix_tinstance -
Method Summary
Modifier and TypeMethodDescriptionstatic MatrixAllocate a new, uninitializedcaio_matrix_tinit(double xx, double yx, double xy, double yy, double x0, double y0) Sets the matrix to be the affine transformation given byxx,yx,xy,yy,x0,y0.Modifies the matrix to be an identity transformation.initTranslate(double tx, double ty) Initializes the matrix to a transformation that translates bytxandtyin the X and Y dimensions, respectively.voidinvert()Changes the matrix to be the inverse of its original value.voidMultiplies the affine transformations in this matrix and the provided matrix together and stores the result in the resulting matrix.voidrotate(double radians) Applies rotation byradiansto the transformation in the matrix.voidscale(double sx, double sy) Applies scaling bysx, syto the transformation in the matrix.toString()String representation of this MatrixtransformDistance(Point distanceVector) Transforms the distance vector(dx, dy)by the matrix.transformPoint(Point point) Transforms the point(x, y)by the matrix.voidtranslate(double tx, double ty) Applies a translation bytx, tyto the transformation in the matrix.doublex0()Get the x0 value of the Matrixdoublexx()Get the xx value of the Matrixdoublexy()Get the xy value of the Matrixdoubley0()Get the y0 value of the Matrixdoubleyx()Get the yx value of the Matrixdoubleyy()Get the yy value of the Matrix
-
Constructor Details
-
Matrix
Constructor used internally to instantiate a java Matrix object for a nativecairo_matrix_tinstance- Parameters:
address- the memory address of the nativecairo_matrix_tinstance
-
-
Method Details
-
xx
public double xx()Get the xx value of the Matrix- Returns:
- the xx value
-
yx
public double yx()Get the yx value of the Matrix- Returns:
- the yx value
-
xy
public double xy()Get the xy value of the Matrix- Returns:
- the xy value
-
yy
public double yy()Get the yy value of the Matrix- Returns:
- the yy value
-
x0
public double x0()Get the x0 value of the Matrix- Returns:
- the x0 value
-
y0
public double y0()Get the y0 value of the Matrix- Returns:
- the y0 value
-
create
-
init
Sets the matrix to be the affine transformation given byxx,yx,xy,yy,x0,y0. The transformation is given by:xNew = xx * x + xy * y + x0; yNew = yx * x + yy * y + y0;
- Parameters:
xx- xx component of the affine transformationyx- yx component of the affine transformationxy- xy component of the affine transformationyy- yy component of the affine transformationx0- X translation component of the affine transformationy0- Y translation component of the affine transformation- Returns:
- the resulting Matrix
- Since:
- 1.0
-
initIdentity
Modifies the matrix to be an identity transformation.- Returns:
- the matrix
- Since:
- 1.0
-
initTranslate
Initializes the matrix to a transformation that translates bytxandtyin the X and Y dimensions, respectively.- Parameters:
tx- amount to translate in the X directionty- amount to translate in the Y direction- Returns:
- the matrix
- Since:
- 1.0
-
translate
public void translate(double tx, double ty) Applies a translation bytx, tyto the transformation in the matrix. The effect of the new transformation is to first translate the coordinates bytxandty, then apply the original transformation to the coordinates.- Parameters:
tx- amount to translate in the X directionty- amount to translate in the Y direction- Since:
- 1.0
-
scale
public void scale(double sx, double sy) Applies scaling bysx, syto the transformation in the matrix. The effect of the new transformation is to first scale the coordinates bysxandsy, then apply the original transformation to the coordinates.- Parameters:
sx- scale factor in the X directionsy- scale factor in the X direction- Since:
- 1.0
-
rotate
public void rotate(double radians) Applies rotation byradiansto the transformation in the matrix. The effect of the new transformation is to first rotate the coordinates byradians, 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.- Since:
- 1.0
-
invert
Changes the 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.- Throws:
IllegalArgumentException- if the matrix has no inverse. SeeStatus.INVALID_MATRIX.
-
multiply
Multiplies the affine transformations in this matrix and the provided matrix together and stores the result in the resulting matrix. The effect of the resulting transformation is to first apply the transformation inato the coordinates and then apply the transformation inbto the coordinates.It is allowable for the resulting matrix to be identical to either
aorb.- Parameters:
a- a matrixb- a matrix- Since:
- 1.0
-
transformDistance
Transforms the distance vector(dx, dy)by the matrix. This is similar totransformPoint(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;
- Parameters:
distanceVector- X and Y component of a distance vector- Returns:
- the transformed X and Y component
- Since:
- 1.0
-
transformPoint
-
toString
-