Files
StructureHelper/StructureHelperCommon/Models/Shapes/Logics/LinePolygonShapeUpdateStrategy.cs
2025-10-19 17:37:17 +05:00

47 lines
1.5 KiB
C#

using StructureHelperCommon.Infrastructures.Interfaces;
using StructureHelperCommon.Models.Shapes.Logics;
using StructureHelperCommon.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Shapes;
namespace StructureHelperCommon.Models.Shapes
{
public class LinePolygonShapeUpdateStrategy : IParentUpdateStrategy<ILinePolygonShape>
{
public bool UpdateChildren { get; set; } = true;
public void Update(ILinePolygonShape targetObject, ILinePolygonShape sourceObject)
{
CheckObject.IsNull(targetObject, sourceObject);
if (ReferenceEquals(targetObject, sourceObject)) { return; }
// Update simple properties
targetObject.IsClosed = sourceObject.IsClosed;
if (UpdateChildren == true)
{
// Replace vertices
targetObject.Clear();
foreach (var vertex in sourceObject.Vertices)
{
// Copy the underlying point into a new vertex
Vertex newVertex = GetVertexClone(vertex);
targetObject.AddVertex(newVertex);
}
}
}
private static Vertex GetVertexClone(IVertex vertex)
{
var updateStrategy = new VertexUpdateStrategy();
Vertex newVertex = new(Guid.NewGuid());
updateStrategy.Update(newVertex, vertex);
return newVertex;
}
}
}