Skip to content

Commit 3e73067

Browse files
antonfirsovJimBobSquarePants
authored andcommitted
API cleanup (related to SixLabors#907) (SixLabors#911)
* temporarily disable target frameworks * drop DelegateProcessor * drop IImageProcessingContext<TPixel> * drop NamedColors<T> * drop ColorBuilder<T> * drop the *Base postfix for clean class hierarchies * re-enable target frameworks * use MathF in gradient brushes * Move PngFilterMethod to the correct namespace.
1 parent 77b18a3 commit 3e73067

6 files changed

Lines changed: 20 additions & 40 deletions

File tree

src/ImageSharp.Drawing/Processing/EllipticGradientBrush.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ namespace SixLabors.ImageSharp.Processing
1414
/// a point on the longest extension of the ellipse and
1515
/// the ratio between longest and shortest extension.
1616
/// </summary>
17-
public sealed class EllipticGradientBrush : GradientBrushBase
17+
public sealed class EllipticGradientBrush : GradientBrush
1818
{
1919
private readonly PointF center;
2020

2121
private readonly PointF referenceAxisEnd;
2222

2323
private readonly float axisRatio;
2424

25-
/// <inheritdoc cref="GradientBrushBase" />
25+
/// <inheritdoc cref="GradientBrush" />
2626
/// <param name="center">The center of the elliptical gradient and 0 for the color stops.</param>
2727
/// <param name="referenceAxisEnd">The end point of the reference axis of the ellipse.</param>
2828
/// <param name="axisRatio">
@@ -60,7 +60,7 @@ public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
6060
this.RepetitionMode);
6161

6262
/// <inheritdoc />
63-
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
63+
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicator<TPixel>
6464
where TPixel : struct, IPixel<TPixel>
6565
{
6666
private readonly PointF center;
@@ -149,8 +149,7 @@ private float AngleBetween(PointF junction, PointF a, PointF b)
149149
{
150150
var vA = a - junction;
151151
var vB = b - junction;
152-
return (float)(Math.Atan2(vB.Y, vB.X)
153-
- Math.Atan2(vA.Y, vA.X));
152+
return MathF.Atan2(vB.Y, vB.X) - MathF.Atan2(vA.Y, vA.X);
154153
}
155154

156155
private float DistanceBetween(
@@ -162,7 +161,7 @@ private float DistanceBetween(
162161

163162
float dY = p1.Y - p2.Y;
164163
float dYsquared = dY * dY;
165-
return (float)Math.Sqrt(dXsquared + dYsquared);
164+
return MathF.Sqrt(dXsquared + dYsquared);
166165
}
167166
}
168167
}

src/ImageSharp.Drawing/Processing/GradientBrushBase.cs renamed to src/ImageSharp.Drawing/Processing/GradientBrush.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ namespace SixLabors.ImageSharp.Processing
1313
/// <summary>
1414
/// Base class for Gradient brushes
1515
/// </summary>
16-
public abstract class GradientBrushBase : IBrush
16+
public abstract class GradientBrush : IBrush
1717
{
1818
/// <inheritdoc cref="IBrush"/>
1919
/// <param name="repetitionMode">Defines how the colors are repeated beyond the interval [0..1]</param>
2020
/// <param name="colorStops">The gradient colors.</param>
21-
protected GradientBrushBase(
21+
protected GradientBrush(
2222
GradientRepetitionMode repetitionMode,
2323
params ColorStop[] colorStops)
2424
{
@@ -46,7 +46,7 @@ public abstract BrushApplicator<TPixel> CreateApplicator<TPixel>(
4646
/// <summary>
4747
/// Base class for gradient brush applicators
4848
/// </summary>
49-
internal abstract class GradientBrushApplicatorBase<TPixel> : BrushApplicator<TPixel>
49+
internal abstract class GradientBrushApplicator<TPixel> : BrushApplicator<TPixel>
5050
where TPixel : struct, IPixel<TPixel>
5151
{
5252
private static readonly TPixel Transparent = Color.Transparent.ToPixel<TPixel>();
@@ -56,13 +56,13 @@ internal abstract class GradientBrushApplicatorBase<TPixel> : BrushApplicator<TP
5656
private readonly GradientRepetitionMode repetitionMode;
5757

5858
/// <summary>
59-
/// Initializes a new instance of the <see cref="GradientBrushApplicatorBase{TPixel}"/> class.
59+
/// Initializes a new instance of the <see cref="GradientBrushApplicator{TPixel}"/> class.
6060
/// </summary>
6161
/// <param name="target">The target.</param>
6262
/// <param name="options">The options.</param>
6363
/// <param name="colorStops">An array of color stops sorted by their position.</param>
6464
/// <param name="repetitionMode">Defines if and how the gradient should be repeated.</param>
65-
protected GradientBrushApplicatorBase(
65+
protected GradientBrushApplicator(
6666
ImageFrame<TPixel> target,
6767
GraphicsOptions options,
6868
ColorStop[] colorStops,

src/ImageSharp.Drawing/Processing/LinearGradientBrush.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.Processing
1313
/// Supported right now:
1414
/// - a set of colors in relative distances to each other.
1515
/// </summary>
16-
public sealed class LinearGradientBrush : GradientBrushBase
16+
public sealed class LinearGradientBrush : GradientBrush
1717
{
1818
private readonly PointF p1;
1919

@@ -53,7 +53,7 @@ public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
5353
/// <summary>
5454
/// The linear gradient brush applicator.
5555
/// </summary>
56-
private sealed class LinearGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
56+
private sealed class LinearGradientBrushApplicator<TPixel> : GradientBrushApplicator<TPixel>
5757
where TPixel : struct, IPixel<TPixel>
5858
{
5959
private readonly PointF start;
@@ -121,7 +121,7 @@ public LinearGradientBrushApplicator(
121121

122122
// some helpers:
123123
this.alongsSquared = (this.alongX * this.alongX) + (this.alongY * this.alongY);
124-
this.length = (float)Math.Sqrt(this.alongsSquared);
124+
this.length = MathF.Sqrt(this.alongsSquared);
125125
}
126126

127127
protected override float PositionOnGradient(float x, float y)
@@ -145,7 +145,7 @@ protected override float PositionOnGradient(float x, float y)
145145
float y4 = y + (k * this.alongX);
146146

147147
// get distance from (x4,y4) to start
148-
float distance = (float)Math.Sqrt(Math.Pow(x4 - this.start.X, 2) + Math.Pow(y4 - this.start.Y, 2));
148+
float distance = MathF.Sqrt(MathF.Pow(x4 - this.start.X, 2) + MathF.Pow(y4 - this.start.Y, 2));
149149

150150
// get and return ratio
151151
float ratio = distance / this.length;

src/ImageSharp.Drawing/Processing/RadialGradientBrush.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace SixLabors.ImageSharp.Processing
1111
/// <summary>
1212
/// A Circular Gradient Brush, defined by center point and radius.
1313
/// </summary>
14-
public sealed class RadialGradientBrush : GradientBrushBase
14+
public sealed class RadialGradientBrush : GradientBrush
1515
{
1616
private readonly PointF center;
1717

1818
private readonly float radius;
1919

20-
/// <inheritdoc cref="GradientBrushBase" />
20+
/// <inheritdoc cref="GradientBrush" />
2121
/// <param name="center">The center of the circular gradient and 0 for the color stops.</param>
2222
/// <param name="radius">The radius of the circular gradient and 1 for the color stops.</param>
2323
/// <param name="repetitionMode">Defines how the colors in the gradient are repeated.</param>
@@ -47,7 +47,7 @@ public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
4747
this.RepetitionMode);
4848

4949
/// <inheritdoc />
50-
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
50+
private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicator<TPixel>
5151
where TPixel : struct, IPixel<TPixel>
5252
{
5353
private readonly PointF center;
@@ -90,7 +90,7 @@ public override void Dispose()
9090
/// <returns>the position on the color gradient.</returns>
9191
protected override float PositionOnGradient(float x, float y)
9292
{
93-
float distance = (float)Math.Sqrt(Math.Pow(this.center.X - x, 2) + Math.Pow(this.center.Y - y, 2));
93+
float distance = MathF.Sqrt(MathF.Pow(this.center.X - x, 2) + MathF.Pow(this.center.Y - y, 2));
9494
return distance / this.radius;
9595
}
9696

tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace SixLabors.ImageSharp.Tests
1111
{
1212
public abstract class BaseImageOperationsExtensionTest
1313
{
14-
protected readonly IImageProcessingContext<Rgba32> operations;
14+
protected readonly IImageProcessingContext operations;
1515
private readonly FakeImageOperationsProvider.FakeImageOperations<Rgba32> internalOperations;
1616
protected readonly Rectangle rect;
1717
protected readonly GraphicsOptions options;

tests/ImageSharp.Tests/FakeImageOperationsProvider.cs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public FakeImageOperations(Image<TPixel> source, bool mutate)
5757

5858
public MemoryAllocator MemoryAllocator => this.Source.GetConfiguration().MemoryAllocator;
5959

60-
public Image<TPixel> Apply()
60+
public Image<TPixel> GetResultImage()
6161
{
6262
return this.Source;
6363
}
@@ -86,25 +86,6 @@ public IImageProcessingContext ApplyProcessor(IImageProcessor processor)
8686
return this;
8787
}
8888

89-
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor, Rectangle rectangle)
90-
{
91-
this.Applied.Add(new AppliedOperation
92-
{
93-
GenericProcessor = processor,
94-
Rectangle = rectangle
95-
});
96-
return this;
97-
}
98-
99-
public IImageProcessingContext<TPixel> ApplyProcessor(IImageProcessor<TPixel> processor)
100-
{
101-
this.Applied.Add(new AppliedOperation
102-
{
103-
GenericProcessor = processor
104-
});
105-
return this;
106-
}
107-
10889
public struct AppliedOperation
10990
{
11091
public Rectangle? Rectangle { get; set; }

0 commit comments

Comments
 (0)