<commit_before>﻿using Perspex;

namespace MatrixPanAndZoomDemo.Perspex
{
    // http://referencesource.microsoft.com/#WindowsBase/Base/System/Windows/Media/Matrix.cs,13b7d422c46ba7a0,references
    // https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX.Mathematics/Matrix3x2.cs

    public static class MatrixHelper
    {
        public static Matrix Rotation(double angle, Vector center)
        {
            return
                Matrix.CreateTranslation(-center)
                * Matrix.CreateRotation(angle)
                * Matrix.CreateTranslation(center);
        }

        public static Point TransformPoint(Matrix matrix, Point point)
        {
            return new Point(
                (point.X * matrix.M11) + (point.Y * matrix.M21) + matrix.M31,
                (point.X * matrix.M12) + (point.Y * matrix.M22) + matrix.M32);
        }

        public static Matrix ScaleAt(double scaleX, double scaleY, double centerX, double centerY)
        {
            //Point center = new Point(centerX, centerY);
            //return Matrix.CreateTranslation(-center)
            //    * Matrix.CreateScale(scaleX, scaleY)
            //    * Matrix.CreateTranslation(center);
            return new Matrix(scaleX, 0, 0, scaleY, centerX - scaleX * centerX, centerY - scaleY * centerY);
        }

        public static Matrix ScaleAtPrepend(Matrix matrix, double scaleX, double scaleY, double centerX, double centerY)
        {
            //Point center = new Point(centerX, centerY);
            //return Matrix.CreateTranslation(-center)
            //    * Matrix.CreateScale(scaleX, scaleY)
            //    * Matrix.CreateTranslation(center)
            //    * matrix;
            return new Matrix(scaleX, 0, 0, scaleY, centerX - scaleX * centerX, centerY - scaleY * centerY) * matrix;
        }

        public static Matrix TranslatePrepend(Matrix matrix, double offsetX, double offsetY)
        {
            return Matrix.CreateTranslation(offsetX, offsetY) * matrix;
        }
    }
}<commit_msg>Added Translation method<commit_after>﻿using Perspex;

namespace MatrixPanAndZoomDemo.Perspex
{
    // http://referencesource.microsoft.com/#WindowsBase/Base/System/Windows/Media/Matrix.cs,13b7d422c46ba7a0,references
    // https://github.com/sharpdx/SharpDX/blob/master/Source/SharpDX.Mathematics/Matrix3x2.cs

    public static class MatrixHelper
    {
        public static Matrix Translation(double offsetX, double offsetY)
        {
            return new Matrix(1.0, 0.0, 0.0, 1.0, offsetX, offsetY);
        }
        
        public static Matrix TranslatePrepend(Matrix matrix, double offsetX, double offsetY)
        {
            return Translation(offsetX, offsetY) * matrix;
        }

        public static Matrix Rotation(double angle, Vector center)
        {
            return
                Matrix.CreateTranslation(-center)
                * Matrix.CreateRotation(angle)
                * Matrix.CreateTranslation(center);
        }

        public static Point TransformPoint(Matrix matrix, Point point)
        {
            return new Point(
                (point.X * matrix.M11) + (point.Y * matrix.M21) + matrix.M31,
                (point.X * matrix.M12) + (point.Y * matrix.M22) + matrix.M32);
        }

        public static Matrix ScaleAt(double scaleX, double scaleY, double centerX, double centerY)
        {
            //Point center = new Point(centerX, centerY);
            //return Matrix.CreateTranslation(-center)
            //    * Matrix.CreateScale(scaleX, scaleY)
            //    * Matrix.CreateTranslation(center);
            return new Matrix(scaleX, 0, 0, scaleY, centerX - scaleX * centerX, centerY - scaleY * centerY);
        }

        public static Matrix ScaleAtPrepend(Matrix matrix, double scaleX, double scaleY, double centerX, double centerY)
        {
            //Point center = new Point(centerX, centerY);
            //return Matrix.CreateTranslation(-center)
            //    * Matrix.CreateScale(scaleX, scaleY)
            //    * Matrix.CreateTranslation(center)
            //    * matrix;
            return new Matrix(scaleX, 0, 0, scaleY, centerX - scaleX * centerX, centerY - scaleY * centerY) * matrix;
        }
    }
}
{'fraction_non_alphanumeric': 0.10021271567005437, 'fraction_numerical': 0.015126447648310093, 'mean_word_length': 2.0800582241630274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6636492', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1145, 'n_words': 265}