FileDocCategorySizeDatePackage
Matrix.javaAPI DocAndroid 1.5 API25462Wed May 06 22:42:00 BST 2009android.graphics

Matrix

public class Matrix extends Object
The Matrix class holds a 3x3 matrix for transforming coordinates. Matrix does not have a constructor, so it must be explicitly initialized using either reset() - to construct an identity matrix, or one of the set..() functions (e.g. setTranslate, setRotate, etc.).

Fields Summary
public static final int
MSCALE_X
public static final int
MSKEW_X
public static final int
MTRANS_X
public static final int
MSKEW_Y
public static final int
MSCALE_Y
public static final int
MTRANS_Y
public static final int
MPERSP_0
public static final int
MPERSP_1
public static final int
MPERSP_2
int
native_instance
Constructors Summary
public Matrix()
Create an identity matrix


             
      
        native_instance = native_create(0);
    
public Matrix(Matrix src)
Create a matrix that is a (deep) copy of src

param
src The matrix to copy into this matrix

        native_instance = native_create(src != null ? src.native_instance : 0);
    
Methods Summary
private static voidcheckPointArrays(float[] src, int srcIndex, float[] dst, int dstIndex, int pointCount)

        // check for too-small and too-big indices
        int srcStop = srcIndex + (pointCount << 1);
        int dstStop = dstIndex + (pointCount << 1);
        if ((pointCount | srcIndex | dstIndex | srcStop | dstStop) < 0 ||
                srcStop > src.length || dstStop > dst.length) {
            throw new ArrayIndexOutOfBoundsException();
        }
    
public booleanequals(java.lang.Object obj)
Returns true iff obj is a Matrix and its values equal our values.

        return obj != null &&
               obj instanceof Matrix &&
               native_equals(native_instance, ((Matrix)obj).native_instance);
    
protected voidfinalize()

        finalizer(native_instance);
    
private static native voidfinalizer(int native_instance)

public voidgetValues(float[] values)
Copy 9 values from the matrix into the array.

        if (values.length < 9) {
            throw new ArrayIndexOutOfBoundsException();
        }
        native_getValues(native_instance, values);
    
public booleaninvert(android.graphics.Matrix inverse)
If this matrix can be inverted, return true and if inverse is not null, set inverse to be the inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false.

        return native_invert(native_instance, inverse.native_instance);
    
public booleanisIdentity()
Returns true if the matrix is identity. This maybe faster than testing if (getType() == 0)

        return native_isIdentity(native_instance);
    
public voidmapPoints(float[] dst, int dstIndex, float[] src, int srcIndex, int pointCount)
Apply this matrix to the array of 2D points specified by src, and write the transformed points into the array of points specified by dst. The two arrays represent their "points" as pairs of floats [x, y].

param
dst The array of dst points (x,y pairs)
param
dstIndex The index of the first [x,y] pair of dst floats
param
src The array of src points (x,y pairs)
param
srcIndex The index of the first [x,y] pair of src floats
param
pointCount The number of points (x,y pairs) to transform

        checkPointArrays(src, srcIndex, dst, dstIndex, pointCount);
        native_mapPoints(native_instance, dst, dstIndex, src, srcIndex,
                         pointCount, true);
    
public voidmapPoints(float[] dst, float[] src)
Apply this matrix to the array of 2D points specified by src, and write the transformed points into the array of points specified by dst. The two arrays represent their "points" as pairs of floats [x, y].

param
dst The array of dst points (x,y pairs)
param
src The array of src points (x,y pairs)

        if (dst.length != src.length) {
            throw new ArrayIndexOutOfBoundsException();
        }
        mapPoints(dst, 0, src, 0, dst.length >> 1);
    
public voidmapPoints(float[] pts)
Apply this matrix to the array of 2D points, and write the transformed points back into the array

param
pts The array [x0, y0, x1, y1, ...] of points to transform.

        mapPoints(pts, 0, pts, 0, pts.length >> 1);
    
public floatmapRadius(float radius)
Return the mean radius of a circle after it has been mapped by this matrix. NOTE: in perspective this value assumes the circle has its center at the origin.

        return native_mapRadius(native_instance, radius);
    
