Refactored PointsToPath method

This commit is contained in:
Wiesław Šoltés 2015-08-01 12:58:23 +02:00
Родитель 62006b5669
Коммит 5dcc2d577f
2 изменённых файлов: 11 добавлений и 11 удалений

Просмотреть файл

@ -111,7 +111,7 @@ namespace SpiroNet.Wpf
NewShape();
NewPoint(e.GetPosition(canvas));
SpiroShape.PointsToPath(_shape);
_shape.UpdateSource();
canvas.InvalidateVisual();
}
@ -119,7 +119,7 @@ namespace SpiroNet.Wpf
{
if (_shape != null)
{
SpiroShape.PointsToPath(_shape);
_shape.UpdateSource();
canvas.InvalidateVisual();
_shape = null;
}
@ -130,7 +130,7 @@ namespace SpiroNet.Wpf
if (_shape != null && _shape.Points.Count > 1)
{
UpdateLastPoint(e.GetPosition(canvas));
SpiroShape.PointsToPath(_shape);
_shape.UpdateSource();
canvas.InvalidateVisual();
}
}

Просмотреть файл

@ -33,30 +33,30 @@ namespace SpiroNet.Wpf
public bool IsTagged { get; set; }
public string Source { get; set; }
public static bool PointsToPath(SpiroShape shape)
public bool UpdateSource()
{
var points = shape.Points.ToArray();
var points = this.Points.ToArray();
var bc = new PathBezierContext();
try
{
if (shape.IsTagged)
if (this.IsTagged)
{
var success = Spiro.TaggedSpiroCPsToBezier(points, bc);
if (success)
shape.Source = bc.ToString();
this.Source = bc.ToString();
else
shape.Source = string.Empty;
this.Source = string.Empty;
return success;
}
else
{
var success = Spiro.SpiroCPsToBezier(points, points.Length, shape.IsClosed, bc);
var success = Spiro.SpiroCPsToBezier(points, points.Length, this.IsClosed, bc);
if (success)
shape.Source = bc.ToString();
this.Source = bc.ToString();
else
shape.Source = string.Empty;
this.Source = string.Empty;
return success;
}