Skip to content

Commit f136c25

Browse files
Normalize and fix build
1 parent b5eeb6b commit f136c25

19 files changed

Lines changed: 277 additions & 328 deletions

src/ImageSharp.Drawing/Processing/Brush.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@ public abstract BrushApplicator<TPixel> CreateApplicator<TPixel>(
3636
ImageFrame<TPixel> source,
3737
RectangleF region)
3838
where TPixel : unmanaged, IPixel<TPixel>;
39+
40+
/// <inheritdoc/>
41+
public abstract bool Equals(Brush other);
3942
}
4043
}

src/ImageSharp.Drawing/Processing/GradientBrush.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,15 @@ protected GradientBrush(GradientRepetitionMode repetitionMode, params ColorStop[
3737
/// <inheritdoc />
3838
public override bool Equals(Brush other)
3939
{
40-
if (other is GradientBrush sb)
40+
if (other is GradientBrush brush)
4141
{
42-
return sb.RepetitionMode == this.RepetitionMode &&
43-
Enumerable.SequenceEqual(sb.ColorStops, this.ColorStops);
42+
return this.RepetitionMode == brush.RepetitionMode
43+
&& this.ColorStops?.SequenceEqual(brush.ColorStops) == true;
4444
}
4545

4646
return false;
4747
}
4848

49-
/// <inheritdoc />
50-
public abstract BrushApplicator<TPixel> CreateApplicator<TPixel>(
51-
Configuration configuration,
52-
GraphicsOptions options,
53-
ImageFrame<TPixel> source,
54-
RectangleF region)
55-
where TPixel : unmanaged, IPixel<TPixel>;
56-
5749
/// <summary>
5850
/// Base class for gradient brush applicators
5951
/// </summary>
@@ -124,7 +116,7 @@ protected GradientBrushApplicator(
124116

125117
break;
126118
case GradientRepetitionMode.DontFill:
127-
if (positionOnCompleteGradient > 1 || positionOnCompleteGradient < 0)
119+
if (positionOnCompleteGradient is > 1 or < 0)
128120
{
129121
return Transparent;
130122
}

src/ImageSharp.Drawing/Processing/IPen.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/ImageSharp.Drawing/Processing/LinearGradientBrush.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace SixLabors.ImageSharp.Drawing.Processing
1414
public sealed class LinearGradientBrush : GradientBrush
1515
{
1616
private readonly PointF p1;
17-
1817
private readonly PointF p2;
1918

2019
/// <summary>
@@ -35,6 +34,19 @@ public LinearGradientBrush(
3534
this.p2 = p2;
3635
}
3736

37+
/// <inheritdoc/>
38+
public override bool Equals(Brush other)
39+
{
40+
if (other is LinearGradientBrush brush)
41+
{
42+
return base.Equals(other)
43+
&& this.p1.Equals(brush.p1)
44+
&& this.p2.Equals(brush.p2);
45+
}
46+
47+
return false;
48+
}
49+
3850
/// <inheritdoc />
3951
public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
4052
Configuration configuration,

src/ImageSharp.Drawing/Processing/PathGradientBrush.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Diagnostics.CodeAnalysis;
76
using System.Linq;
87
using System.Numerics;
98
using SixLabors.ImageSharp.Drawing.Utilities;
@@ -81,9 +80,11 @@ public PathGradientBrush(PointF[] points, Color[] colors, Color centerColor)
8180
/// <inheritdoc />
8281
public override bool Equals(Brush other)
8382
{
84-
if (other is PathGradientBrush sb)
83+
if (other is PathGradientBrush brush)
8584
{
86-
return Enumerable.SequenceEqual(sb.edges, this.edges);
85+
return this.centerColor.Equals(brush.centerColor)
86+
&& this.hasSpecialCenterColor.Equals(brush.hasSpecialCenterColor)
87+
&& this.edges?.SequenceEqual(brush.edges) == true;
8788
}
8889

8990
return false;
@@ -364,7 +365,7 @@ protected override void Dispose(bool disposing)
364365
}
365366
}
366367

367-
return closestEdge != null ? (closestEdge, closestIntersection) : ((Edge Edge, Vector2 Point)?)null;
368+
return closestEdge != null ? (closestEdge, closestIntersection) : null;
368369
}
369370

370371
private static bool FindPointOnTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Vector2 point, out float u, out float v)

src/ImageSharp.Drawing/Processing/PatternBrush.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5-
using System.Linq;
65
using System.Numerics;
76
using SixLabors.ImageSharp.Drawing.Utilities;
87
using SixLabors.ImageSharp.Memory;
@@ -92,8 +91,8 @@ public override bool Equals(Brush other)
9291
{
9392
if (other is PatternBrush sb)
9493
{
95-
return sb.pattern.Equals(this.pattern) &&
96-
sb.patternVector.Equals(this.patternVector);
94+
return sb.pattern.Equals(this.pattern)
95+
&& sb.patternVector.Equals(this.patternVector);
9796
}
9897

9998
return false;
Lines changed: 35 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,77 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4-
using System;
5-
using System.Diagnostics.CodeAnalysis;
6-
using System.Linq;
7-
84
namespace SixLabors.ImageSharp.Drawing.Processing
95
{
106
/// <summary>
11-
/// Provides a pen that can apply a pattern to a line with a set brush and thickness
7+
/// Defines a pen that can apply a pattern to a line with a set brush and thickness
128
/// </summary>
139
/// <remarks>
14-
/// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be
15-
/// converted into a pattern that is 3.5 times longer that the width with 3 sections
16-
/// section 1 will be width long (making a square) and will be filled by the brush
17-
/// section 2 will be width * 2 long and will be empty
18-
/// section 3 will be width/2 long and will be filled
19-
/// the pattern will immediately repeat without gap.
10+
/// The pattern will be in to the form of <code>new float[]{ 1f, 2f, 0.5f}</code> this will be
11+
/// converted into a pattern that is 3.5 times longer that the width with 3 sections.
12+
/// <list type="bullet">
13+
/// <item>Section 1 will be width long (making a square) and will be filled by the brush.</item>
14+
/// <item>Section 2 will be width * 2 long and will be empty.</item>
15+
/// <item>ection 3 will be width/2 long and will be filled.</item>
16+
/// </list>
17+
/// The pattern will immediately repeat without gap.
2018
/// </remarks>
21-
public class PatternPen : IPen
19+
public class PatternPen : Pen
2220
{
23-
private readonly float[] pattern;
24-
2521
/// <summary>
2622
/// Initializes a new instance of the <see cref="PatternPen"/> class.
2723
/// </summary>
2824
/// <param name="color">The color.</param>
29-
/// <param name="width">The width.</param>
30-
/// <param name="pattern">The pattern.</param>
31-
public PatternPen(Color color, float width, float[] pattern)
32-
: this(new SolidBrush(color), width, pattern)
33-
{
34-
}
35-
36-
/// <summary>
37-
/// Initializes a new instance of the <see cref="PatternPen"/> class.
38-
/// </summary>
39-
/// <param name="brush">The brush.</param>
40-
/// <param name="width">The width.</param>
41-
/// <param name="pattern">The pattern.</param>
42-
public PatternPen(IBrush brush, float width, float[] pattern)
43-
{
44-
Guard.MustBeGreaterThan(width, 0, nameof(width));
45-
46-
this.StrokeFill = brush;
47-
this.StrokeWidth = width;
48-
this.pattern = pattern;
49-
}
50-
51-
/// <inheritdoc/>
52-
public IBrush StrokeFill { get; }
53-
54-
/// <summary>
55-
/// Gets the width to apply to the stroke
56-
/// </summary>
57-
public float? StrokeWidth { get; }
58-
59-
/// <summary>
60-
/// Gets the stoke pattern.
61-
/// </summary>
62-
public ReadOnlySpan<float> StrokePattern => this.pattern;
63-
64-
/// <summary>
65-
/// Gets or sets the stroke joint style
66-
/// </summary>
67-
public JointStyle JointStyle { get; set; }
68-
69-
/// <summary>
70-
/// Gets or sets the stroke endcap style
71-
/// </summary>
72-
public EndCapStyle EndCapStyle { get; set; }
73-
74-
/// <inheritdoc/>
75-
public bool Equals(IPen other)
76-
{
77-
if (other is PatternPen p)
78-
{
79-
return p.StrokeWidth == this.StrokeWidth &&
80-
p.JointStyle == this.JointStyle &&
81-
p.EndCapStyle == this.EndCapStyle &&
82-
p.StrokeFill.Equals(this.StrokeFill) &&
83-
Enumerable.SequenceEqual(p.pattern, this.pattern);
84-
}
85-
86-
return false;
87-
}
88-
89-
/// <inheritdoc />
90-
public IPath GeneratePath(IPath path, float? defaultWidth = null)
91-
=> path.GenerateOutline(this.StrokeWidth ?? defaultWidth ?? 1, this.StrokePattern, this.JointStyle, this.EndCapStyle);
92-
}
93-
94-
/// <summary>
95-
/// Provides a pen that can apply a pattern to a line with a set brush and thickness
96-
/// </summary>
97-
/// <remarks>
98-
/// The pattern will be in to the form of new float[]{ 1f, 2f, 0.5f} this will be
99-
/// converted into a pattern that is 3.5 times longer that the width with 3 sections
100-
/// section 1 will be width long (making a square) and will be filled by the brush
101-
/// section 2 will be width * 2 long and will be empty
102-
/// section 3 will be width/2 long and will be filled
103-
/// the pattern will immediately repeat without gap.
104-
/// </remarks>
105-
public sealed class Pen
106-
{
107-
private readonly float[] pattern;
108-
109-
/// <summary>
110-
/// Initializes a new instance of the <see cref="PatternPen"/> class.
111-
/// </summary>
112-
/// <param name="strokeFill">The brush used to fill the stroke outline.</param>
113-
public Pen(Brush strokeFill)
114-
: this(strokeFill, 1)
25+
/// <param name="strokePattern">The stroke pattern.</param>
26+
public PatternPen(Color color, float[] strokePattern)
27+
: base(new SolidBrush(color), 1, strokePattern)
11528
{
11629
}
11730

11831
/// <summary>
11932
/// Initializes a new instance of the <see cref="PatternPen"/> class.
12033
/// </summary>
121-
/// <param name="strokeFill">The brush used to fill the stroke outline.</param>
34+
/// <param name="color">The color.</param>
12235
/// <param name="strokeWidth">The stroke width in px units.</param>
123-
public Pen(Brush strokeFill, float strokeWidth)
124-
: this(strokeFill, strokeWidth, Pens.EmptyPattern)
36+
/// <param name="strokePattern">The stroke pattern.</param>
37+
public PatternPen(Color color, float strokeWidth, float[] strokePattern)
38+
: base(new SolidBrush(color), strokeWidth, strokePattern)
12539
{
12640
}
12741

12842
/// <summary>
129-
/// Initializes a new instance of the <see cref="Pen"/> class.
43+
/// Initializes a new instance of the <see cref="PatternPen"/> class.
13044
/// </summary>
13145
/// <param name="strokeFill">The brush used to fill the stroke outline.</param>
13246
/// <param name="strokeWidth">The stroke width in px units.</param>
13347
/// <param name="strokePattern">The stroke pattern.</param>
134-
private Pen(Brush strokeFill, float strokeWidth, float[] strokePattern)
48+
public PatternPen(Brush strokeFill, float strokeWidth, float[] strokePattern)
49+
: base(strokeFill, strokeWidth, strokePattern)
13550
{
136-
Guard.MustBeGreaterThan(strokeWidth, 0, nameof(strokeWidth));
137-
138-
this.StrokeFill = strokeFill;
139-
this.StrokeWidth = strokeWidth;
140-
this.pattern = strokePattern;
14151
}
14252

14353
/// <summary>
144-
/// Initializes a new instance of the <see cref="Pen"/> class.
54+
/// Initializes a new instance of the <see cref="PatternPen"/> class.
14555
/// </summary>
14656
/// <param name="options">The pen options.</param>
147-
public Pen(PenOptions options)
57+
public PatternPen(PenOptions options)
58+
: base(options)
14859
{
149-
Guard.NotNull(options, nameof(options));
150-
151-
this.StrokeFill = options.StrokeFill;
152-
this.StrokeWidth = options.StrokeWidth;
153-
this.pattern = options.StrokePattern;
154-
this.JointStyle = options.JointStyle;
155-
this.EndCapStyle = options.EndCapStyle;
15660
}
15761

158-
/// <inheritdoc cref="PenOptions.StrokeFill"/>
159-
public Brush StrokeFill { get; }
160-
161-
/// <inheritdoc cref="PenOptions.StrokeWidth"/>
162-
public float StrokeWidth { get; }
163-
164-
/// <inheritdoc cref="PenOptions.StrokePattern"/>
165-
public ReadOnlySpan<float> StrokePattern => this.pattern;
62+
/// <inheritdoc/>
63+
public override bool Equals(Pen other)
64+
{
65+
if (other is PatternPen)
66+
{
67+
return base.Equals(other);
68+
}
16669

167-
/// <inheritdoc cref="PenOptions.JointStyle"/>
168-
public JointStyle JointStyle { get; }
70+
return false;
71+
}
16972

170-
/// <inheritdoc cref="PenOptions.EndCapStyle"/>
171-
public EndCapStyle EndCapStyle { get; }
73+
/// <inheritdoc />
74+
public override IPath GeneratePath(IPath path, float strokeWidth)
75+
=> path.GenerateOutline(strokeWidth, this.StrokePattern, this.JointStyle, this.EndCapStyle);
17276
}
17377
}

0 commit comments

Comments
 (0)