public booleanmapRect(RectF dst, RectF src)
Apply this matrix to the src rectangle, and write the transformed rectangle into dst. This is accomplished by transforming the 4 corners of src, and then setting dst to the bounds of those points.

param
dst Where the transformed rectangle is written.
param
src The original rectangle to be transformed.
return
the result of calling rectStaysRect()

        if (dst == null || src == null) {
            throw new NullPointerException();
        }
        return native_mapRect(native_instance, dst, src);
    
public booleanmapRect(RectF rect)
Apply this matrix to the rectangle, and write the transformed rectangle back into it. This is accomplished by transforming the 4 corners of rect, and then setting it to the bounds of those points

param
rect The rectangle to transform.
return
the result of calling rectStaysRect()

        return mapRect(rect, rect);
    
public voidmapVectors(float[] dst, int dstIndex, float[] src, int srcIndex, int vectorCount)
Apply this matrix to the array of 2D vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. The two arrays represent their "vectors" as pairs of floats [x, y].

param
dst The array of dst vectors (x,y pairs)
param
dstIndex The index of the first [x,y] pair of dst floats
param
src The array of src vectors (x,y pairs)
param
srcIndex The index of the first [x,y] pair of src floats
param
vectorCount The number of vectors (x,y pairs) to transform

        checkPointArrays(src, srcIndex, dst, dstIndex, vectorCount);
        native_mapPoints(native_instance, dst, dstIndex, src, srcIndex,
                         vectorCount, false);
    
public voidmapVectors(float[] dst, float[] src)
Apply this matrix to the array of 2D vectors specified by src, and write the transformed vectors into the array of vectors specified by dst. The two arrays represent their "vectors" as pairs of floats [x, y].

param
dst The array of dst vectors (x,y pairs)
param
src The array of src vectors (x,y pairs)

        if (dst.length != src.length) {
            throw new ArrayIndexOutOfBoundsException();
        }
        mapVectors(dst, 0, src, 0, dst.length >> 1);
    
public voidmapVectors(float[] vecs)
Apply this matrix to the array of 2D vectors, and write the transformed vectors back into the array.

param
vecs The array [x0, y0, x1, y1, ...] of vectors to transform.

        mapVectors(vecs, 0, vecs, 0, vecs.length >> 1);
    
private static native intnative_create(int native_src_or_zero)

private static native booleannative_equals(int native_a, int native_b)

private static native voidnative_getValues(int native_object, float[] values)

private static native booleannative_invert(int native_object, int inverse)

private static native booleannative_isIdentity(int native_object)

private static native voidnative_mapPoints(int native_object, float[] dst, int dstIndex, float[] src, int srcIndex, int ptCount, boolean isPts)

private static native floatnative_mapRadius(int native_object, float radius)

private static native booleannative_mapRect(int native_object, RectF dst, RectF src)

private static native booleannative_postConcat(int native_object, int other_matrix)

private static native booleannative_postRotate(int native_object, float degrees, float px, float py)

private static native booleannative_postRotate(int native_object, float degrees)

private static native booleannative_postScale(int native_object, float sx, float sy, float px, float py)

private static native booleannative_postScale(int native_object, float sx, float sy)

private static native booleannative_postSkew(int native_object, float kx, float ky, float px, float py)

private static native booleannative_postSkew(int native_object, float kx, float ky)

private static native booleannative_postTranslate(int native_object, float dx, float dy)

private static native booleannative_preConcat(int native_object, int other_matrix)

private static native booleannative_preRotate(int native_object, float degrees, float px, float py)

private static native booleannative_preRotate(int native_object, float degrees)

private static native booleannative_preScale(int native_object, float sx, float sy, float px, float py)

private static native booleannative_preScale(int native_object, float sx, float sy)

private static native booleannative_preSkew(int native_object, float kx, float ky, float px, float py)

private static native booleannative_preSkew(int native_object, float kx, float ky)

private static native booleannative_preTranslate(int native_object, float dx, float dy)

private static native booleannative_rectStaysRect(int native_object)

private static native voidnative_reset(int native_object)

private static native voidnative_set(int native_object, int other)

private static native booleannative_setConcat(int native_object, int a, int b)

private static native booleannative_setPolyToPoly(int native_object, float[] src, int srcIndex, float[] dst, int dstIndex, int pointCount)

