@@ -22,10 +22,7 @@ public sealed class PathGradientBrush : Brush
22
22
/// <param name="colors">Array of colors that correspond to each point in the polygon.</param>
23
23
public PathGradientBrush ( PointF [ ] points , Color [ ] colors )
24
24
{
25
- if ( points == null )
26
- {
27
- throw new ArgumentNullException ( nameof ( points ) ) ;
28
- }
25
+ ArgumentNullException . ThrowIfNull ( points ) ;
29
26
30
27
if ( points . Length < 3 )
31
28
{
@@ -34,10 +31,7 @@ public PathGradientBrush(PointF[] points, Color[] colors)
34
31
"There must be at least 3 lines to construct a path gradient brush." ) ;
35
32
}
36
33
37
- if ( colors == null )
38
- {
39
- throw new ArgumentNullException ( nameof ( colors ) ) ;
40
- }
34
+ ArgumentNullException . ThrowIfNull ( colors ) ;
41
35
42
36
if ( colors . Length == 0 )
43
37
{
@@ -106,10 +100,7 @@ public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
106
100
107
101
private static Color CalculateCenterColor ( Color [ ] colors )
108
102
{
109
- if ( colors == null )
110
- {
111
- throw new ArgumentNullException ( nameof ( colors ) ) ;
112
- }
103
+ ArgumentNullException . ThrowIfNull ( colors ) ;
113
104
114
105
if ( colors . Length == 0 )
115
106
{
@@ -118,7 +109,7 @@ private static Color CalculateCenterColor(Color[] colors)
118
109
"One or more color is needed to construct a path gradient brush." ) ;
119
110
}
120
111
121
- return new Color ( colors . Select ( c => ( Vector4 ) c ) . Aggregate ( ( p1 , p2 ) => p1 + p2 ) / colors . Length ) ;
112
+ return Color . FromScaledVector ( colors . Select ( c => c . ToScaledVector4 ( ) ) . Aggregate ( ( p1 , p2 ) => p1 + p2 ) / colors . Length ) ;
122
113
}
123
114
124
115
private static float DistanceBetween ( Vector2 p1 , Vector2 p2 ) => ( p2 - p1 ) . Length ( ) ;
@@ -147,8 +138,8 @@ public Edge(Vector2 start, Vector2 end, Color startColor, Color endColor)
147
138
{
148
139
this . Start = start ;
149
140
this . End = end ;
150
- this . StartColor = ( Vector4 ) startColor ;
151
- this . EndColor = ( Vector4 ) endColor ;
141
+ this . StartColor = startColor . ToScaledVector4 ( ) ;
142
+ this . EndColor = endColor . ToScaledVector4 ( ) ;
152
143
153
144
this . length = DistanceBetween ( this . End , this . Start ) ;
154
145
}
@@ -236,7 +227,7 @@ public PathGradientBrushApplicator(
236
227
Vector2 [ ] points = edges . Select ( s => s . Start ) . ToArray ( ) ;
237
228
238
229
this . center = points . Aggregate ( ( p1 , p2 ) => p1 + p2 ) / edges . Count ;
239
- this . centerColor = ( Vector4 ) centerColor ;
230
+ this . centerColor = centerColor . ToScaledVector4 ( ) ;
240
231
this . hasSpecialCenterColor = hasSpecialCenterColor ;
241
232
this . centerPixel = centerColor . ToPixel < TPixel > ( ) ;
242
233
this . maxDistance = points . Select ( p => p - this . center ) . Max ( d => d . Length ( ) ) ;
@@ -272,9 +263,7 @@ public PathGradientBrushApplicator(
272
263
+ ( u * this . edges [ 0 ] . EndColor )
273
264
+ ( v * this . edges [ 2 ] . StartColor ) ;
274
265
275
- TPixel px = default ;
276
- px . FromScaledVector4 ( pointColor ) ;
277
- return px ;
266
+ return TPixel . FromScaledVector4 ( pointColor ) ;
278
267
}
279
268
280
269
Vector2 direction = Vector2 . Normalize ( point - this . center ) ;
@@ -295,9 +284,7 @@ public PathGradientBrushApplicator(
295
284
296
285
Vector4 color = Vector4 . Lerp ( edgeColor , this . centerColor , ratio ) ;
297
286
298
- TPixel pixel = default ;
299
- pixel . FromScaledVector4 ( color ) ;
300
- return pixel ;
287
+ return TPixel . FromScaledVector4 ( color ) ;
301
288
}
302
289
}
303
290
0 commit comments