Skip to content

Commit

Permalink
Merge pull request #103 from mohammadKarimi/102-modified-code-to-use-…
Browse files Browse the repository at this point in the history
…click-point-as-the-circles-outer-edge

Modified Code to Use Click Point as the Circle's Outer Edge
  • Loading branch information
mohammadKarimi authored Nov 6, 2024
2 parents f19d458 + 13ef9a8 commit 5dbbbb7
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Riter/Core/UI/MainInkCanvasControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,33 +146,41 @@ private void DrawLine(object sender, MouseEventArgs e)

private void DrawCircle(object sender, MouseEventArgs e)
{
if (_isMoving is false)
if (!_isMoving)
{
return;
}

var currentPoint = e.GetPosition(MainInkCanvas);
var radius = Math.Abs(currentPoint.X - _startPoint.X);
var points = new List<Point>();

// Calculate the center of the circle
var centerX = (_startPoint.X + currentPoint.X) / 2;
var centerY = (_startPoint.Y + currentPoint.Y) / 2;
var center = new Point(centerX, centerY);

var radius = Math.Sqrt(Math.Pow(currentPoint.X - centerX, 2) + Math.Pow(currentPoint.Y - centerY, 2));

var points = new List<Point>();
var segments = 100;
for (var i = 0; i <= segments; i++)
{
var angle = 2 * Math.PI * i / segments;
var x = _startPoint.X + (radius * Math.Cos(angle));
var y = _startPoint.Y + (radius * Math.Sin(angle));
var x = center.X + (radius * Math.Cos(angle));
var y = center.Y + (radius * Math.Sin(angle));
points.Add(new Point(x, y));
}

var stylusPoints = new StylusPointCollection(points);
var newAttributes = MainInkCanvas.DefaultDrawingAttributes.Clone();
newAttributes.StylusTip = StylusTip.Ellipse;
newAttributes.IgnorePressure = true;

var stroke = new Stroke(stylusPoints)
{
DrawingAttributes = newAttributes,
};
if (_lastStroke is not null)

if (_lastStroke != null)
{
MainInkCanvas.Strokes.Remove(_lastStroke);
}
Expand Down

0 comments on commit 5dbbbb7

Please sign in to comment.