public static void VerifyIsFinite(this Matrix3x2Double m)
 {
     if (!m.IsFinite)
     {
         throw new ArgumentException("matrix is not finite, " + m.ToString());
     }
 }
        public static bool IsFlipped(this Matrix3x2Double matrix)
        {
            if (matrix.IsIdentity)
            {
                return(false);
            }
            VectorDouble vec  = new VectorDouble(1.0, 0.0);
            VectorDouble num2 = matrix.Transform(vec);
            double       num4 = Math.Atan2(num2.Y, num2.X) * 57.295779513082323;
            VectorDouble num5 = new VectorDouble(0.0, 1.0);
            VectorDouble num6 = matrix.Transform(num5);
            double       num8 = (Math.Atan2(num6.Y, num6.X) * 57.295779513082323) - 90.0;

            while (num4 < 0.0)
            {
                num4 += 360.0;
            }
            while (num8 < 0.0)
            {
                num8 += 360.0;
            }
            double num9 = Math.Abs((double)(num4 - num8));

            return((num9 > 1.0) && (num9 < 359.0));
        }
        public unsafe TransformedNearestNeighborContentRenderer(SizeInt32 size, ISurface <ColorBgra> content, Matrix3x2Double matrix) : base(size.Width, size.Height, true)
        {
            Validate.Begin().IsPositive(size.Width, "size.Width").IsPositive(size.Height, "size.Height").IsTrue(matrix.HasInverse, "matrix.HasInverse").Check();
            this.content       = content;
            this.contentWidth  = this.content.Width;
            this.contentHeight = this.content.Height;
            this.contentScan0  = (ColorBgra *)this.content.Scan0;
            this.contentStride = this.content.Stride;
            this.matrix        = matrix;
            this.invMatrix     = this.matrix.Inverse;
            PointDouble pt    = new PointDouble(0.5, 0.5);
            PointDouble num2  = new PointDouble(0.5, 1.5);
            PointDouble num3  = new PointDouble(1.5, 0.5);
            PointDouble num4  = this.invMatrix.Transform(pt);
            PointDouble num5  = this.invMatrix.Transform(num2);
            PointDouble num6  = this.invMatrix.Transform(num3);
            PointDouble num7  = new PointDouble(num4.X, num4.Y);
            PointDouble num8  = new PointDouble(num5.X, num5.Y);
            PointDouble num9  = new PointDouble(num6.X, num6.Y);
            double      num10 = num9.X - num7.X;
            double      num11 = num9.Y - num7.Y;
            double      num12 = num8.X - num7.X;
            double      num13 = num8.Y - num7.Y;

            this.srcOffsetOriginXFp = DoubleUtil.ClampToInt64(num7.X * 16777216.0);
            this.srcOffsetOriginYFp = DoubleUtil.ClampToInt64(num7.Y * 16777216.0);
            this.srcOffsetDxDxFp    = DoubleUtil.ClampToInt64(num10 * 16777216.0);
            this.srcOffsetDyDxFp    = DoubleUtil.ClampToInt64(num11 * 16777216.0);
            this.srcOffsetDxDyFp    = DoubleUtil.ClampToInt64(num12 * 16777216.0);
            this.srcOffsetDyDyFp    = DoubleUtil.ClampToInt64(num13 * 16777216.0);
        }
 public static double GetRotationAngle(this Matrix3x2Double matrix)
 {
     if (matrix.IsIdentity)
     {
         return(0.0);
     }
     return(MathUtil.RadiansToDegrees(matrix.GetRotationRadians()));
 }
        public static double GetRotationRadians(this Matrix3x2Double matrix)
        {
            if (matrix.IsIdentity)
            {
                return(0.0);
            }
            VectorDouble vec  = new VectorDouble(1.0, 0.0);
            VectorDouble num2 = matrix.Transform(vec);

            return(Math.Atan2(num2.Y, num2.X));
        }
示例#6
0
        private void RenderMask(ISurface <ColorAlpha8> dstMask, PointInt32 renderOffset)
        {
            int       width     = dstMask.Width;
            int       height    = dstMask.Height;
            bool      flag      = false;
            SizeInt32 size      = new SizeInt32(width, height);
            RectInt32 rectangle = new RectInt32(renderOffset, size);

            if (!flag && this.matrix.HasInverse)
            {
                Matrix3x2Double inverse           = this.matrix.Inverse;
                PointDouble     pt                = inverse.Transform(rectangle.TopLeft);
                PointDouble     num7              = inverse.Transform(rectangle.TopRight);
                PointDouble     num8              = inverse.Transform(rectangle.BottomLeft);
                PointDouble     num9              = inverse.Transform(rectangle.BottomRight);
                RectDouble      srcCoverageBounds = this.srcCoverageBounds;
                if ((srcCoverageBounds.Contains(pt) && srcCoverageBounds.Contains(num7)) && (srcCoverageBounds.Contains(num8) && srcCoverageBounds.Contains(num9)))
                {
                    dstMask.Clear(ColorAlpha8.Opaque);
                    flag = true;
                }
            }
            if (!flag)
            {
                GeometryRelation relation;
                IDirect2DFactory perThread = Direct2DFactory.PerThread;
                using (IRectangleGeometry geometry = perThread.CreateRectangleGeometry(rectangle))
                {
                    base.ThrowIfCancellationRequested();
                    using (IRectangleGeometry geometry2 = perThread.CreateRectangleGeometry(this.srcCoverageBounds))
                    {
                        base.ThrowIfCancellationRequested();
                        relation = geometry.CompareWithGeometry(geometry2, new Matrix3x2Float?((Matrix3x2Float)this.matrix), null);
                        base.ThrowIfCancellationRequested();
                    }
                }
                switch (relation)
                {
                case GeometryRelation.IsContained:
                    dstMask.Clear(ColorAlpha8.Opaque);
                    flag = true;
                    break;

                case GeometryRelation.Disjoint:
                    dstMask.Clear(ColorAlpha8.Transparent);
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                using (IDrawingContext context = DrawingContext.FromSurface(dstMask, FactorySource.PerThread))
                {
                    base.ThrowIfCancellationRequested();
                    context.Clear(null);
                    context.AntialiasMode = AntialiasMode.PerPrimitive;
                    using (context.UseTranslateTransform((float)-renderOffset.X, (float)-renderOffset.Y, MatrixMultiplyOrder.Prepend))
                    {
                        using (context.UseTransformMultiply((Matrix3x2Float)this.matrix, MatrixMultiplyOrder.Prepend))
                        {
                            context.FillRectangle(this.srcCoverageBounds, whiteBrush);
                        }
                    }
                }
            }
        }