public void PerformOperation(object sender, RoutedEventArgs e) { var li = sender as RadioButton; string syntaxString, resultType, operationString; switch (li?.Name) { // begin switch case "rb1": { // Multiplies a Matrix by a Matrix using the overloaded * operator // Returns a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var isInvertible = matrix1.HasInverse; // isInvertible is equal to True // Displaying Results syntaxString = "isInvertible = matrix1.HasInverse;"; resultType = "Boolean"; operationString = "Checking if matrix1 is invertible"; ShowResults(isInvertible.ToString(), syntaxString, resultType, operationString); break; } case "rb2": { // Translates a Matrix // Returns a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); const double offsetX = 15; const double offsetY = 25; matrix1.Translate(offsetX, offsetY); // matrix1 is not equal to //Displaying Results syntaxString = "matrix1.Translate(offsetX, offsetY);"; resultType = "Void"; operationString = "Translating a Matrix by a Point"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb3": { // Prepend a Tranlsation to a Matrix // Returns a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); const double offsetX = 15; const double offsetY = 25; matrix1.TranslatePrepend(offsetX, offsetY); // matrix1 is not equal to //Displaying Results syntaxString = " matrix1.TranslatePrepend(offsetX, offsetY);"; resultType = "Void"; operationString = "Prepending Translating a matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb4": { // Sets a Matrix to an identity matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1.SetIdentity(); // matrix1 is now equal to (1,0,0,1,0,0) //Displaying Results syntaxString = "matrix1.SetIdentity();"; resultType = "Void"; operationString = "Setting a matrix to an identity matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb5": { // Checks if a Matrix is an identity matrix // Creates a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); // Sets matrix1 into an identity matrix matrix1.SetIdentity(); var isIdentityMatrix = matrix1.IsIdentity; // isIdentityMatrix is equal to True //Displaying Results syntaxString = "isIdentityMatrix = matrix1.IsIdentity;"; resultType = "Boolean"; operationString = "Determining if a Matrix is an identity matrix"; ShowResults(isIdentityMatrix.ToString(), syntaxString, resultType, operationString); break; } case "rb6": { // Changes a Matrix into an identity matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1 = System.Windows.Media.Matrix.Identity; // matrix1 is now equal to (1,0,0,1,0,0) //Displaying Results syntaxString = "matrix1 = Matrix.Identity;"; resultType = "Matrix"; operationString = "Gets an identity Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb7": { // Converts a string representation of a matrix into a Matrix structure var matrixResult = new System.Windows.Media.Matrix(); matrixResult = System.Windows.Media.Matrix.Parse("1,2,3,4,5,6"); // matrixResult is equal to (1,2,3,4,5,6) //Displaying Results syntaxString = "matrixResult = Matrix.Parse(\"1,2,3,4,5,6\");"; resultType = "Matrix"; operationString = "Convert a string into a Matrix structure"; ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString); break; } case "rb8": { // Checks if two Matrixes are equal using the static Equals method // Returns a Boolean. var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var areEqual = System.Windows.Media.Matrix.Equals(matrix1, matrix2); // areEqual is equal to False //Displaying Results syntaxString = "areEqual = Matrix.Equals(matrix1, matrix2);"; resultType = "Boolean"; operationString = "Checking if the matrices are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb8b": { // Checks if an Object is equal to a Matrix using the static Equals method // Returns a Boolean. var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var areEqual = matrix1.Equals(matrix2); // areEqual is equal to False //Displaying Results syntaxString = "areEqual = Matrix.Equals(matrix1, matrix2);"; resultType = "Boolean"; operationString = "Checking if the matrices are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb9": { // Checks if two Matrixes are equal using the overloaded == operator // Returns a Boolean. var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var areEqual = matrix1 == matrix2; // areEqual is equal to False //Displaying Results syntaxString = "areEqual = matrix1 == matrix2;"; resultType = "Boolean"; operationString = "Checking if the matrices are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb10": { // Checks if two Matrixes are not equal using the overloaded != operator // Returns a Boolean. var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var areEqual = matrix1 != matrix2; // areEqual is equal to False //Displaying Results syntaxString = "areEqual = matrix1 != matrix2;"; resultType = "Boolean"; operationString = "Checking if the matrices are not equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb11": { // Inverts a Matrix // Creating a Matrix structure var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); // Checking if matrix1 is invertible if (matrix1.HasInverse) { // Inverting matrix1 matrix1.Invert(); // matrix1 is equal to (-0.04, 0.2 , 0.3, -0.1, 1, -2) } //Displaying Results syntaxString = "matrix1.Invert();"; resultType = "Void"; operationString = "Inverting a matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb12": { // Prepends a Matrix to another Matrix. var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); matrix1.Prepend(matrix2); // matrix1 is equal to (70,100,150,220,255,370) //Displaying Results syntaxString = "matrix1.Prepend(matrix2);"; resultType = "Void"; operationString = "Prepending a Matrix to another Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb13": { // Appends a Matrix to another Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); matrix1.Append(matrix2); // matrix1 is equal to (70,100,150,220,240,352) //Displaying Results syntaxString = "matrix1.Append(matrix2);"; resultType = "Void"; operationString = "Appending a Matrix to another Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb14": { // Rotates a Matrix by a specified angle var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double rotateAngle = 90; matrix1.Rotate(rotateAngle); // matrix1 is equal to (-10,5,-20,15,-30,25) //Displaying Results syntaxString = "matrix1.Rotate(rotateAngle);"; resultType = "Void"; operationString = "Rotating a Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb15": { // Rotates a Matrix by a specified angle at a specific point var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1.RotateAt(90, 2, 4); // matrix1 is equal to (-10,5,-20,15,-24,27) //Displaying Results syntaxString = "matrix1.RotateAt(rotateAngle, rotateCenterX, rotateCenterY);"; resultType = "Void"; operationString = "Rotating a Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb16": { // Prepends a Rotation to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double rotateAngle = 90; matrix1.RotatePrepend(rotateAngle); // matrix1 is equal to (15,20,-5,-10,25,30) //Displaying Results syntaxString = "matrix1.RotatePrepend(rotateAngle);"; resultType = "Void"; operationString = "Rotating a Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb17": { // Prepends a Rotation at a specific point to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1.RotateAtPrepend(90, 2, 4); // matrix1 is equal to (15,20,-5,-10,85,130) //Displaying Results syntaxString = "matrix1.RotateAtPrepend(rotateAngle, rotateCenterX, rotateCenterY);"; resultType = "Void"; operationString = "Rotating a Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb18": { // Scales a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double scaleX = (1); double scaleY = (2); matrix1.Scale(scaleX, scaleY); // matrix1 is equal to //Displaying Results syntaxString = "matrix1.Scale(scaleX, scaleY);"; resultType = "Void"; operationString = "Scaling a Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb19": { // Multiplies a Matrix by another Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var matrixResult = new System.Windows.Media.Matrix(); matrixResult = System.Windows.Media.Matrix.Multiply(matrix2, matrix1); // matrixResult is equal to (70, 100, 150, 220, 255, 370) //Displaying Results syntaxString = "matrixResult = Matrix.Multiply(matrix2, matrix1);"; resultType = "Matrix"; operationString = "Multiplying matrix1 and matrix2"; ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString); break; } case "rb20": { // Multiplies a Matrix by another Matrix using the overloaded * operator var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var matrixResult = new System.Windows.Media.Matrix(); matrixResult = matrix1*matrix2; // matrixResult is equal to (70, 100, 150, 220, 240, 352) //Displaying Results syntaxString = " matrixResult = matrix1 * matrix2;"; resultType = "Matrix"; operationString = "Multiplying matrix1 and matrix2"; ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString); break; } case "rb21": { // Appends a skew to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double skewAngleX = 45; double skewAngleY = 180; matrix1.Skew(skewAngleX, skewAngleY); // matrix1 is equal to (15, 10, 35, 20, 55, 30) //Displaying Results syntaxString = "matrix1.Skew(skewAngleX, skewAngleY);"; resultType = "Void"; operationString = "Multiplying matrix2 and matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb22": { // Prepends a skew to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double skewAngleX = 45; double skewAngleY = 180; matrix1.SkewPrepend(skewAngleX, skewAngleY); // matrix1 is equal to (5, 10, 20, 30, 25, 30) //Displaying Results syntaxString = "matrix1.SkewPrepend(skewAngleX, skewAngleY);"; resultType = "Void"; operationString = "Multiplying matrix2 and matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb23": { // Appends a scale to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double scaleFactorX = 2; double scaleFactorY = 4; matrix1.Scale(scaleFactorX, scaleFactorY); // matrix1 is equal to (10, 40, 30, 80, 50, 120) //Displaying Results syntaxString = "matrix1.Scale(scaleFactorX, scaleFactorY);"; resultType = "Void"; operationString = "Appending a scale to a matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb24": { // Appends a scale at a specific point to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1.ScaleAt(2, 4, 5, 10); // matrix1 is equal to (10, 40, 30, 80, 45, 90) //Displaying Results syntaxString = " matrix1.ScaleAt(scaleFactorX, scaleFactorY, scaleCenterX, scaleCenterY);"; resultType = "Void"; operationString = "Appends a scale at a specific point to matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb25": { // Prepends a scale to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double scaleFactorX = 2; double scaleFactorY = 4; matrix1.ScalePrepend(scaleFactorX, scaleFactorY); // matrix1 is equal to (10, 20, 60, 80, 25, 30) //Displaying Results syntaxString = "matrix1.ScalePrepend(scaleFactorX, scaleFactorY);"; resultType = "Void"; operationString = "Prepending a scale to matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb26": { // Prepends a scale at a specific point to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1.ScaleAtPrepend(2, 4, 5, 10); // matrix1 is equal to (10, 20, 60, 80, -450, -620) //Displaying Results syntaxString = "matrix1.ScalePrependAt(scaleFactorX, scaleFactorY, centerPointX, centerPointY);"; resultType = "Void"; operationString = "Prepending a scale at a specific point to matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb29": { // Transform a point by a matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var point1 = new Point(15, 25); var pointResult = new Point(); pointResult = matrix1.Transform(point1); // pointResult is equal to (475, 680) //Displaying Results syntaxString = "pointResult = matrix1.Transform(point1)"; resultType = "Point"; operationString = "Transforming a point1 by matrix1"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb30": { // Transform a Vector by a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var vector1 = new Vector(15, 25); new Vector(); matrix1.Transform(vector1); // vectorResult is equal to (450, 650) //Displaying Results syntaxString = "vectorResult = matrix1.Transform(vector1);"; resultType = "Vector"; operationString = "Multiplying matrix2 and matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb31": { // Transform an array of Points by a Matrix // Creating a Matrix and an array of Pointers var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var pointArray = new Point[2]; // Setting the Point's X and Y values pointArray[0].X = 15; pointArray[0].Y = 25; pointArray[1].X = 30; pointArray[1].Y = 35; // Transforming the Points in pointArry by matrix1 matrix1.Transform(pointArray); // pointArray[0] is equal to (475, 680) // pointArray[1] is equal to (700, 1030) //Displaying Results syntaxString = "matrix1.Transform(pointArray);"; resultType = "void"; operationString = "Transforming an array of Points by matrix1"; ShowResults(pointArray[1].ToString(), syntaxString, resultType, operationString); break; } case "rb32": { // Transform an array of Vectors by a Matrix // Creating a Matrix and an array of Vectors var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var vectorArray = new Vector[2]; // Setting the Vector's X and Y values vectorArray[0].X = 15; vectorArray[0].Y = 25; vectorArray[1].X = 30; vectorArray[1].Y = 35; // Transforming the Vectors in vectorArray by matrix1 matrix1.Transform(vectorArray); // VectorArray[0] is equal to (450, 650) // VectorArray[1] is equal to (675, 1000) //Displaying Results syntaxString = " matrix1.Transform(vectorArray);"; resultType = "Void"; operationString = "Multiplying matrix2 and matrix1"; ShowResults(vectorArray[0].ToString(), syntaxString, resultType, operationString); break; } } // end switch }
public void PerformOperation(object sender, RoutedEventArgs e) { var li = sender as RadioButton; string syntaxString, resultType, operationString; switch (li?.Name) { // begin switch case "rb1": { // Multiplies a Matrix by a Matrix using the overloaded * operator // Returns a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var isInvertible = matrix1.HasInverse; // isInvertible is equal to True // Displaying Results syntaxString = "isInvertible = matrix1.HasInverse;"; resultType = "Boolean"; operationString = "Checking if matrix1 is invertible"; ShowResults(isInvertible.ToString(), syntaxString, resultType, operationString); break; } case "rb2": { // Translates a Matrix // Returns a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); const double offsetX = 15; const double offsetY = 25; matrix1.Translate(offsetX, offsetY); // matrix1 is not equal to //Displaying Results syntaxString = "matrix1.Translate(offsetX, offsetY);"; resultType = "Void"; operationString = "Translating a Matrix by a Point"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb3": { // Prepend a Tranlsation to a Matrix // Returns a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); const double offsetX = 15; const double offsetY = 25; matrix1.TranslatePrepend(offsetX, offsetY); // matrix1 is not equal to //Displaying Results syntaxString = " matrix1.TranslatePrepend(offsetX, offsetY);"; resultType = "Void"; operationString = "Prepending Translating a matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb4": { // Sets a Matrix to an identity matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1.SetIdentity(); // matrix1 is now equal to (1,0,0,1,0,0) //Displaying Results syntaxString = "matrix1.SetIdentity();"; resultType = "Void"; operationString = "Setting a matrix to an identity matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb5": { // Checks if a Matrix is an identity matrix // Creates a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); // Sets matrix1 into an identity matrix matrix1.SetIdentity(); var isIdentityMatrix = matrix1.IsIdentity; // isIdentityMatrix is equal to True //Displaying Results syntaxString = "isIdentityMatrix = matrix1.IsIdentity;"; resultType = "Boolean"; operationString = "Determining if a Matrix is an identity matrix"; ShowResults(isIdentityMatrix.ToString(), syntaxString, resultType, operationString); break; } case "rb6": { // Changes a Matrix into an identity matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1 = System.Windows.Media.Matrix.Identity; // matrix1 is now equal to (1,0,0,1,0,0) //Displaying Results syntaxString = "matrix1 = Matrix.Identity;"; resultType = "Matrix"; operationString = "Gets an identity Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb7": { // Converts a string representation of a matrix into a Matrix structure var matrixResult = new System.Windows.Media.Matrix(); matrixResult = System.Windows.Media.Matrix.Parse("1,2,3,4,5,6"); // matrixResult is equal to (1,2,3,4,5,6) //Displaying Results syntaxString = "matrixResult = Matrix.Parse(\"1,2,3,4,5,6\");"; resultType = "Matrix"; operationString = "Convert a string into a Matrix structure"; ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString); break; } case "rb8": { // Checks if two Matrixes are equal using the static Equals method // Returns a Boolean. var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var areEqual = System.Windows.Media.Matrix.Equals(matrix1, matrix2); // areEqual is equal to False //Displaying Results syntaxString = "areEqual = Matrix.Equals(matrix1, matrix2);"; resultType = "Boolean"; operationString = "Checking if the matrices are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb8b": { // Checks if an Object is equal to a Matrix using the static Equals method // Returns a Boolean. var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var areEqual = matrix1.Equals(matrix2); // areEqual is equal to False //Displaying Results syntaxString = "areEqual = Matrix.Equals(matrix1, matrix2);"; resultType = "Boolean"; operationString = "Checking if the matrices are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb9": { // Checks if two Matrixes are equal using the overloaded == operator // Returns a Boolean. var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var areEqual = matrix1 == matrix2; // areEqual is equal to False //Displaying Results syntaxString = "areEqual = matrix1 == matrix2;"; resultType = "Boolean"; operationString = "Checking if the matrices are equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb10": { // Checks if two Matrixes are not equal using the overloaded != operator // Returns a Boolean. var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var areEqual = matrix1 != matrix2; // areEqual is equal to False //Displaying Results syntaxString = "areEqual = matrix1 != matrix2;"; resultType = "Boolean"; operationString = "Checking if the matrices are not equal"; ShowResults(areEqual.ToString(), syntaxString, resultType, operationString); break; } case "rb11": { // Inverts a Matrix // Creating a Matrix structure var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); // Checking if matrix1 is invertible if (matrix1.HasInverse) { // Inverting matrix1 matrix1.Invert(); // matrix1 is equal to (-0.04, 0.2 , 0.3, -0.1, 1, -2) } //Displaying Results syntaxString = "matrix1.Invert();"; resultType = "Void"; operationString = "Inverting a matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb12": { // Prepends a Matrix to another Matrix. var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); matrix1.Prepend(matrix2); // matrix1 is equal to (70,100,150,220,255,370) //Displaying Results syntaxString = "matrix1.Prepend(matrix2);"; resultType = "Void"; operationString = "Prepending a Matrix to another Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb13": { // Appends a Matrix to another Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); matrix1.Append(matrix2); // matrix1 is equal to (70,100,150,220,240,352) //Displaying Results syntaxString = "matrix1.Append(matrix2);"; resultType = "Void"; operationString = "Appending a Matrix to another Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb14": { // Rotates a Matrix by a specified angle var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double rotateAngle = 90; matrix1.Rotate(rotateAngle); // matrix1 is equal to (-10,5,-20,15,-30,25) //Displaying Results syntaxString = "matrix1.Rotate(rotateAngle);"; resultType = "Void"; operationString = "Rotating a Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb15": { // Rotates a Matrix by a specified angle at a specific point var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1.RotateAt(90, 2, 4); // matrix1 is equal to (-10,5,-20,15,-24,27) //Displaying Results syntaxString = "matrix1.RotateAt(rotateAngle, rotateCenterX, rotateCenterY);"; resultType = "Void"; operationString = "Rotating a Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb16": { // Prepends a Rotation to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double rotateAngle = 90; matrix1.RotatePrepend(rotateAngle); // matrix1 is equal to (15,20,-5,-10,25,30) //Displaying Results syntaxString = "matrix1.RotatePrepend(rotateAngle);"; resultType = "Void"; operationString = "Rotating a Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb17": { // Prepends a Rotation at a specific point to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1.RotateAtPrepend(90, 2, 4); // matrix1 is equal to (15,20,-5,-10,85,130) //Displaying Results syntaxString = "matrix1.RotateAtPrepend(rotateAngle, rotateCenterX, rotateCenterY);"; resultType = "Void"; operationString = "Rotating a Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb18": { // Scales a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double scaleX = (1); double scaleY = (2); matrix1.Scale(scaleX, scaleY); // matrix1 is equal to //Displaying Results syntaxString = "matrix1.Scale(scaleX, scaleY);"; resultType = "Void"; operationString = "Scaling a Matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb19": { // Multiplies a Matrix by another Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var matrixResult = new System.Windows.Media.Matrix(); matrixResult = System.Windows.Media.Matrix.Multiply(matrix2, matrix1); // matrixResult is equal to (70, 100, 150, 220, 255, 370) //Displaying Results syntaxString = "matrixResult = Matrix.Multiply(matrix2, matrix1);"; resultType = "Matrix"; operationString = "Multiplying matrix1 and matrix2"; ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString); break; } case "rb20": { // Multiplies a Matrix by another Matrix using the overloaded * operator var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12); var matrixResult = new System.Windows.Media.Matrix(); matrixResult = matrix1 * matrix2; // matrixResult is equal to (70, 100, 150, 220, 240, 352) //Displaying Results syntaxString = " matrixResult = matrix1 * matrix2;"; resultType = "Matrix"; operationString = "Multiplying matrix1 and matrix2"; ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString); break; } case "rb21": { // Appends a skew to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double skewAngleX = 45; double skewAngleY = 180; matrix1.Skew(skewAngleX, skewAngleY); // matrix1 is equal to (15, 10, 35, 20, 55, 30) //Displaying Results syntaxString = "matrix1.Skew(skewAngleX, skewAngleY);"; resultType = "Void"; operationString = "Multiplying matrix2 and matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb22": { // Prepends a skew to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double skewAngleX = 45; double skewAngleY = 180; matrix1.SkewPrepend(skewAngleX, skewAngleY); // matrix1 is equal to (5, 10, 20, 30, 25, 30) //Displaying Results syntaxString = "matrix1.SkewPrepend(skewAngleX, skewAngleY);"; resultType = "Void"; operationString = "Multiplying matrix2 and matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb23": { // Appends a scale to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double scaleFactorX = 2; double scaleFactorY = 4; matrix1.Scale(scaleFactorX, scaleFactorY); // matrix1 is equal to (10, 40, 30, 80, 50, 120) //Displaying Results syntaxString = "matrix1.Scale(scaleFactorX, scaleFactorY);"; resultType = "Void"; operationString = "Appending a scale to a matrix"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb24": { // Appends a scale at a specific point to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1.ScaleAt(2, 4, 5, 10); // matrix1 is equal to (10, 40, 30, 80, 45, 90) //Displaying Results syntaxString = " matrix1.ScaleAt(scaleFactorX, scaleFactorY, scaleCenterX, scaleCenterY);"; resultType = "Void"; operationString = "Appends a scale at a specific point to matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb25": { // Prepends a scale to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); double scaleFactorX = 2; double scaleFactorY = 4; matrix1.ScalePrepend(scaleFactorX, scaleFactorY); // matrix1 is equal to (10, 20, 60, 80, 25, 30) //Displaying Results syntaxString = "matrix1.ScalePrepend(scaleFactorX, scaleFactorY);"; resultType = "Void"; operationString = "Prepending a scale to matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb26": { // Prepends a scale at a specific point to a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); matrix1.ScaleAtPrepend(2, 4, 5, 10); // matrix1 is equal to (10, 20, 60, 80, -450, -620) //Displaying Results syntaxString = "matrix1.ScalePrependAt(scaleFactorX, scaleFactorY, centerPointX, centerPointY);"; resultType = "Void"; operationString = "Prepending a scale at a specific point to matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb29": { // Transform a point by a matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var point1 = new Point(15, 25); var pointResult = new Point(); pointResult = matrix1.Transform(point1); // pointResult is equal to (475, 680) //Displaying Results syntaxString = "pointResult = matrix1.Transform(point1)"; resultType = "Point"; operationString = "Transforming a point1 by matrix1"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb30": { // Transform a Vector by a Matrix var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var vector1 = new Vector(15, 25); new Vector(); matrix1.Transform(vector1); // vectorResult is equal to (450, 650) //Displaying Results syntaxString = "vectorResult = matrix1.Transform(vector1);"; resultType = "Vector"; operationString = "Multiplying matrix2 and matrix1"; ShowResults(matrix1.ToString(), syntaxString, resultType, operationString); break; } case "rb31": { // Transform an array of Points by a Matrix // Creating a Matrix and an array of Pointers var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var pointArray = new Point[2]; // Setting the Point's X and Y values pointArray[0].X = 15; pointArray[0].Y = 25; pointArray[1].X = 30; pointArray[1].Y = 35; // Transforming the Points in pointArry by matrix1 matrix1.Transform(pointArray); // pointArray[0] is equal to (475, 680) // pointArray[1] is equal to (700, 1030) //Displaying Results syntaxString = "matrix1.Transform(pointArray);"; resultType = "void"; operationString = "Transforming an array of Points by matrix1"; ShowResults(pointArray[1].ToString(), syntaxString, resultType, operationString); break; } case "rb32": { // Transform an array of Vectors by a Matrix // Creating a Matrix and an array of Vectors var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30); var vectorArray = new Vector[2]; // Setting the Vector's X and Y values vectorArray[0].X = 15; vectorArray[0].Y = 25; vectorArray[1].X = 30; vectorArray[1].Y = 35; // Transforming the Vectors in vectorArray by matrix1 matrix1.Transform(vectorArray); // VectorArray[0] is equal to (450, 650) // VectorArray[1] is equal to (675, 1000) //Displaying Results syntaxString = " matrix1.Transform(vectorArray);"; resultType = "Void"; operationString = "Multiplying matrix2 and matrix1"; ShowResults(vectorArray[0].ToString(), syntaxString, resultType, operationString); break; } } // end switch }
/// <summary> /// Scales the <see cref="Image"/> vertically and horizontally without changing its resolution. /// </summary> /// <param name="dst">The destination <see cref="Image"/>. Can be <b>null</b>.</param> /// <param name="width">The desired width of the image, in pixels.</param> /// <param name="height">The desired height of the image, in pixels.</param> /// <param name="options">The scaling options.</param> /// <returns> /// The destination <see cref="Image"/>. /// </returns> public Image ScaleToSize(Image dst, int width, int height, ScalingOptions options) { if (width == this.Width && height == this.Height) { return(this.Copy(dst, true)); } if (width <= 0) { throw new ArgumentException(Properties.Resources.E_InvalidWidth, nameof(width)); } if (height <= 0) { throw new ArgumentException(Properties.Resources.E_InvalidHeight, nameof(height)); } System.Windows.Media.Matrix matrix = System.Windows.Media.Matrix.Identity; matrix.Scale((double)width / this.Width, (double)height / this.Height); #if false dst = this.Affine(dst, matrix, BorderType.BorderConst, this.WhiteColor); Debug.Assert(width == dst.Width && height == dst.Height, "Image dimensions are wrong."); return(dst); #else // IPP does not support 1bpp images - convert to 8bpp Image src; bool convert1bpp = false; if (this.BitsPerPixel == 1) { src = this.Convert1To8(null); convert1bpp = true; } else { src = this; } bool inplace = dst == this; dst = src.CreateTemplate(dst, width, height, src.BitsPerPixel); IPP.Execute(() => { return(NativeMethods.resize( src.BitsPerPixel, src.Width, src.Height, src.Bits, src.Stride8, dst.Width, dst.Height, dst.Bits, dst.Stride8, options.InterpolationType, options.Antialiasing, options.ValueB, options.ValueC, options.Lobes, BorderType.BorderConst, src.WhiteColor)); }); dst.AppendTransform(new MatrixTransform(matrix)); // convert back to 1bpp if (convert1bpp) { dst.Convert8To1(dst, 1); } if (inplace) { this.Attach(dst); return(this); } return(dst); #endif }
public override void Render(Feature feature) { if (_recursion > _window.MaxRecursion) return; RenderCount++; var geometry = feature.Geometry; //geometry = geometry.Envelope; if (geometry.OgcGeometryType != OgcGeometryType.Polygon && geometry.OgcGeometryType != OgcGeometryType.MultiPolygon) return; if (feature.Fid != 6306) return; //evaluate fields var centerX = Evaluate(_centerXEvaluator, _centerX); var centerY = Evaluate(_centerYEvaluator, _centerY); var zoom = Evaluate(_zoomEvaluator, _zoom); var angle = Evaluate(_angleEvaluator, _angle); var centroid = geometry.Centroid.ToWinPoint(); //temporary debug value //_zoom = (_zoom + 10) % 360; //centerX = centroid.X + 25; //centerY = centroid.Y; //zoom = 0.5; //angle = -_zoom; //clip path coordinates var coordinates = ToWinPointArray(geometry.Coordinates); Renderer.Transform(coordinates); var coordinatesF = coordinates.ToPointFArray(); var clipPath = new GraphicsPath(); clipPath.AddPolygon(coordinatesF); //camera transform var camera = new WinMatrix(); camera.Translate(-centroid.X, -centroid.Y); camera.Scale(1/zoom, 1/zoom); camera.Rotate(-angle); camera.Translate(centerX, centerY); //camera polygon coordinates = ToWinPointArray(geometry.Coordinates); camera.Transform(coordinates); var queryWindow = new Envelope(); ExpendToInclude(queryWindow, coordinates); var oldMatrix = Renderer.Matrix; var invCamera = camera; invCamera.Invert(); var newMatrix = invCamera * oldMatrix; var newTranslate = newMatrix; newTranslate.OffsetX = newTranslate.OffsetY = 0; newTranslate.Invert(); newTranslate = newMatrix * newTranslate; Feature queryFeature = null; Feature windowTargetFeature = null; var newTransform = new System.Drawing.Drawing2D.Matrix((float)newMatrix.M11, (float)newMatrix.M12, (float)newMatrix.M21, (float)newMatrix.M22, 0f, 0f); var oldWindow = Renderer.Window; var savedState = Renderer.Graphics.Save(); var oldModelView = Renderer.Translate; var oldZoom = Renderer.Zoom; //var oldAngle = Renderer.Angle; _recursion++; int i = 0; while (i < Renderers.Count) { var renderer = Renderers[i]; var childNode = renderer.Node; if (childNode is WindowQuery) { if (queryFeature == null) { queryFeature = new Feature(feature); queryFeature.Geometry = Util.ToPolygon(queryWindow); } do renderer.Render(queryFeature); while (++i < Renderers.Count && (childNode = (renderer = Renderers[i]).Node) is WindowQuery); } else if (childNode is WindowTarget) { if (windowTargetFeature == null) { windowTargetFeature = new Feature(feature); windowTargetFeature.Geometry = new Polygon(new LinearRing(ToCoordinateArray(coordinates))); } do renderer.Render(windowTargetFeature); while (++i < Renderers.Count && (childNode = (renderer = Renderers[i]).Node) is WindowTarget); } else { try { Renderer.Window = queryWindow; if (_window.Clip) { var region = Renderer.Graphics.Clip; if (region != null) { region.Intersect(clipPath); Renderer.Graphics.Clip = region; } else Renderer.Graphics.SetClip(clipPath); } Renderer.Matrix = newMatrix; Renderer.Translate = newTranslate; Renderer.Graphics.Transform = newTransform; Renderer.Zoom *= zoom; //Renderer.Angle += angle; //Renderer.Graphics.Clear(Evaluate(_bgColorEvaluator, _bgColor)); do renderer.Render(feature); while (++i < Renderers.Count && !((childNode = (renderer = Renderers[i]).Node) is WindowQuery || childNode is WindowTarget)); } finally { Renderer.Window = oldWindow; Renderer.Graphics.Restore(savedState); Renderer.Translate = oldModelView; Renderer.Zoom = oldZoom; //Renderer.Angle = oldAngle; Renderer.Matrix = oldMatrix; _recursion--; } } } ////debug: render camera polygon //Renderer.Transform(coordinates); //coordinatesF = coordinates.ToPointFArray(); //using (var brush = new SolidBrush(Color.FromArgb(50, Color.Red))) // Renderer.Graphics.FillPolygon(brush, coordinatesF); ////debug: render camera envelope //var points = new[] { new WinPoint(queryWindow.MinX, queryWindow.MinY), new WinPoint(queryWindow.MaxX, queryWindow.MaxY) }; //Renderer.Transform(points); //var size = points[1] - points[0]; //using (var brush = new SolidBrush(Color.FromArgb(50, Color.Green))) // Renderer.Graphics.FillRectangle(brush, (float)points[0].X, (float)points[0].Y, (float)size.X, (float)size.Y); }
private static Vector2 GetTextureCoordinate(double t, double y) { System.Windows.Media.Matrix TYtoUV = new System.Windows.Media.Matrix(); TYtoUV.Scale(1 / (2 * Math.PI), -0.5); System.Windows.Point p = new System.Windows.Point(t, y); p = p * TYtoUV; return new Vector2((float)p.X, (float)p.Y + 0.5f); }