146b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy/*
246b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * Copyright (C) 2018 The Android Open Source Project
346b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy *
446b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * Licensed under the Apache License, Version 2.0 (the "License");
546b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * you may not use this file except in compliance with the License.
646b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * You may obtain a copy of the License at
746b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy *
846b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy *       http://www.apache.org/licenses/LICENSE-2.0
946b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy *
1046b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * Unless required by applicable law or agreed to in writing, software
1146b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * distributed under the License is distributed on an "AS IS" BASIS,
1246b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1346b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * See the License for the specific language governing permissions and
1446b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * limitations under the License.
1546b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy */
1646b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy
1746b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy@file:Suppress("NOTHING_TO_INLINE")
1846b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy
199c80550cbbe357a89e2abeeb9c7769fcaefc3a65Jake Whartonpackage androidx.core.graphics
2046b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy
2146b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guyimport android.graphics.Matrix
2246b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy
2346b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy/**
2446b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * Multiplies this [Matrix] by another matrix and returns the result as
2546b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * a new matrix.
2646b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy */
2746b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guyinline operator fun Matrix.times(m: Matrix) = Matrix(this).apply { preConcat(m) }
2846b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy
2946b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy/**
3046b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * Returns the 9 values of this [Matrix] as a new array of floats.
3146b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy */
3246b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guyinline fun Matrix.values() = FloatArray(9).apply { getValues(this) }
3346b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy
3446b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy/**
3546b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * Creates a translation matrix with the translation amounts [tx] and [ty]
3646b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * respectively on the `x` and `y` axis.
3746b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy */
3846b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guyfun translationMatrix(tx: Float = 0.0f, ty: Float = 0.0f) = Matrix().apply { setTranslate(tx, ty) }
3946b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy
4046b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy/**
4146b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * Creates a scale matrix with the scale factor [sx] and [sy] respectively on the
4246b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * `x` and `y` axis.
4346b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy */
4446b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guyfun scaleMatrix(sx: Float = 1.0f, sy: Float = 1.0f) = Matrix().apply { setScale(sx, sy) }
4546b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy
4646b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy/**
4746b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy * Creates a rotation matrix, defined by a rotation angle in degrees around the pivot
4860a72273a0679873be713ba28099c5a4c71d1d9aRomain Guy * point located at the coordinates ([px], [py]).
4946b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guy */
5046b8a0ef84de421456d4ad06cc7f698d3505422fRomain Guyfun rotationMatrix(degrees: Float, px: Float = 0.0f, py: Float = 0.0f) =
51ec87f3d0ed8fb2a23ee2bbe8b323fdd7bdcbf4eaJake Wharton    Matrix().apply { setRotate(degrees, px, py) }
52