@@ -146,33 +146,41 @@ private void DrawLine(object sender, MouseEventArgs e)
146146
147147 private void DrawCircle ( object sender , MouseEventArgs e )
148148 {
149- if ( _isMoving is false )
149+ if ( ! _isMoving )
150150 {
151151 return ;
152152 }
153153
154154 var currentPoint = e . GetPosition ( MainInkCanvas ) ;
155- var radius = Math . Abs ( currentPoint . X - _startPoint . X ) ;
156- var points = new List < Point > ( ) ;
157155
156+ // Calculate the center of the circle
157+ var centerX = ( _startPoint . X + currentPoint . X ) / 2 ;
158+ var centerY = ( _startPoint . Y + currentPoint . Y ) / 2 ;
159+ var center = new Point ( centerX , centerY ) ;
160+
161+ var radius = Math . Sqrt ( Math . Pow ( currentPoint . X - centerX , 2 ) + Math . Pow ( currentPoint . Y - centerY , 2 ) ) ;
162+
163+ var points = new List < Point > ( ) ;
158164 var segments = 100 ;
159165 for ( var i = 0 ; i <= segments ; i ++ )
160166 {
161167 var angle = 2 * Math . PI * i / segments ;
162- var x = _startPoint . X + ( radius * Math . Cos ( angle ) ) ;
163- var y = _startPoint . Y + ( radius * Math . Sin ( angle ) ) ;
168+ var x = center . X + ( radius * Math . Cos ( angle ) ) ;
169+ var y = center . Y + ( radius * Math . Sin ( angle ) ) ;
164170 points . Add ( new Point ( x , y ) ) ;
165171 }
166172
167173 var stylusPoints = new StylusPointCollection ( points ) ;
168174 var newAttributes = MainInkCanvas . DefaultDrawingAttributes . Clone ( ) ;
169175 newAttributes . StylusTip = StylusTip . Ellipse ;
170176 newAttributes . IgnorePressure = true ;
177+
171178 var stroke = new Stroke ( stylusPoints )
172179 {
173180 DrawingAttributes = newAttributes ,
174181 } ;
175- if ( _lastStroke is not null )
182+
183+ if ( _lastStroke != null )
176184 {
177185 MainInkCanvas . Strokes . Remove ( _lastStroke ) ;
178186 }
0 commit comments