11// Copyright (c) Six Labors.
22// Licensed under the Six Labors Split License.
33
4- #nullable disable
5-
64using System . Numerics ;
75using SixLabors . ImageSharp . Drawing . Utilities ;
86
@@ -76,7 +74,7 @@ public PathGradientBrush(PointF[] points, Color[] colors, Color centerColor)
7674 }
7775
7876 /// <inheritdoc />
79- public override bool Equals ( Brush other )
77+ public override bool Equals ( Brush ? other )
8078 {
8179 if ( other is PathGradientBrush brush )
8280 {
@@ -123,7 +121,7 @@ private static Color CalculateCenterColor(Color[] colors)
123121 return new Color ( colors . Select ( c => ( Vector4 ) c ) . Aggregate ( ( p1 , p2 ) => p1 + p2 ) / colors . Length ) ;
124122 }
125123
126- private static float DistanceBetween ( PointF p1 , PointF p2 ) => ( ( Vector2 ) ( p2 - p1 ) ) . Length ( ) ;
124+ private static float DistanceBetween ( Vector2 p1 , Vector2 p2 ) => ( p2 - p1 ) . Length ( ) ;
127125
128126 private readonly struct Intersection
129127 {
@@ -178,13 +176,14 @@ public Vector4 ColorAt(float distance)
178176
179177 public Vector4 ColorAt ( PointF point ) => this . ColorAt ( DistanceBetween ( point , this . Start ) ) ;
180178
181- public bool Equals ( Edge other )
182- => other . Start == this . Start &&
183- other . End == this . End &&
184- other . StartColor . Equals ( this . StartColor ) &&
185- other . EndColor . Equals ( this . EndColor ) ;
179+ public bool Equals ( Edge ? other )
180+ => other != null &&
181+ other . Start == this . Start &&
182+ other . End == this . End &&
183+ other . StartColor . Equals ( this . StartColor ) &&
184+ other . EndColor . Equals ( this . EndColor ) ;
186185
187- public override bool Equals ( object obj ) => this . Equals ( obj as Edge ) ;
186+ public override bool Equals ( object ? obj ) => this . Equals ( obj as Edge ) ;
188187
189188 public override int GetHashCode ( )
190189 => HashCode . Combine ( this . Start , this . End , this . StartColor , this . EndColor ) ;
@@ -249,7 +248,7 @@ public PathGradientBrushApplicator(
249248 {
250249 get
251250 {
252- var point = new Vector2 ( x , y ) ;
251+ Vector2 point = new ( x , y ) ;
253252
254253 if ( point == this . center )
255254 {
@@ -278,7 +277,7 @@ public PathGradientBrushApplicator(
278277 return px ;
279278 }
280279
281- var direction = Vector2 . Normalize ( point - this . center ) ;
280+ Vector2 direction = Vector2 . Normalize ( point - this . center ) ;
282281 Vector2 end = point + ( direction * this . maxDistance ) ;
283282
284283 ( Edge Edge , Vector2 Point ) ? isc = this . FindIntersection ( point , end ) ;
@@ -294,7 +293,7 @@ public PathGradientBrushApplicator(
294293 float length = DistanceBetween ( intersection , this . center ) ;
295294 float ratio = length > 0 ? DistanceBetween ( intersection , point ) / length : 0 ;
296295
297- var color = Vector4 . Lerp ( edgeColor , this . centerColor , ratio ) ;
296+ Vector4 color = Vector4 . Lerp ( edgeColor , this . centerColor , ratio ) ;
298297
299298 TPixel pixel = default ;
300299 pixel . FromScaledVector4 ( color ) ;
@@ -305,8 +304,8 @@ public PathGradientBrushApplicator(
305304 /// <inheritdoc />
306305 public override void Apply ( Span < float > scanline , int x , int y )
307306 {
308- Span < float > amounts = this . blenderBuffers . AmountSpan . Slice ( 0 , scanline . Length ) ;
309- Span < TPixel > overlays = this . blenderBuffers . OverlaySpan . Slice ( 0 , scanline . Length ) ;
307+ Span < float > amounts = this . blenderBuffers . AmountSpan [ .. scanline . Length ] ;
308+ Span < TPixel > overlays = this . blenderBuffers . OverlaySpan [ .. scanline . Length ] ;
310309 float blendPercentage = this . Options . BlendPercentage ;
311310
312311 // TODO: Remove bounds checks.
@@ -355,7 +354,7 @@ protected override void Dispose(bool disposing)
355354 {
356355 Vector2 ip = default ;
357356 Vector2 closestIntersection = default ;
358- Edge closestEdge = null ;
357+ Edge ? closestEdge = null ;
359358 const float minDistance = float . MaxValue ;
360359 foreach ( Edge edge in this . edges )
361360 {
@@ -385,9 +384,9 @@ private static bool FindPointOnTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Vect
385384 Vector2 pv2 = point - v2 ;
386385 Vector2 pv3 = point - v3 ;
387386
388- var d1 = Vector3 . Cross ( new Vector3 ( e1 . X , e1 . Y , 0 ) , new Vector3 ( pv1 . X , pv1 . Y , 0 ) ) ;
389- var d2 = Vector3 . Cross ( new Vector3 ( e2 . X , e2 . Y , 0 ) , new Vector3 ( pv2 . X , pv2 . Y , 0 ) ) ;
390- var d3 = Vector3 . Cross ( new Vector3 ( e3 . X , e3 . Y , 0 ) , new Vector3 ( pv3 . X , pv3 . Y , 0 ) ) ;
387+ Vector3 d1 = Vector3 . Cross ( new Vector3 ( e1 . X , e1 . Y , 0 ) , new Vector3 ( pv1 . X , pv1 . Y , 0 ) ) ;
388+ Vector3 d2 = Vector3 . Cross ( new Vector3 ( e2 . X , e2 . Y , 0 ) , new Vector3 ( pv2 . X , pv2 . Y , 0 ) ) ;
389+ Vector3 d3 = Vector3 . Cross ( new Vector3 ( e3 . X , e3 . Y , 0 ) , new Vector3 ( pv3 . X , pv3 . Y , 0 ) ) ;
391390
392391 if ( Math . Sign ( Vector3 . Dot ( d1 , d2 ) ) * Math . Sign ( Vector3 . Dot ( d1 , d3 ) ) == - 1 || Math . Sign ( Vector3 . Dot ( d1 , d2 ) ) * Math . Sign ( Vector3 . Dot ( d2 , d3 ) ) == - 1 )
393392 {
0 commit comments