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
ConstructorDescriptionMatrix
(MemorySegment address) Constructor used internally to instantiate a java Matrix object for a nativecairo_matrix_t
instance -
Method Summary
Modifier and TypeMethodDescriptionstatic Matrix
Allocate a new, uninitializedcaio_matrix_t
init
(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 bytx
andty
in the X and Y dimensions, respectively.void
invert()
Changes the matrix to be the inverse of its original value.void
Multiplies the affine transformations in this matrix and the provided matrix together and stores the result in the resulting matrix.void
rotate
(double radians) Applies rotation byradians
to the transformation in the matrix.void
scale
(double sx, double sy) Applies scaling bysx, sy
to 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.void
translate
(double tx, double ty) Applies a translation bytx, ty
to the transformation in the matrix.double
x0()
Get the x0 value of the Matrixdouble
xx()
Get the xx value of the Matrixdouble
xy()
Get the xy value of the Matrixdouble
y0()
Get the y0 value of the Matrixdouble
yx()
Get the yx value of the Matrixdouble
yy()
Get the yy value of the Matrix
-
Constructor Details
-
Matrix
Constructor used internally to instantiate a java Matrix object for a nativecairo_matrix_t
instance- Parameters:
address
- the memory address of the nativecairo_matrix_t
instance
-
-
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 bytx
andty
in 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, ty
to the transformation in the matrix. The effect of the new transformation is to first translate the coordinates bytx
andty
, 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, sy
to the transformation in the matrix. The effect of the new transformation is to first scale the coordinates bysx
andsy
, 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 byradians
to 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 ina
to the coordinates and then apply the transformation inb
to the coordinates.It is allowable for the resulting matrix to be identical to either
a
orb
.- 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
-