Package com.leia.core

Class MatrixUtils


  • public class MatrixUtils
    extends Object
    MatrixUtils is a collection of functions for various matrix operations.

    Android provides two matrix representations, Matrix and Matrix, 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 Detail

      • MatrixUtils

        public MatrixUtils()
    • Method Detail

      • GetScaleTypeMatrix

        public static Matrix GetScaleTypeMatrix​(ScaleType scaleType,
                                                RectF srcRect,
                                                RectF destRect)
        Returns a Matrix to 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 an Matrix to zoom around a point.
        Parameters:
        view - the interlaced view being transformed
        rectMatrix - the scaleType matrix used by the view
        localMatrix - the current zoom/pan transform
        scaleX - x scale factor
        scaleY - y scale factor
        focusX - the x coordinate of the point to zoom around
        focusY - the y coordinate of the point to zoom around
        applyLimits - 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 an Matrix to zoom around a point.
        (Convenience method with fewer arguments, using view to get localMatrix and rectMatrix.)
        Parameters:
        view - the interlaced view being transformed
        scaleX - x scale factor
        scaleY - y scale factor
        focusX - the x coordinate of the point to zoom around
        focusY - the y coordinate of the point to zoom around
        applyLimits - 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 a Matrix to zoom around a point.
        Parameters:
        view - the interlaced view being transformed
        scaleTypeMatrix - the scaleType matrix used by the view
        localMatrix - the current zoom/pan transform
        scaleX - x scale factor
        scaleY - y scale factor
        focusX - the x coordinate of the point to zoom around
        focusY - the y coordinate of the point to zoom around
        applyLimits - 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 an Matrix to translate the contents of a view.
        Parameters:
        view - the interlaced view being transformed
        rectMatrix - the scaleType matrix used by the view
        localMatrix - the current zoom/pan transform
        panX - x translation distance
        panY - y translation distance
        applyLimits - limit the transform to the edges of the view
      • getTranslationTransform

        public static float[] getTranslationTransform​(InterlacedView view,
                                                      float panX,
                                                      float panY,
                                                      boolean applyLimits)
        Returns an Matrix to translate the contents of a view.
        (Convenience method with fewer arguments, using view to get localMatrix and rectMatrix.)
        Parameters:
        view - the interlaced view being transformed
        panX - x translation distance
        panY - y translation distance
        applyLimits - 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 a Matrix to translate the contents of a view.
        Parameters:
        view - the interlaced view being transformed
        scaleTypeMatrix - the scaleType matrix used by the view
        localMatrix - the current zoom/pan transform
        panX - x translation distance
        panY - y translation distance
        applyLimits - 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 matrix
        point - 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 matrix
        point - a 2D point/vector to transform
        w - 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 matrix
        vector - a 2D vector to transform
      • ToMatrix

        public static Matrix ToMatrix​(float[] matrixIn)
        Convert a 4x4 Matrix to a 3x3 Matrix.
        Parameters:
        matrixIn - a 4x4 Matrix
      • FromMatrix

        public static float[] FromMatrix​(Matrix matrixIn)
        Convert a 3x3 Matrix to a 4x4 Matrix.
        Parameters:
        matrixIn - a 3x3 Matrix