Package com.leia.core
Class MatrixUtils
- java.lang.Object
-
- com.leia.core.MatrixUtils
-
public class MatrixUtils extends Object
MatrixUtils is a collection of functions for various matrix operations.Android provides two matrix representations,
MatrixandMatrix, MatrixUtils provides methods to convert between the two.MatrixUtils also provides matrix routines needed for pinch-to-zoom and pan gesture support. This includes a helper function to return a matrix for different ScaleTypes.
-
-
Constructor Summary
Constructors Constructor Description MatrixUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static float[]FromMatrix(Matrix matrixIn)static MatrixGetScaleTypeMatrix(ScaleType scaleType, RectF srcRect, RectF destRect)Returns aMatrixto transform srcRect to destRect given a specific scaleType.static MatrixgetTranslationMatrix(InterlacedView view, Matrix scaleTypeMatrix, Matrix localMatrix, float panX, float panY, boolean applyLimits)Returns aMatrixto translate the contents of a view.static float[]getTranslationTransform(InterlacedView view, float[] rectMatrix, float[] localMatrix, float panX, float panY, boolean applyLimits)Returns anMatrixto translate the contents of a view.static float[]getTranslationTransform(InterlacedView view, float panX, float panY, boolean applyLimits)Returns anMatrixto translate the contents of a view.static MatrixgetZoomMatrix(InterlacedView view, Matrix scaleTypeMatrix, Matrix localMatrix, float scaleX, float scaleY, float focusX, float focusY, boolean applyLimits)Returns aMatrixto zoom around a point.static float[]getZoomTransform(InterlacedView view, float[] rectMatrix, float[] localMatrix, float scaleX, float scaleY, float focusX, float focusY, boolean applyLimits)Returns anMatrixto zoom around a point.static float[]getZoomTransform(InterlacedView view, float scaleX, float scaleY, float focusX, float focusY, boolean applyLimits)Returns anMatrixto zoom around a point.static MatrixToMatrix(float[] matrixIn)static PointFtransformPoint(float[] matrix, PointF point)Returns a 2D point transformed by a matrix.static PointFtransformPoint(float[] matrix, PointF point, float w)Returns a 2D point or vector transformed by a matrix.static PointFtransformVector(float[] matrix, PointF vector)Returns a 2D vector transformed by a matrix.
-
-
-
Method Detail
-
GetScaleTypeMatrix
public static Matrix GetScaleTypeMatrix(ScaleType scaleType, RectF srcRect, RectF destRect)
Returns aMatrixto transform srcRect to destRect given a specific scaleType.- Parameters:
scaleType- how to fit srcRect into destRect [FILL | FIT_CENTER | CROP_FILL]srcRect- source rectangle (e.g. the image)destRect- destination rectangle (e.g. the view)
-
getZoomTransform
public static float[] getZoomTransform(InterlacedView view, float[] rectMatrix, float[] localMatrix, float scaleX, float scaleY, float focusX, float focusY, boolean applyLimits)
Returns anMatrixto zoom around a point.- Parameters:
view- the interlaced view being transformedrectMatrix- the scaleType matrix used by the viewlocalMatrix- the current zoom/pan transformscaleX- x scale factorscaleY- y scale factorfocusX- the x coordinate of the point to zoom aroundfocusY- the y coordinate of the point to zoom aroundapplyLimits- limit the transform to the edges of the view
-
getZoomTransform
public static float[] getZoomTransform(InterlacedView view, float scaleX, float scaleY, float focusX, float focusY, boolean applyLimits)
Returns anMatrixto zoom around a point.
(Convenience method with fewer arguments, using view to get localMatrix and rectMatrix.)- Parameters:
view- the interlaced view being transformedscaleX- x scale factorscaleY- y scale factorfocusX- the x coordinate of the point to zoom aroundfocusY- the y coordinate of the point to zoom aroundapplyLimits- limit the transform to the edges of the view
-
getZoomMatrix
public static Matrix getZoomMatrix(InterlacedView view, Matrix scaleTypeMatrix, Matrix localMatrix, float scaleX, float scaleY, float focusX, float focusY, boolean applyLimits)
Returns aMatrixto zoom around a point.- Parameters:
view- the interlaced view being transformedscaleTypeMatrix- the scaleType matrix used by the viewlocalMatrix- the current zoom/pan transformscaleX- x scale factorscaleY- y scale factorfocusX- the x coordinate of the point to zoom aroundfocusY- the y coordinate of the point to zoom aroundapplyLimits- limit the transform to the edges of the view
-
getTranslationTransform
public static float[] getTranslationTransform(InterlacedView view, float[] rectMatrix, float[] localMatrix, float panX, float panY, boolean applyLimits)
Returns anMatrixto translate the contents of a view.- Parameters:
view- the interlaced view being transformedrectMatrix- the scaleType matrix used by the viewlocalMatrix- the current zoom/pan transformpanX- x translation distancepanY- y translation distanceapplyLimits- limit the transform to the edges of the view
-
getTranslationTransform
public static float[] getTranslationTransform(InterlacedView view, float panX, float panY, boolean applyLimits)
Returns anMatrixto translate the contents of a view.
(Convenience method with fewer arguments, using view to get localMatrix and rectMatrix.)- Parameters:
view- the interlaced view being transformedpanX- x translation distancepanY- y translation distanceapplyLimits- limit the transform to the edges of the view
-
getTranslationMatrix
public static Matrix getTranslationMatrix(InterlacedView view, Matrix scaleTypeMatrix, Matrix localMatrix, float panX, float panY, boolean applyLimits)
Returns aMatrixto translate the contents of a view.- Parameters:
view- the interlaced view being transformedscaleTypeMatrix- the scaleType matrix used by the viewlocalMatrix- the current zoom/pan transformpanX- x translation distancepanY- y translation distanceapplyLimits- limit the transform to the edges of the view
-
transformPoint
public static PointF transformPoint(float[] matrix, @NonNull PointF point)
Returns a 2D point transformed by a matrix.- Parameters:
matrix- a 4x4 transform matrixpoint- a 2D point to transform
-
transformPoint
public static PointF transformPoint(float[] matrix, @NonNull PointF point, float w)
Returns a 2D point or vector transformed by a matrix.- Parameters:
matrix- a 4x4 transform matrixpoint- a 2D point/vector to transformw- the w value for (point.x, point.y, 0, w) used for transforming the point/vector
-
transformVector
public static PointF transformVector(float[] matrix, @NonNull PointF vector)
Returns a 2D vector transformed by a matrix.- Parameters:
matrix- a 4x4 transform matrixvector- a 2D vector to transform
-
-