@@ -22,33 +22,43 @@ namespace GitHub.VisualStudio.UI.UI.Controls
2222 public partial class PullRequestStatusCircle : UserControl
2323 {
2424 public static readonly DependencyProperty ErrorCountProperty = DependencyProperty . Register (
25- "ErrorCount" , typeof ( int ) , typeof ( PullRequestStatusCircle ) , new PropertyMetadata ( 0 ) ) ;
25+ "ErrorCount" , typeof ( int ) , typeof ( PullRequestStatusCircle ) ,
26+ new PropertyMetadata ( 0 , ( d , args ) => ( ( PullRequestStatusCircle ) d ) . ErrorCount = ( int ) args . NewValue ) ) ;
2627
2728 public static readonly DependencyProperty SuccessCountProperty = DependencyProperty . Register (
28- "SuccessCount" , typeof ( int ) , typeof ( PullRequestStatusCircle ) , new PropertyMetadata ( 0 ) ) ;
29+ "SuccessCount" , typeof ( int ) , typeof ( PullRequestStatusCircle ) ,
30+ new PropertyMetadata ( 0 , ( d , args ) => ( ( PullRequestStatusCircle ) d ) . SuccessCount = ( int ) args . NewValue ) ) ;
2931
3032 public static readonly DependencyProperty PendingCountProperty = DependencyProperty . Register (
31- "PendingCount" , typeof ( int ) , typeof ( PullRequestStatusCircle ) , new PropertyMetadata ( 0 ) ) ;
33+ "PendingCount" , typeof ( int ) , typeof ( PullRequestStatusCircle ) ,
34+ new PropertyMetadata ( 0 , ( d , args ) => ( ( PullRequestStatusCircle ) d ) . PendingCount = ( int ) args . NewValue ) ) ;
3235
3336 public static readonly DependencyProperty RadiusProperty = DependencyProperty . Register (
34- "Radius" , typeof ( double ) , typeof ( PullRequestStatusCircle ) , new PropertyMetadata ( ( double ) 250 ) ) ;
37+ "Radius" , typeof ( double ) , typeof ( PullRequestStatusCircle ) ,
38+ new PropertyMetadata ( ( double ) 250 , ( d , args ) => ( ( PullRequestStatusCircle ) d ) . Radius = ( double ) args . NewValue ) ) ;
3539
3640 public static readonly DependencyProperty InnerRadiusProperty = DependencyProperty . Register (
37- "InnerRadius" , typeof ( double ) , typeof ( PullRequestStatusCircle ) , new PropertyMetadata ( ( double ) 200 ) ) ;
41+ "InnerRadius" , typeof ( double ) , typeof ( PullRequestStatusCircle ) ,
42+ new PropertyMetadata ( ( double ) 200 , ( d , args ) => ( ( PullRequestStatusCircle ) d ) . InnerRadius = ( double ) args . NewValue ) ) ;
3843
39- public static IEnumerable < Point > GeneratePoints ( double size , float percentage )
44+ public static IEnumerable < Point > GeneratePoints ( double diameter , float percentage )
4045 {
46+ if ( float . IsNaN ( percentage ) )
47+ {
48+ return Array . Empty < Point > ( ) ;
49+ }
50+
4151 if ( percentage < 0 || percentage > 1 )
4252 {
43- throw new ArgumentException ( ) ;
53+ throw new ArgumentException ( $@ "` { nameof ( percentage ) } ` must be >=0 and <=1" , nameof ( percentage ) ) ;
4454 }
4555
46- var halfSize = size / 2 ;
47- var origin = new Point ( halfSize , halfSize ) ;
48- var topMiddle = new Point ( halfSize , 0 ) ;
49- var topRight = new Point ( size , 0 ) ;
50- var bottomRight = new Point ( size , size ) ;
51- var bottomLeft = new Point ( 0 , size ) ;
56+ var radius = diameter / 2 ;
57+ var origin = new Point ( radius , radius ) ;
58+ var topMiddle = new Point ( radius , 0 ) ;
59+ var topRight = new Point ( diameter , 0 ) ;
60+ var bottomRight = new Point ( diameter , diameter ) ;
61+ var bottomLeft = new Point ( 0 , diameter ) ;
5262 var topLeft = new Point ( 0 , 0 ) ;
5363
5464 if ( percentage == 1 )
@@ -64,74 +74,74 @@ public static IEnumerable<Point> GeneratePoints(double size, float percentage)
6474 var angleDegrees = adjustedDegrees - 90 ;
6575 var angleRadians = ToRadians ( angleDegrees ) ;
6676 var tan = Math . Tan ( angleRadians ) ;
67- var oppositeEdge = tan * halfSize ;
68- return new [ ] { origin , topMiddle , new Point ( halfSize + oppositeEdge , 0 ) } ;
77+ var oppositeEdge = tan * radius ;
78+ return new [ ] { origin , topMiddle , new Point ( radius + oppositeEdge , 0 ) } ;
6979 }
7080
7181 if ( adjustedDegrees >= 135 && adjustedDegrees < 180 )
7282 {
7383 var angleDegrees = adjustedDegrees - 135 ;
7484 var angleRadians = ToRadians ( angleDegrees ) ;
7585 var tan = Math . Tan ( angleRadians ) ;
76- var oppositeEdge = tan * halfSize ;
77- return new [ ] { origin , topMiddle , topRight , new Point ( size , oppositeEdge ) } ;
86+ var oppositeEdge = tan * radius ;
87+ return new [ ] { origin , topMiddle , topRight , new Point ( diameter , oppositeEdge ) } ;
7888 }
7989
8090 if ( adjustedDegrees >= 180 && adjustedDegrees < 225 )
8191 {
8292 var angleDegrees = adjustedDegrees - 180 ;
8393 var angleRadians = ToRadians ( angleDegrees ) ;
8494 var tan = Math . Tan ( angleRadians ) ;
85- var oppositeEdge = tan * halfSize ;
86- return new [ ] { origin , topMiddle , topRight , new Point ( size , halfSize + oppositeEdge ) } ;
95+ var oppositeEdge = tan * radius ;
96+ return new [ ] { origin , topMiddle , topRight , new Point ( diameter , radius + oppositeEdge ) } ;
8797 }
8898
8999 if ( adjustedDegrees >= 225 && adjustedDegrees < 270 )
90100 {
91101 var angleDegrees = adjustedDegrees - 225 ;
92102 var angleRadians = ToRadians ( angleDegrees ) ;
93103 var tan = Math . Tan ( angleRadians ) ;
94- var oppositeEdge = tan * halfSize ;
95- return new [ ] { origin , topMiddle , topRight , bottomRight , new Point ( size - oppositeEdge , size ) } ;
104+ var oppositeEdge = tan * radius ;
105+ return new [ ] { origin , topMiddle , topRight , bottomRight , new Point ( diameter - oppositeEdge , diameter ) } ;
96106 }
97107
98108 if ( adjustedDegrees >= 270 && adjustedDegrees < 315 )
99109 {
100110 var angleDegrees = adjustedDegrees - 270 ;
101111 var angleRadians = ToRadians ( angleDegrees ) ;
102112 var tan = Math . Tan ( angleRadians ) ;
103- var oppositeEdge = tan * halfSize ;
104- return new [ ] { origin , topMiddle , topRight , bottomRight , new Point ( halfSize - oppositeEdge , size ) } ;
113+ var oppositeEdge = tan * radius ;
114+ return new [ ] { origin , topMiddle , topRight , bottomRight , new Point ( radius - oppositeEdge , diameter ) } ;
105115 }
106116
107117 if ( adjustedDegrees >= 315 && adjustedDegrees < 360 )
108118 {
109119 var angleDegrees = adjustedDegrees - 315 ;
110120 var angleRadians = ToRadians ( angleDegrees ) ;
111121 var tan = Math . Tan ( angleRadians ) ;
112- var oppositeEdge = tan * halfSize ;
113- return new [ ] { origin , topMiddle , topRight , bottomRight , bottomLeft , new Point ( 0 , size - oppositeEdge ) } ;
122+ var oppositeEdge = tan * radius ;
123+ return new [ ] { origin , topMiddle , topRight , bottomRight , bottomLeft , new Point ( 0 , diameter - oppositeEdge ) } ;
114124 }
115125
116126 if ( adjustedDegrees >= 0 && adjustedDegrees < 45 )
117127 {
118128 var angleDegrees = adjustedDegrees ;
119129 var angleRadians = ToRadians ( angleDegrees ) ;
120130 var tan = Math . Tan ( angleRadians ) ;
121- var oppositeEdge = tan * halfSize ;
122- return new [ ] { origin , topMiddle , topRight , bottomRight , bottomLeft , new Point ( 0 , halfSize - oppositeEdge ) } ;
131+ var oppositeEdge = tan * radius ;
132+ return new [ ] { origin , topMiddle , topRight , bottomRight , bottomLeft , new Point ( 0 , radius - oppositeEdge ) } ;
123133 }
124134
125135 if ( adjustedDegrees >= 45 && adjustedDegrees < 90 )
126136 {
127137 var angleDegrees = adjustedDegrees - 45 ;
128138 var angleRadians = ToRadians ( angleDegrees ) ;
129139 var tan = Math . Tan ( angleRadians ) ;
130- var oppositeEdge = tan * halfSize ;
140+ var oppositeEdge = tan * radius ;
131141 return new [ ] { origin , topMiddle , topRight , bottomRight , bottomLeft , topLeft , new Point ( oppositeEdge , 0 ) } ;
132142 }
133143
134- return new Point [ 0 ] ;
144+ throw new InvalidOperationException ( ) ;
135145 }
136146
137147 public static double ToRadians ( float val )
0 commit comments