public void AppendSkewDegrees_WithSkewCenter(
            int width,
            int height,
            float degreesX,
            float degreesY,
            float cx,
            float cy,
            float x,
            float y)
        {
            var      size    = new Size(width, height);
            TBuilder builder = this.CreateBuilder();

            var centerPoint = new Vector2(cx, cy);

            this.AppendSkewDegrees(builder, degreesX, degreesY, centerPoint);

            var matrix = Matrix3x2.CreateSkew(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY), centerPoint);

            var     position = new Vector2(x, y);
            var     expected = Vector2.Transform(position, matrix);
            Vector2 actual   = this.Execute(builder, new Rectangle(Point.Empty, size), position);

            Assert.Equal(actual, expected, Comparer);
        }
Example #2
0
        /// <summary>
        /// Create a hue filter matrix using the given angle in degrees.
        /// </summary>
        /// <param name="degrees">The angle of rotation in degrees.</param>
        /// <returns>The <see cref="ColorMatrix"/></returns>
        public static ColorMatrix CreateHueFilter(float degrees)
        {
            // Wrap the angle round at 360.
            degrees %= 360;

            // Make sure it's not negative.
            while (degrees < 0)
            {
                degrees += 360;
            }

            float radian    = GeometryUtilities.DegreeToRadian(degrees);
            float cosRadian = MathF.Cos(radian);
            float sinRadian = MathF.Sin(radian);

            // The matrix is set up to preserve the luminance of the image.
            // See http://graficaobscura.com/matrix/index.html
            // Number are taken from https://msdn.microsoft.com/en-us/library/jj192162(v=vs.85).aspx
            return(new ColorMatrix
            {
                M11 = .213F + (cosRadian * .787F) - (sinRadian * .213F),
                M21 = .715F - (cosRadian * .715F) - (sinRadian * .715F),
                M31 = .072F - (cosRadian * .072F) + (sinRadian * .928F),

                M12 = .213F - (cosRadian * .213F) + (sinRadian * .143F),
                M22 = .715F + (cosRadian * .285F) + (sinRadian * .140F),
                M32 = .072F - (cosRadian * .072F) - (sinRadian * .283F),

                M13 = .213F - (cosRadian * .213F) - (sinRadian * .787F),
                M23 = .715F - (cosRadian * .715F) + (sinRadian * .715F),
                M33 = .072F + (cosRadian * .928F) + (sinRadian * .072F),
                M44 = 1F
            });
        }
        public void DrawPolygon_Transformed <TPixel>(TestImageProvider <TPixel> provider)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            PointF[] simplePath =
            {
                new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300)
            };

            provider.RunValidatingProcessorTest(
                c => c.SetDrawingTransform(Matrix3x2.CreateSkew(GeometryUtilities.DegreeToRadian(-15), 0, new Vector2(200, 200)))
                .DrawPolygon(Color.White, 2.5f, simplePath));
        }
Example #4
0
        public void Fill_RegularPolygon <TPixel>(TestImageProvider <TPixel> provider, int vertices, float radius, float angleDeg)
            where TPixel : struct, IPixel <TPixel>
        {
            float angle   = GeometryUtilities.DegreeToRadian(angleDeg);
            var   polygon = new RegularPolygon(100, 100, vertices, radius, angle);
            var   color   = Color.Yellow;

            FormattableString testOutput = $"V({vertices})_R({radius})_Ang({angleDeg})";

            provider.RunValidatingProcessorTest(
                c => c.Fill(color, polygon),
                testOutput,
                appendSourceFileOrDescription: false,
                appendPixelTypeToFileName: false);
        }
 /// <summary>
 /// Appends a centered rotation matrix using the given rotation in degrees at the given origin.
 /// </summary>
 /// <param name="degrees">The amount of rotation, in radians.</param>
 /// <param name="origin">The rotation origin point.</param>
 /// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
 internal ProjectiveTransformBuilder AppendRotationDegrees(float degrees, Vector2 origin)
 => this.AppendRotationRadians(GeometryUtilities.DegreeToRadian(degrees), origin);
 /// <summary>
 /// Appends a centered rotation matrix using the given rotation in degrees.
 /// </summary>
 /// <param name="degrees">The amount of rotation, in degrees.</param>
 /// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
 public ProjectiveTransformBuilder AppendRotationDegrees(float degrees)
 => this.AppendRotationRadians(GeometryUtilities.DegreeToRadian(degrees));
 /// <summary>
 /// Appends a skew matrix using the given angles in degrees at the given origin.
 /// </summary>
 /// <param name="degreesX">The X angle, in degrees.</param>
 /// <param name="degreesY">The Y angle, in degrees.</param>
 /// <param name="origin">The skew origin point.</param>
 /// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
 public ProjectiveTransformBuilder AppendSkewDegrees(float degreesX, float degreesY, Vector2 origin)
 => this.AppendSkewRadians(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY), origin);
 /// <summary>
 /// Appends a centered skew matrix from the give angles in degrees.
 /// </summary>
 /// <param name="degreesX">The X angle, in degrees.</param>
 /// <param name="degreesY">The Y angle, in degrees.</param>
 /// <returns>The <see cref="ProjectiveTransformBuilder"/>.</returns>
 internal ProjectiveTransformBuilder AppendSkewDegrees(float degreesX, float degreesY)
 => this.AppendSkewRadians(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY));
