Example #1
0
        public NDArrayGeneric <T> inv()
        {
            NDArrayGeneric <T> npInv = new NDArrayGeneric <T>();

            npInv.Shape = new Shape(this.Shape.Shapes);
            npInv.Data  = new T[this.Data.Length];

            switch (this)
            {
            case NDArrayGeneric <double> np:
            {
                NDArrayGeneric <double> npInvDouble = npInv as NDArrayGeneric <double>;
                double[][] matrix = np.ToDotNetArray <double[][]>();

                double[][] matrixInv = MatrixInv.InverseMatrix(matrix);

                for (int idx = 0; idx < npInv.Shape.Shapes[0]; idx++)
                {
                    for (int jdx = 0; jdx < npInv.Shape.Shapes[1]; jdx++)
                    {
                        npInvDouble[idx, jdx] = matrixInv[idx][jdx];
                    }
                }
                break;
            }

            default:
            {
                throw new Exception("This method was not implemented for this Type : " + typeof(T).Name);
            }
            }

            return(npInv);
        }
Example #2
0
        public NDArray inv()
        {
            var npInv = new NDArray(this.Storage.DType, this.shape);

            Array matrixStorage = this.Storage.GetData();
            Array invStorage    = Array.CreateInstance(npInv.Storage.DType, matrixStorage.Length);

            switch (matrixStorage)
            {
            case double[] np:
            {
                double[][] matrix = new double[this.Storage.Shape.Dimensions[0]][];
                for (int idx = 0; idx < matrix.Length; idx++)
                {
                    matrix[idx] = new double[this.Storage.Shape.Dimensions[1]];
                    for (int jdx = 0; jdx < matrix[idx].Length; jdx++)
                    {
                        matrix[idx][jdx] = np[this.Storage.Shape.GetIndexInShape(idx, jdx)];
                    }
                }

                double[][] matrixInv = MatrixInv.InverseMatrix(matrix);
                double[]   invArray  = invStorage as double[];

                for (int idx = 0; idx < npInv.shape[0]; idx++)
                {
                    for (int jdx = 0; jdx < npInv.shape[1]; jdx++)
                    {
                        invArray[this.Storage.Shape.GetIndexInShape(idx, jdx)] = matrixInv[idx][jdx];
                    }
                }

                break;
            }

            default:
            {
                throw new IncorrectTypeException();
            }
            }

            npInv.Storage.SetData(invStorage);

            return(npInv);
        }
Example #3
0
        public static NDArray <double> Inv(this NDArray <double> np)
        {
            double[][] matrix = np.ToDotNetArray <double[][]>();

            double[][] matrixInv = MatrixInv.InverseMatrix(matrix);

            NDArray <double> npInv = new NDArray <double>().Zeros(np.Shape[0], np.Shape[1]);

            for (int idx = 0; idx < npInv.Shape[0]; idx++)
            {
                for (int jdx = 0; jdx < npInv.Shape[1]; jdx++)
                {
                    npInv[idx, jdx] = matrixInv[idx][jdx];
                }
            }

            return(npInv);
        }
Example #4
0
        public override void Drag(Vector3 position, Quaternion rotation, Vector3 scale)
        {
            if (Meshes == null)
            {
                return;
            }

            Vector3 lp = MatrixInv.MultiplyPoint(position);

            Vector2 delta = new Vector2(-lp.x, -lp.y);

            List <Face> faces = new List <Face>();

            for (int m = 0; m < Meshes.Length; ++m)
            {
                ProBuilderMesh mesh         = Meshes[m];
                Vector2[]      origins      = Origins[m];
                var            uvTransforms = UVTransforms[m];
                int[]          indexes      = Indexes[m];

                Vector2[]       textures = mesh.textures.ToArray();
                IList <Vector4> tangents = mesh.tangents;

                // Account for object scale
                delta *= k_vector3Magnitude / mesh.transform.lossyScale.magnitude;

                for (int i = 0; i < indexes.Length; ++i)
                {
                    int index       = indexes[i];
                    var uvTransform = uvTransforms[i];
                    textures[index] = origins[i] + new Vector2(tangents[index].w * delta.x / uvTransform.scale.x, delta.y / uvTransform.scale.y);
                }

                mesh.textures = textures;
                mesh.GetFaces(Selection.SelectedFaces[mesh.gameObject], faces);

                mesh.RefreshUV(faces);
                faces.Clear();
            }
        }