@@ -22,10 +22,7 @@ public sealed class PathGradientBrush : Brush
2222 /// <param name="colors">Array of colors that correspond to each point in the polygon.</param>
2323 public PathGradientBrush ( PointF [ ] points , Color [ ] colors )
2424 {
25- if ( points == null )
26- {
27- throw new ArgumentNullException ( nameof ( points ) ) ;
28- }
25+ ArgumentNullException . ThrowIfNull ( points ) ;
2926
3027 if ( points . Length < 3 )
3128 {
@@ -34,10 +31,7 @@ public PathGradientBrush(PointF[] points, Color[] colors)
3431 "There must be at least 3 lines to construct a path gradient brush." ) ;
3532 }
3633
37- if ( colors == null )
38- {
39- throw new ArgumentNullException ( nameof ( colors ) ) ;
40- }
34+ ArgumentNullException . ThrowIfNull ( colors ) ;
4135
4236 if ( colors . Length == 0 )
4337 {
@@ -106,10 +100,7 @@ public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
106100
107101 private static Color CalculateCenterColor ( Color [ ] colors )
108102 {
109- if ( colors == null )
110- {
111- throw new ArgumentNullException ( nameof ( colors ) ) ;
112- }
103+ ArgumentNullException . ThrowIfNull ( colors ) ;
113104
114105 if ( colors . Length == 0 )
115106 {
@@ -118,7 +109,7 @@ private static Color CalculateCenterColor(Color[] colors)
118109 "One or more color is needed to construct a path gradient brush." ) ;
119110 }
120111
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 ) ;
122113 }
123114
124115 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)
147138 {
148139 this . Start = start ;
149140 this . End = end ;
150- this . StartColor = ( Vector4 ) startColor ;
151- this . EndColor = ( Vector4 ) endColor ;
141+ this . StartColor = startColor . ToScaledVector4 ( ) ;
142+ this . EndColor = endColor . ToScaledVector4 ( ) ;
152143
153144 this . length = DistanceBetween ( this . End , this . Start ) ;
154145 }
@@ -236,7 +227,7 @@ public PathGradientBrushApplicator(
236227 Vector2 [ ] points = edges . Select ( s => s . Start ) . ToArray ( ) ;
237228
238229 this . center = points . Aggregate ( ( p1 , p2 ) => p1 + p2 ) / edges . Count ;
239- this . centerColor = ( Vector4 ) centerColor ;
230+ this . centerColor = centerColor . ToScaledVector4 ( ) ;
240231 this . hasSpecialCenterColor = hasSpecialCenterColor ;
241232 this . centerPixel = centerColor . ToPixel < TPixel > ( ) ;
242233 this . maxDistance = points . Select ( p => p - this . center ) . Max ( d => d . Length ( ) ) ;
@@ -272,9 +263,7 @@ public PathGradientBrushApplicator(
272263 + ( u * this . edges [ 0 ] . EndColor )
273264 + ( v * this . edges [ 2 ] . StartColor ) ;
274265
275- TPixel px = default ;
276- px . FromScaledVector4 ( pointColor ) ;
277- return px ;
266+ return TPixel . FromScaledVector4 ( pointColor ) ;
278267 }
279268
280269 Vector2 direction = Vector2 . Normalize ( point - this . center ) ;
@@ -295,9 +284,7 @@ public PathGradientBrushApplicator(
295284
296285 Vector4 color = Vector4 . Lerp ( edgeColor , this . centerColor , ratio ) ;
297286
298- TPixel pixel = default ;
299- pixel . FromScaledVector4 ( color ) ;
300- return pixel ;
287+ return TPixel . FromScaledVector4 ( color ) ;
301288 }
302289 }
303290
0 commit comments