diff --git a/ImageSharp.v2.ncrunchsolution b/ImageSharp.v2.ncrunchsolution new file mode 100644 index 0000000000..b98737f1c0 --- /dev/null +++ b/ImageSharp.v2.ncrunchsolution @@ -0,0 +1,14 @@ + + 1 + false + false + true + UseDynamicAnalysis + UseStaticAnalysis + UseStaticAnalysis + UseStaticAnalysis + UseDynamicAnalysis + + + + \ No newline at end of file diff --git a/src/ImageSharp/Drawing/Draw.cs b/src/ImageSharp/Drawing/Draw.cs index 8410b60ed3..aa2b91de60 100644 --- a/src/ImageSharp/Drawing/Draw.cs +++ b/src/ImageSharp/Drawing/Draw.cs @@ -5,6 +5,7 @@ namespace ImageSharp { + using System.Numerics; using Drawing; using Drawing.Brushes; using Drawing.Paths; @@ -78,7 +79,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The Image - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, PointF[] points) + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { @@ -95,7 +96,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The Image - public static Image DrawPolygon(this Image source, TColor color, float thickness, PointF[] points) + public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { @@ -111,57 +112,7 @@ namespace ImageSharp /// The pen. /// The points. /// The Image - public static Image DrawPolygon(this Image source, IPen pen, PointF[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points))); - } - - /// - /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The brush. - /// The thickness. - /// The points. - /// The Image - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Point[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return source.DrawPolygon(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); - } - - /// - /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The color. - /// The thickness. - /// The points. - /// The Image - public static Image DrawPolygon(this Image source, TColor color, float thickness, Point[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return source.DrawPolygon(new SolidBrush(color), thickness, points); - } - - /// - /// Draws the provided Points as a closed Linear Polygon with the provided Pen. - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The pen. - /// The points. - /// The Image - public static Image DrawPolygon(this Image source, IPen pen, Point[] points) + public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { @@ -228,7 +179,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The Image - public static Image DrawLines(this Image source, IBrush brush, float thickness, PointF[] points) + public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { @@ -245,7 +196,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The Image - public static Image DrawLines(this Image source, TColor color, float thickness, PointF[] points) + public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { @@ -261,112 +212,13 @@ namespace ImageSharp /// The pen. /// The points. /// The Image - public static Image DrawLines(this Image source, IPen pen, PointF[] points) + public static Image DrawLines(this Image source, IPen pen, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { return source.DrawPath(pen, new Path(new LinearLineSegment(points))); } - - /// - /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The brush. - /// The thickness. - /// The points. - /// The Image - public static Image DrawLines(this Image source, IBrush brush, float thickness, Point[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return source.DrawPath(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); - } - - /// - /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The color. - /// The thickness. - /// The points. - /// The Image - public static Image DrawLines(this Image source, TColor color, float thickness, Point[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return source.DrawLines(new SolidBrush(color), thickness, points); - } - - /// - /// Draws the provided Points as an open Linear path with the supplied pen - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The pen. - /// The points. - /// The Image - public static Image DrawLines(this Image source, IPen pen, Point[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return source.DrawPath(pen, new Path(new LinearLineSegment(points))); - } - - /// - /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The brush. - /// The thickness. - /// The points. - /// The Image - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, PointF[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return source.DrawPath(new Pen(brush, thickness), new Path(new BezierLineSegment(points))); - } - - /// - /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The color. - /// The thickness. - /// The points. - /// The Image - public static Image DrawBeziers(this Image source, TColor color, float thickness, PointF[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return source.DrawBeziers(new SolidBrush(color), thickness, points); - } - - /// - /// Draws the provided Points as an open Bezier path with the supplied pen - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The pen. - /// The points. - /// The Image - public static Image DrawBeziers(this Image source, IPen pen, PointF[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - return source.DrawPath(pen, new Path(new BezierLineSegment(points))); - } + /// /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush @@ -378,7 +230,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The Image - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Point[] points) + public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { @@ -395,7 +247,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The Image - public static Image DrawBeziers(this Image source, TColor color, float thickness, Point[] points) + public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { @@ -411,7 +263,7 @@ namespace ImageSharp /// The pen. /// The points. /// The Image - public static Image DrawBeziers(this Image source, IPen pen, Point[] points) + public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { diff --git a/src/ImageSharp/Drawing/Fill.cs b/src/ImageSharp/Drawing/Fill.cs index e8fc7f2e4b..02c9a7a3f8 100644 --- a/src/ImageSharp/Drawing/Fill.cs +++ b/src/ImageSharp/Drawing/Fill.cs @@ -5,6 +5,7 @@ namespace ImageSharp { + using System.Numerics; using Drawing; using Drawing.Brushes; using Drawing.Paths; @@ -88,7 +89,7 @@ namespace ImageSharp /// The brush. /// The points. /// The Image - public static Image FillPolygon(this Image source, IBrush brush, PointF[] points) + public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { @@ -105,46 +106,12 @@ namespace ImageSharp /// The color. /// The points. /// The Image - public static Image FillPolygon(this Image source, TColor color, PointF[] points) + public static Image FillPolygon(this Image source, TColor color, Vector2[] points) where TColor : struct, IPackedPixel where TPacked : struct { // using Polygon directly instead of LinearPolygon as its will have less indirection return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); } - - /// - /// Flood fills the image in the shape of a Linear polygon described by the points - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The brush. - /// The points. - /// The Image - public static Image FillPolygon(this Image source, IBrush brush, Point[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - // using Polygon directly instead of LinearPolygon as its will have less indirection - return source.Fill(brush, new Polygon(new LinearLineSegment(points))); - } - - /// - /// Flood fills the image in the shape of a Linear polygon described by the points - /// - /// The type of the color. - /// The type of the packed. - /// The source. - /// The color. - /// The points. - /// The Image - public static Image FillPolygon(this Image source, TColor color, Point[] points) - where TColor : struct, IPackedPixel - where TPacked : struct - { - // using Polygon directly instead of LinearPolygon as its will have less indirection - return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); - } } } diff --git a/src/ImageSharp/Drawing/Paths/BezierLineSegment.cs b/src/ImageSharp/Drawing/Paths/BezierLineSegment.cs index 8452efd5ca..edd6bbeea5 100644 --- a/src/ImageSharp/Drawing/Paths/BezierLineSegment.cs +++ b/src/ImageSharp/Drawing/Paths/BezierLineSegment.cs @@ -23,38 +23,11 @@ namespace ImageSharp.Drawing.Paths private Vector2[] linePoints; - /// - /// Initializes a new instance of the class. - /// - /// The points. - public BezierLineSegment(IEnumerable points) - : this(points?.Select(x => x.ToVector2()).ToArray()) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The points. - public BezierLineSegment(IEnumerable points) - : this(points?.Select(x => x.ToVector2()).ToArray()) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The points. - public BezierLineSegment(params PointF[] points) - : this(points?.Select(x => x.ToVector2()).ToArray()) - { - } - /// /// Initializes a new instance of the class. /// /// The points. - internal BezierLineSegment(Vector2[] points) + public BezierLineSegment(params Vector2[] points) { Guard.NotNull(points, nameof(points)); Guard.MustBeGreaterThanOrEqualTo(points.Length, 4, nameof(points)); diff --git a/src/ImageSharp/Drawing/Paths/LinearLineSegment.cs b/src/ImageSharp/Drawing/Paths/LinearLineSegment.cs index 59e344d282..3275c7883a 100644 --- a/src/ImageSharp/Drawing/Paths/LinearLineSegment.cs +++ b/src/ImageSharp/Drawing/Paths/LinearLineSegment.cs @@ -20,39 +20,12 @@ namespace ImageSharp.Drawing.Paths { private Vector2[] points; - /// - /// Initializes a new instance of the class. - /// - /// The points. - public LinearLineSegment(IEnumerable points) - : this(points?.Select(x => x.ToVector2()).ToArray()) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The points. - public LinearLineSegment(IEnumerable points) - : this(points?.Select(x => x.ToVector2()).ToArray()) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The points. - public LinearLineSegment(params PointF[] points) - : this(points?.Select(x => x.ToVector2()).ToArray()) - { - } - /// /// Initializes a new instance of the class. /// /// The start. /// The end. - internal LinearLineSegment(Vector2 start, Vector2 end) + public LinearLineSegment(Vector2 start, Vector2 end) : this(new[] { start, end }) { } @@ -61,7 +34,7 @@ namespace ImageSharp.Drawing.Paths /// Initializes a new instance of the class. /// /// The points. - internal LinearLineSegment(Vector2[] points) + public LinearLineSegment(params Vector2[] points) { Guard.NotNull(points, nameof(points)); Guard.MustBeGreaterThanOrEqualTo(points.Count(), 2, nameof(points)); diff --git a/src/ImageSharp/Drawing/Shapes/BezierPolygon.cs b/src/ImageSharp/Drawing/Shapes/BezierPolygon.cs index 19b46f1566..2e77ff77b8 100644 --- a/src/ImageSharp/Drawing/Shapes/BezierPolygon.cs +++ b/src/ImageSharp/Drawing/Shapes/BezierPolygon.cs @@ -7,7 +7,7 @@ namespace ImageSharp.Drawing.Shapes { using System.Collections; using System.Collections.Generic; - + using System.Numerics; using Paths; /// @@ -21,16 +21,7 @@ namespace ImageSharp.Drawing.Shapes /// Initializes a new instance of the class. /// /// The points. - public BezierPolygon(params Point[] points) - { - this.innerPolygon = new Polygon(new BezierLineSegment(points)); - } - - /// - /// Initializes a new instance of the class. - /// - /// The points. - public BezierPolygon(params PointF[] points) + public BezierPolygon(params Vector2[] points) { this.innerPolygon = new Polygon(new BezierLineSegment(points)); } diff --git a/src/ImageSharp/Drawing/Shapes/LinearPolygon.cs b/src/ImageSharp/Drawing/Shapes/LinearPolygon.cs index 02522d892d..fcd0b65453 100644 --- a/src/ImageSharp/Drawing/Shapes/LinearPolygon.cs +++ b/src/ImageSharp/Drawing/Shapes/LinearPolygon.cs @@ -7,7 +7,7 @@ namespace ImageSharp.Drawing.Shapes { using System.Collections; using System.Collections.Generic; - + using System.Numerics; using Paths; /// @@ -21,20 +21,11 @@ namespace ImageSharp.Drawing.Shapes /// Initializes a new instance of the class. /// /// The points. - public LinearPolygon(params Point[] points) - { - this.innerPolygon = new Polygon(new LinearLineSegment(points)); - } - - /// - /// Initializes a new instance of the class. - /// - /// The points. - public LinearPolygon(params PointF[] points) + public LinearPolygon(params Vector2[] points) { this.innerPolygon = new Polygon(new LinearLineSegment(points)); } - + /// /// Gets the bounding box of this shape. /// diff --git a/src/ImageSharp/Numerics/PointF.cs b/src/ImageSharp/Numerics/PointF.cs deleted file mode 100644 index 8f6eaf6b82..0000000000 --- a/src/ImageSharp/Numerics/PointF.cs +++ /dev/null @@ -1,287 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - using System.ComponentModel; - using System.Numerics; - using System.Runtime.CompilerServices; - - /// - /// Represents an ordered pair of floating point x- and y-coordinates that defines a point in - /// a two-dimensional plane. - /// - /// - /// This struct is fully mutable. This is done (against the guidelines) for the sake of performance, - /// as it avoids the need to create new values for modification operations. - /// - public struct PointF : IEquatable - { - /// - /// Represents a that has X and Y values set to zero. - /// - public static readonly PointF Empty = default(PointF); - - private Vector2 backingVector; - - /// - /// Initializes a new instance of the struct. - /// - /// The horizontal position of the point. - /// The vertical position of the point. - public PointF(float x, float y) - : this(new Vector2(x, y)) - { - } - - /// - /// Initializes a new instance of the struct. - /// - /// - /// The vector representing the width and height. - /// - public PointF(Vector2 vector) - { - this.backingVector = vector; - } - - /// - /// Gets or sets the x-coordinate of this . - /// - public float X - { - get { return this.backingVector.X; } - set { this.backingVector.X = value; } - } - - /// - /// Gets or sets the y-coordinate of this . - /// - public float Y - { - get { return this.backingVector.Y; } - set { this.backingVector.Y = value; } - } - - /// - /// Gets a value indicating whether this is empty. - /// - [EditorBrowsable(EditorBrowsableState.Never)] - public bool IsEmpty => this.Equals(Empty); - - /// - /// Performs an implicit conversion from to . - /// - /// The d. - /// - /// The result of the conversion. - /// - public static implicit operator PointF(Point d) - { - return new PointF(d.ToVector2()); - } - - /// - /// Computes the sum of adding two points. - /// - /// The point on the left hand of the operand. - /// The point on the right hand of the operand. - /// - /// The - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static PointF operator +(PointF left, PointF right) - { - return new PointF(left.backingVector + right.backingVector); - } - - /// - /// Computes the difference left by subtracting one point from another. - /// - /// The point on the left hand of the operand. - /// The point on the right hand of the operand. - /// - /// The - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static PointF operator -(PointF left, PointF right) - { - return new PointF(left.backingVector - right.backingVector); - } - - /// - /// Compares two objects for equality. - /// - /// - /// The on the left side of the operand. - /// - /// - /// The on the right side of the operand. - /// - /// - /// True if the current left is equal to the parameter; otherwise, false. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(PointF left, PointF right) - { - return left.Equals(right); - } - - /// - /// Compares two objects for inequality. - /// - /// - /// The on the left side of the operand. - /// - /// - /// The on the right side of the operand. - /// - /// - /// True if the current left is unequal to the parameter; otherwise, false. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(PointF left, PointF right) - { - return !left.Equals(right); - } - - /// - /// Creates a rotation matrix for the given point and angle. - /// - /// The origin point to rotate around - /// Rotation in degrees - /// The rotation - public static Matrix3x2 CreateRotation(PointF origin, float degrees) - { - float radians = ImageMaths.DegreesToRadians(degrees); - return Matrix3x2.CreateRotation(radians, new Vector2(origin.X, origin.Y)); - } - - /// - /// Rotates a point around a given a rotation matrix. - /// - /// The point to rotate - /// Rotation matrix used - /// The rotated - public static PointF Rotate(PointF point, Matrix3x2 rotation) - { - return new PointF(Vector2.Transform(new Vector2(point.X, point.Y), rotation)); - } - - /// - /// Rotates a point around a given origin by the specified angle in degrees. - /// - /// The point to rotate - /// The center point to rotate around. - /// The angle in degrees. - /// The rotated - public static PointF Rotate(PointF point, PointF origin, float degrees) - { - return new PointF(Vector2.Transform(new Vector2(point.X, point.Y), CreateRotation(origin, degrees))); - } - - /// - /// Creates a skew matrix for the given point and angle. - /// - /// The origin point to rotate around - /// The x-angle in degrees. - /// The y-angle in degrees. - /// The rotation - public static Matrix3x2 CreateSkew(PointF origin, float degreesX, float degreesY) - { - float radiansX = ImageMaths.DegreesToRadians(degreesX); - float radiansY = ImageMaths.DegreesToRadians(degreesY); - return Matrix3x2.CreateSkew(radiansX, radiansY, origin.backingVector); - } - - /// - /// Skews a point using a given a skew matrix. - /// - /// The point to rotate - /// Rotation matrix used - /// The rotated - public static PointF Skew(PointF point, Matrix3x2 skew) - { - return new PointF(Vector2.Transform(point.backingVector, skew)); - } - - /// - /// Skews a point around a given origin by the specified angles in degrees. - /// - /// The point to skew. - /// The center point to rotate around. - /// The x-angle in degrees. - /// The y-angle in degrees. - /// The skewed - public static PointF Skew(PointF point, PointF origin, float degreesX, float degreesY) - { - return new PointF(Vector2.Transform(point.backingVector, CreateSkew(origin, degreesX, degreesY))); - } - - /// - /// Gets a representation for this . - /// - /// A representation for this object. - public Vector2 ToVector2() - { - // should this be a return of the mutable vector2 backing vector instead of a copy? - return new Vector2(this.X, this.Y); - } - - /// - /// Translates this by the specified amount. - /// - /// The amount to offset the x-coordinate. - /// The amount to offset the y-coordinate. - public void Offset(float dx, float dy) - { - this.backingVector += new Vector2(dx, dy); - } - - /// - /// Translates this by the specified amount. - /// - /// The used offset this . - public void Offset(PointF p) - { - this.backingVector += p.backingVector; - } - - /// - public override int GetHashCode() - { - return this.backingVector.GetHashCode(); - } - - /// - public override string ToString() - { - if (this.IsEmpty) - { - return "Point [ Empty ]"; - } - - return $"Point [ X={this.X}, Y={this.Y} ]"; - } - - /// - public override bool Equals(object obj) - { - if (obj is PointF) - { - return this.Equals((PointF)obj); - } - - return false; - } - - /// - public bool Equals(PointF other) - { - return this.backingVector == other.backingVector; - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs index b0f34dd8ca..559cc4c110 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs @@ -11,10 +11,10 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; - using CorePointF= ImageSharp.PointF; - using CoreColor= ImageSharp.Color; + using CoreColor = ImageSharp.Color; using System.IO; - + using System.Numerics; + public class DrawBeziers { [Benchmark(Baseline = true, Description = "System.Drawing Draw Beziers")] @@ -49,10 +49,10 @@ namespace ImageSharp.Benchmarks CoreImage image = new CoreImage(800, 800); image.DrawBeziers(CoreColor.HotPink, 10, new[] { - new CorePointF(10, 500), - new CorePointF(30, 10), - new CorePointF(240, 30), - new CorePointF(300, 500) + new Vector2(10, 500), + new Vector2(30, 10), + new Vector2(240, 30), + new Vector2(300, 500) }); using (MemoryStream ms = new MemoryStream()) diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs index 8385561b5a..429da047d1 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs @@ -11,10 +11,10 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; - using CorePointF= ImageSharp.PointF; - using CoreColor= ImageSharp.Color; + using CoreColor = ImageSharp.Color; using System.IO; - + using System.Numerics; + public class DrawLines { [Benchmark(Baseline = true, Description = "System.Drawing Draw Lines")] @@ -48,9 +48,9 @@ namespace ImageSharp.Benchmarks CoreImage image = new CoreImage(800, 800); image.DrawLines(CoreColor.HotPink, 10, new[] { - new CorePointF(10, 10), - new CorePointF(550, 50), - new CorePointF(200, 400) + new Vector2(10, 10), + new Vector2(550, 50), + new Vector2(200, 400) }); using (MemoryStream ms = new MemoryStream()) diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index 3164632944..405e8d0a71 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -11,10 +11,10 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; using CorePoint = ImageSharp.Point; - using CorePointF= ImageSharp.PointF; - using CoreColor= ImageSharp.Color; + using CoreColor = ImageSharp.Color; using System.IO; - + using System.Numerics; + public class DrawPolygon { [Benchmark(Baseline = true, Description = "System.Drawing Draw Polygon")] @@ -48,9 +48,9 @@ namespace ImageSharp.Benchmarks CoreImage image = new CoreImage(800, 800); image.DrawPolygon(CoreColor.HotPink, 10, new[] { - new CorePointF(10, 10), - new CorePointF(550, 50), - new CorePointF(200, 400) + new Vector2(10, 10), + new Vector2(550, 50), + new Vector2(200, 400) }); using (MemoryStream ms = new MemoryStream()) diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index a2f640bc5a..5e07d12422 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -10,9 +10,9 @@ namespace ImageSharp.Benchmarks using BenchmarkDotNet.Attributes; using CoreImage = ImageSharp.Image; - using CorePoint = ImageSharp.Point; using CoreColor = ImageSharp.Color; using System.IO; + using System.Numerics; public class FillPolygon { @@ -44,9 +44,9 @@ namespace ImageSharp.Benchmarks CoreImage image = new CoreImage(800, 800); image.FillPolygon(CoreColor.HotPink, new[] { - new CorePoint(10, 10), - new CorePoint(550, 50), - new CorePoint(200, 400) + new Vector2(10, 10), + new Vector2(550, 50), + new Vector2(200, 400) } ); diff --git a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs index 053ccdad41..c219f91aa0 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -28,10 +28,10 @@ using (FileStream output = File.OpenWrite($"{path}/Simple.png")) image .BackgroundColor(Color.Blue) .DrawBeziers(Color.HotPink, 5, new[] { - new PointF(10, 400), - new PointF(30, 10), - new PointF(240, 30), - new PointF(300, 400) + new Vector2(10, 400), + new Vector2(30, 10), + new Vector2(240, 30), + new Vector2(300, 400) }) .Save(output); } @@ -70,10 +70,10 @@ using (FileStream output = File.OpenWrite($"{path}/Simple.png")) image .BackgroundColor(Color.Blue) .DrawBeziers(color, 10, new[] { - new PointF(10, 400), - new PointF(30, 10), - new PointF(240, 30), - new PointF(300, 400) + new Vector2(10, 400), + new Vector2(30, 10), + new Vector2(240, 30), + new Vector2(300, 400) }) .Save(output); } diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index a3a7ce4aec..3404694967 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -23,27 +23,26 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPath() { string path = CreateOutputDirectory("Drawing", "Path"); -var image = new Image(500, 500); + var image = new Image(500, 500); -var linerSegemnt = new LinearLineSegment( - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) - ); -var bazierSegment = new BezierLineSegment(new Point(50, 300), - new Point(500, 500), - new Point(60, 10), - new Point(10, 400)); + var linerSegemnt = new LinearLineSegment( + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300)); + var bazierSegment = new BezierLineSegment(new Vector2(50, 300), + new Vector2(500, 500), + new Vector2(60, 10), + new Vector2(10, 400)); -var p = new CorePath(linerSegemnt, bazierSegment); + var p = new CorePath(linerSegemnt, bazierSegment); -using (FileStream output = File.OpenWrite($"{path}/Simple.png")) -{ - image - .BackgroundColor(Color.Blue) - .DrawPath(Color.HotPink, 5, p) - .Save(output); -} + using (FileStream output = File.OpenWrite($"{path}/Simple.png")) + { + image + .BackgroundColor(Color.Blue) + .DrawPath(Color.HotPink, 5, p) + .Save(output); + } using (var sourcePixels = image.Lock()) { @@ -66,19 +65,19 @@ using (FileStream output = File.OpenWrite($"{path}/Simple.png")) var linerSegemnt = new LinearLineSegment( - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) ); - var bazierSegment = new BezierLineSegment(new Point(50, 300), - new Point(500, 500), - new Point(60, 10), - new Point(10, 400)); + var bazierSegment = new BezierLineSegment(new Vector2(50, 300), + new Vector2(500, 500), + new Vector2(60, 10), + new Vector2(10, 400)); var p = new CorePath(linerSegemnt, bazierSegment); var image = new Image(500, 500); - + using (FileStream output = File.OpenWrite($"{path}/Opacity.png")) { @@ -89,7 +88,7 @@ using (FileStream output = File.OpenWrite($"{path}/Simple.png")) } //shift background color towards forground color by the opacity amount - var mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f/255f)); + var mergedColor = new Color(Vector4.Lerp(Color.Blue.ToVector4(), Color.HotPink.ToVector4(), 150f / 255f)); using (var sourcePixels = image.Lock()) { @@ -100,6 +99,6 @@ using (FileStream output = File.OpenWrite($"{path}/Simple.png")) Assert.Equal(Color.Blue, sourcePixels[50, 50]); } } - + } -} +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index aa7672d13f..1f6708bf81 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -22,14 +22,14 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "LineComplexPolygon"); var simplePath = new LinearPolygon( - new Point(10, 10), - new Point(200, 150), - new Point(50, 300)); + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300)); var hole1 = new LinearPolygon( - new Point(37, 85), - new Point(93, 85), - new Point(65, 137)); + new Vector2(37, 85), + new Vector2(93, 85), + new Vector2(65, 137)); var image = new Image(500, 500); @@ -72,14 +72,14 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "LineComplexPolygon"); var simplePath = new LinearPolygon( - new Point(10, 10), - new Point(200, 150), - new Point(50, 300)); + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300)); var hole1 = new LinearPolygon( - new Point(37, 85), - new Point(130, 40), - new Point(65, 137)); + new Vector2(37, 85), + new Vector2(130, 40), + new Vector2(65, 137)); var image = new Image(500, 500); @@ -117,14 +117,14 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "LineComplexPolygon"); var simplePath = new LinearPolygon( - new Point(10, 10), - new Point(200, 150), - new Point(50, 300)); + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300)); var hole1 = new LinearPolygon( - new Point(37, 85), - new Point(93, 85), - new Point(65, 137)); + new Vector2(37, 85), + new Vector2(93, 85), + new Vector2(65, 137)); var image = new Image(500, 500); @@ -143,14 +143,14 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "LineComplexPolygon"); var simplePath = new LinearPolygon( - new Point(10, 10), - new Point(200, 150), - new Point(50, 300)); + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300)); var hole1 = new LinearPolygon( - new Point(37, 85), - new Point(93, 85), - new Point(65, 137)); + new Vector2(37, 85), + new Vector2(93, 85), + new Vector2(65, 137)); var color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); var image = new Image(500, 500); diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index 9baf443a13..7c1a826896 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -29,9 +29,9 @@ namespace ImageSharp.Tests.Drawing image .BackgroundColor(Color.Blue) .DrawLines(Color.HotPink, 5, new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) }) .Save(output); } @@ -59,9 +59,9 @@ namespace ImageSharp.Tests.Drawing image .BackgroundColor(Color.Blue) .DrawLines(Pens.Dash(Color.HotPink, 5), new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) }) .Save(output); } @@ -79,9 +79,9 @@ namespace ImageSharp.Tests.Drawing image .BackgroundColor(Color.Blue) .DrawLines(Pens.Dot(Color.HotPink, 5), new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) }) .Save(output); } @@ -98,9 +98,9 @@ namespace ImageSharp.Tests.Drawing image .BackgroundColor(Color.Blue) .DrawLines(Pens.DashDot(Color.HotPink, 5), new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) }) .Save(output); } @@ -118,9 +118,9 @@ namespace ImageSharp.Tests.Drawing image .BackgroundColor(Color.Blue) .DrawLines(Pens.DashDotDot(Color.HotPink, 5), new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) }) .Save(output); } @@ -141,9 +141,9 @@ namespace ImageSharp.Tests.Drawing image .BackgroundColor(Color.Blue) .DrawLines(color, 10, new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) }) .Save(output); } @@ -173,10 +173,10 @@ namespace ImageSharp.Tests.Drawing image .BackgroundColor(Color.Blue) .DrawLines(Color.HotPink, 10, new[] { - new Point(10, 10), - new Point(200, 10), - new Point(200, 150), - new Point(10, 150) + new Vector2(10, 10), + new Vector2(200, 10), + new Vector2(200, 150), + new Vector2(10, 150) }) .Save(output); } diff --git a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index 383c46f4d1..fbda689fac 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -19,25 +19,20 @@ namespace ImageSharp.Tests.Drawing public void ImageShouldBeOverlayedByPolygonOutline() { string path = CreateOutputDirectory("Drawing", "Polygons"); - var simplePath = new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) - }; -var image = new Image(500, 500); + var image = new Image(500, 500); -using (FileStream output = File.OpenWrite($"{path}/Simple.png")) -{ - image - .BackgroundColor(Color.Blue) - .DrawPolygon(Color.HotPink, 5, new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) - }) - .Save(output); -} + using (FileStream output = File.OpenWrite($"{path}/Simple.png")) + { + image + .BackgroundColor(Color.Blue) + .DrawPolygon(Color.HotPink, 5, new[] { + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) + }) + .Save(output); + } using (var sourcePixels = image.Lock()) { @@ -57,9 +52,9 @@ using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { string path = CreateOutputDirectory("Drawing", "Polygons"); var simplePath = new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) }; var color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); @@ -93,27 +88,21 @@ using (FileStream output = File.OpenWrite($"{path}/Simple.png")) public void ImageShouldBeOverlayedByRectangleOutline() { string path = CreateOutputDirectory("Drawing", "Polygons"); - var simplePath = new[] { - new Point(10, 10), - new Point(200, 10), - new Point(200, 150), - new Point(10, 150) - }; -var image = new Image(500, 500); + var image = new Image(500, 500); -using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) -{ - image - .BackgroundColor(Color.Blue) - .DrawPolygon(Color.HotPink, 10, new[] { - new Point(10, 10), - new Point(200, 10), - new Point(200, 150), - new Point(10, 150) - }) - .Save(output); -} + using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) + { + image + .BackgroundColor(Color.Blue) + .DrawPolygon(Color.HotPink, 10, new[] { + new Vector2(10, 10), + new Vector2(200, 10), + new Vector2(200, 150), + new Vector2(10, 150) + }) + .Save(output); + } using (var sourcePixels = image.Lock()) { @@ -129,4 +118,4 @@ using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) } } } -} +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index c6645151b9..f6bcf49065 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -21,10 +21,10 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "FilledBezier"); var simplePath = new[] { - new PointF(10, 400), - new PointF(30, 10), - new PointF(240, 30), - new PointF(300, 400) + new Vector2(10, 400), + new Vector2(30, 10), + new Vector2(240, 30), + new Vector2(300, 400) }; var image = new Image(500, 500); @@ -59,10 +59,10 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "FilledBezier"); var simplePath = new[] { - new PointF(10, 400), - new PointF(30, 10), - new PointF(240, 30), - new PointF(300, 400) + new Vector2(10, 400), + new Vector2(30, 10), + new Vector2(240, 30), + new Vector2(300, 400) }; var color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); diff --git a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index b765279325..dd4cbfd2b9 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -21,14 +21,14 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "ComplexPolygon"); var simplePath = new LinearPolygon( - new Point(10, 10), - new Point(200, 150), - new Point(50, 300)); + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300)); var hole1 = new LinearPolygon( - new Point(37, 85), - new Point(93, 85), - new Point(65, 137)); + new Vector2(37, 85), + new Vector2(93, 85), + new Vector2(65, 137)); var image = new Image(500, 500); @@ -61,14 +61,14 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "ComplexPolygon"); var simplePath = new LinearPolygon( - new Point(10, 10), - new Point(200, 150), - new Point(50, 300)); + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300)); var hole1 = new LinearPolygon( - new Point(37, 85), - new Point(130, 40), - new Point(65, 137)); + new Vector2(37, 85), + new Vector2(130, 40), + new Vector2(65, 137)); var image = new Image(500, 500); @@ -100,14 +100,14 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "ComplexPolygon"); var simplePath = new LinearPolygon( - new Point(10, 10), - new Point(200, 150), - new Point(50, 300)); + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300)); var hole1 = new LinearPolygon( - new Point(37, 85), - new Point(93, 85), - new Point(65, 137)); + new Vector2(37, 85), + new Vector2(93, 85), + new Vector2(65, 137)); var color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); var image = new Image(500, 500); diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index 484bcb83b8..4f0f4ac9c0 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -20,9 +20,9 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "FilledPolygons"); var simplePath = new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) }; var image = new Image(500, 500); @@ -51,9 +51,9 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "FilledPolygons"); var simplePath = new[] { - new Point(10, 10), - new Point(200, 150), - new Point(50, 300) + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) }; var color = new Color(Color.HotPink.R, Color.HotPink.G, Color.HotPink.B, 150); @@ -87,10 +87,10 @@ namespace ImageSharp.Tests.Drawing { string path = CreateOutputDirectory("Drawing", "FilledPolygons"); var simplePath = new[] { - new Point(10, 10), - new Point(200, 10), - new Point(200, 150), - new Point(10, 150) + new Vector2(10, 10), + new Vector2(200, 10), + new Vector2(200, 150), + new Vector2(10, 150) }; var image = new Image(500, 500);