private static native booleannative_setRectToRect(int native_object, RectF src, RectF dst, int stf)

private static native voidnative_setRotate(int native_object, float degrees, float px, float py)

private static native voidnative_setRotate(int native_object, float degrees)

private static native voidnative_setScale(int native_object, float sx, float sy, float px, float py)

private static native voidnative_setScale(int native_object, float sx, float sy)

private static native voidnative_setSinCos(int native_object, float sinValue, float cosValue, float px, float py)

private static native voidnative_setSinCos(int native_object, float sinValue, float cosValue)

private static native voidnative_setSkew(int native_object, float kx, float ky, float px, float py)

private static native voidnative_setSkew(int native_object, float kx, float ky)

private static native voidnative_setTranslate(int native_object, float dx, float dy)

private static native voidnative_setValues(int native_object, float[] values)

final intni()

        return native_instance;
    
public booleanpostConcat(android.graphics.Matrix other)
Postconcats the matrix with the specified matrix. M' = other * M

        return native_postConcat(native_instance, other.native_instance);
    
public booleanpostRotate(float degrees, float px, float py)
Postconcats the matrix with the specified rotation. M' = R(degrees, px, py) * M

        return native_postRotate(native_instance, degrees, px, py);
    
public booleanpostRotate(float degrees)
Postconcats the matrix with the specified rotation. M' = R(degrees) * M

        return native_postRotate(native_instance, degrees);
    
public booleanpostScale(float sx, float sy, float px, float py)
Postconcats the matrix with the specified scale. M' = S(sx, sy, px, py) * M

        return native_postScale(native_instance, sx, sy, px, py);
    
public booleanpostScale(float sx, float sy)
Postconcats the matrix with the specified scale. M' = S(sx, sy) * M

        return native_postScale(native_instance, sx, sy);
    
public booleanpostSkew(float kx, float ky, float px, float py)
Postconcats the matrix with the specified skew. M' = K(kx, ky, px, py) * M

        return native_postSkew(native_instance, kx, ky, px, py);
    
public booleanpostSkew(float kx, float ky)
Postconcats the matrix with the specified skew. M' = K(kx, ky) * M

        return native_postSkew(native_instance, kx, ky);
    
public booleanpostTranslate(float dx, float dy)
Postconcats the matrix with the specified translation. M' = T(dx, dy) * M

        return native_postTranslate(native_instance, dx, dy);
    
public booleanpreConcat(android.graphics.Matrix other)
Preconcats the matrix with the specified matrix. M' = M * other

        return native_preConcat(native_instance, other.native_instance);
    
public booleanpreRotate(float degrees, float px, float py)
Preconcats the matrix with the specified rotation. M' = M * R(degrees, px, py)

        return native_preRotate(native_instance, degrees, px, py);
    
public booleanpreRotate(float degrees)
Preconcats the matrix with the specified rotation. M' = M * R(degrees)

        return native_preRotate(native_instance, degrees);
    
public booleanpreScale(float sx, float sy, float px, float py)
Preconcats the matrix with the specified scale. M' = M * S(sx, sy, px, py)

        return native_preScale(native_instance, sx, sy, px, py);
    
public booleanpreScale(float sx, float sy)
Preconcats the matrix with the specified scale. M' = M * S(sx, sy)

        return native_preScale(native_instance, sx, sy);
    
public booleanpreSkew(float kx, float ky, float px, float py)
Preconcats the matrix with the specified skew. M' = M * K(kx, ky, px, py)

        return native_preSkew(native_instance, kx, ky, px, py);
    
public booleanpreSkew(float kx, float ky)
Preconcats the matrix with the specified skew. M' = M * K(kx, ky)

        return native_preSkew(native_instance, kx, ky);
    
public booleanpreTranslate(float dx, float dy)
Preconcats the matrix with the specified translation. M' = M * T(dx, dy)

        return native_preTranslate(native_instance, dx, dy);
    
public booleanrectStaysRect()
Returns true if will map a rectangle to another rectangle. This can be true if the matrix is identity, scale-only, or rotates a multiple of 90 degrees.

        return native_rectStaysRect(native_instance);
    
public voidreset()
Set the matrix to identity

        native_reset(native_instance);
    