Example #9
0
 /// <summary>
 /// Prepends a rotation matrix using the given rotation in degrees at the given origin.
 /// </summary>
 /// <param name="degrees">The amount of rotation, in degrees.</param>
 /// <param name="origin">The rotation origin point.</param>
 /// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
 public AffineTransformBuilder PrependRotationDegrees(float degrees, Vector2 origin)
 => this.PrependRotationRadians(GeometryUtilities.DegreeToRadian(degrees), origin);
Example #10
0
 /// <summary>
 /// Prepends a skew matrix using the given angles in degrees at the given origin.
 /// </summary>
 /// <param name="degreesX">The X angle, in degrees.</param>
 /// <param name="degreesY">The Y angle, in degrees.</param>
 /// <param name="origin">The skew origin point.</param>
 /// <returns>The <see cref="AffineTransformBuilder"/>.</returns>
 public AffineTransformBuilder PrependSkewDegrees(float degreesX, float degreesY, Vector2 origin)
 => this.PrependSkewRadians(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY), origin);
Example #11
0
 /// <summary>
 /// Creates a rotation matrix using the given rotation in degrees and a center point.
 /// </summary>
 /// <param name="degrees">The amount of rotation, in degrees.</param>
 /// <param name="centerPoint">The center point.</param>
 /// <returns>A rotation matrix.</returns>
 public static Matrix3x2 CreateRotationDegrees(float degrees, PointF centerPoint) => Matrix3x2.CreateRotation(GeometryUtilities.DegreeToRadian(degrees), centerPoint);
Example #12
0
 /// <summary>
 /// Creates a rotation matrix using the given rotation in degrees.
 /// </summary>
 /// <param name="degrees">The amount of rotation, in degrees.</param>
 /// <returns>A rotation matrix.</returns>
 public static Matrix3x2 CreateRotationDegrees(float degrees) => Matrix3x2.CreateRotation(GeometryUtilities.DegreeToRadian(degrees));
Example #13
0
 /// <summary>
 /// Creates a skew matrix from the given angles in degrees and a center point.
 /// </summary>
 /// <param name="degreesX">The X angle, in degrees.</param>
 /// <param name="degreesY">The Y angle, in degrees.</param>
 /// <param name="centerPoint">The center point.</param>
 /// <returns>A skew matrix.</returns>
 public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY, PointF centerPoint) => Matrix3x2.CreateSkew(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY), centerPoint);
Example #14
0
 /// <summary>
 /// Creates a skew matrix from the given angles in degrees.
 /// </summary>
 /// <param name="degreesX">The X angle, in degrees.</param>
 /// <param name="degreesY">The Y angle, in degrees.</param>
 /// <returns>A skew matrix.</returns>
 public static Matrix3x2 CreateSkewDegrees(float degreesX, float degreesY) => Matrix3x2.CreateSkew(GeometryUtilities.DegreeToRadian(degreesX), GeometryUtilities.DegreeToRadian(degreesY));
Example #15
0
 public void Convert_Degree_To_Radian()
 => Assert.Equal((float)(Math.PI / 2D), GeometryUtilities.DegreeToRadian(90F), new FloatRoundingComparer(6));
Example #16
0
 /// <summary>
 /// Creates a path rotated by the specified degrees around its center.
 /// </summary>
 /// <param name="shape">The path to rotate.</param>
 /// <param name="degree">The degree to rotate the path.</param>
 /// <returns>A <see cref="IPath"/> with a rotate transform applied.</returns>
 public static IPath RotateDegree(this IPath shape, float degree)
 => shape.Rotate(GeometryUtilities.DegreeToRadian(degree));