public static DisplayMatrix BoundsToMatrix(Rect rect, Size defaultSize)
        {
            DisplayMatrix data = new DisplayMatrix();

            //Point corner = rect.TopLeft;
            //Vector sizeVector = new Vector(rect.Size.Width, rect.Size.Height);

            Point center = rect.TopLeft + new Vector(rect.Width / 2, rect.Height / 2);

            Vector scale = new Vector();

            if (defaultSize.Width == 0 || defaultSize.Height == 0)
            {
                throw new DivideByZeroException();
            }

            double scaleX = rect.Size.Width / defaultSize.Width;
            double scaleY = rect.Size.Height / defaultSize.Height;

            scale.X = Math.Min(scaleX, scaleY);
            scale.Y = Math.Min(scaleX, scaleY);

            //Vector offset = ScatterMatrixHelper.CalculateRenderOffset(defaultSize, new Point(0.5, 0.5), center, 0.0, scale);

            //data.Center = new Point(offset.X, offset.Y);
            data.Scale  = scale;
            data.Center = center;
            return(data);
        }
        public static void OrientationPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            DisplayMatrix data = obj as DisplayMatrix;

            if (data == null)
            {
                return;
            }

            data._orientation = MathUtility.NormalizeAngle((double)e.NewValue);
            data.OnViewChanged();
        }
        public static void ScalePropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            DisplayMatrix data = obj as DisplayMatrix;

            if (data == null)
            {
                return;
            }

            data._scale = (Vector)e.NewValue;
            data.UpdateActualSizeFromScale();
            data.OnViewChanged();
        }
        public static void CenterPropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
        {
            DisplayMatrix data = obj as DisplayMatrix;

            if (data == null)
            {
                return;
            }

            data._center = (Point)e.NewValue;
            data.OnViewChanged();
            //data.UpdateMatrix();
        }
        public static Rect MatrixToBounds(DisplayMatrix data, Size size)
        {
            Vector sizeVector = new Vector(size.Width, size.Height);

            sizeVector = data.TransformMatrix.Transform(sizeVector);

            Vector radius = new Vector(size.Width / 2, size.Height / 2);

            radius = data.TransformMatrix.Transform(radius);

            Point corner = data.Center - radius;

            return(new Rect(corner, sizeVector));
        }
 public static void UpdateScatterMatrix(FrameworkElement element, Size size, DisplayMatrix matrix)
 {
     UpdateScatterMatrix(element, size, matrix.Center, matrix.Orientation, matrix.Scale);
 }