public voidset(android.graphics.Matrix src)
(deep) copy the src matrix into this matrix. If src is null, reset this matrix to the identity matrix.

        if (src == null) {
            reset();
        } else {
            native_set(native_instance, src.native_instance);
        }
    
public booleansetConcat(android.graphics.Matrix a, android.graphics.Matrix b)
Set the matrix to the concatenation of the two specified matrices, returning true if the the result can be represented. Either of the two matrices may also be the target matrix. this = a * b

        return native_setConcat(native_instance, a.native_instance,
                                b.native_instance);
    
public booleansetPolyToPoly(float[] src, int srcIndex, float[] dst, int dstIndex, int pointCount)
Set the matrix such that the specified src points would map to the specified dst points. The "points" are represented as an array of floats, order [x0, y0, x1, y1, ...], where each "point" is 2 float values.

param
src The array of src [x,y] pairs (points)
param
srcIndex Index of the first pair of src values
param
dst The array of dst [x,y] pairs (points)
param
dstIndex Index of the first pair of dst values
param
pointCount The number of pairs/points to be used. Must be [0..4]
return
true if the matrix was set to the specified transformation

        if (pointCount > 4) {
            throw new IllegalArgumentException();
        }
        checkPointArrays(src, srcIndex, dst, dstIndex, pointCount);
        return native_setPolyToPoly(native_instance, src, srcIndex,
                                    dst, dstIndex, pointCount);
    
public booleansetRectToRect(RectF src, RectF dst, android.graphics.Matrix$ScaleToFit stf)
Set the matrix to the scale and translate values that map the source rectangle to the destination rectangle, returning true if the the result can be represented.

param
src the source rectangle to map from.
param
dst the destination rectangle to map to.
param
stf the ScaleToFit option
return
true if the matrix can be represented by the rectangle mapping.

        if (dst == null || src == null) {
            throw new NullPointerException();
        }
        return native_setRectToRect(native_instance, src, dst, stf.nativeInt);
    
public voidsetRotate(float degrees, float px, float py)
Set the matrix to rotate by the specified number of degrees, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

        native_setRotate(native_instance, degrees, px, py);
    
public voidsetRotate(float degrees)
Set the matrix to rotate about (0,0) by the specified number of degrees.

        native_setRotate(native_instance, degrees);
    
public voidsetScale(float sx, float sy)
Set the matrix to scale by sx and sy.

        native_setScale(native_instance, sx, sy);
    
public voidsetScale(float sx, float sy, float px, float py)
Set the matrix to scale by sx and sy, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

        native_setScale(native_instance, sx, sy, px, py);
    
public voidsetSinCos(float sinValue, float cosValue, float px, float py)
Set the matrix to rotate by the specified sine and cosine values, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

        native_setSinCos(native_instance, sinValue, cosValue, px, py);
    
public voidsetSinCos(float sinValue, float cosValue)
Set the matrix to rotate by the specified sine and cosine values.

        native_setSinCos(native_instance, sinValue, cosValue);
    
public voidsetSkew(float kx, float ky, float px, float py)
Set the matrix to skew by sx and sy, with a pivot point at (px, py). The pivot point is the coordinate that should remain unchanged by the specified transformation.

        native_setSkew(native_instance, kx, ky, px, py);
    
public voidsetSkew(float kx, float ky)
Set the matrix to skew by sx and sy.

        native_setSkew(native_instance, kx, ky);
    
public voidsetTranslate(float dx, float dy)
Set the matrix to translate by (dx, dy).

        native_setTranslate(native_instance, dx, dy);
    
public voidsetValues(float[] values)
Copy 9 values from the array into the matrix. Depending on the implementation of Matrix, these may be transformed into 16.16 integers in the Matrix, such that a subsequent call to getValues() will not yield exactly the same values.

        if (values.length < 9) {
            throw new ArrayIndexOutOfBoundsException();
        }
        native_setValues(native_instance, values);
    
public java.lang.StringtoShortString()

        float[] values = new float[9];
        getValues(values);
        return "[" +
                values[0] + ", " + values[1] + ", " + values[2] + "][" +
                values[3] + ", " + values[4] + ", " + values[5] + "][" +
                values[6] + ", " + values[7] + ", " + values[8] + "]";
                
    
public java.lang.StringtoString()

        return "Matrix{" + toShortString() + "}";