Add polygon to DTO convert strategy

This commit is contained in:
Evgeny Redikultsev
2025-10-19 17:37:17 +05:00
parent 5bf01bcb09
commit ed66da123c
64 changed files with 759 additions and 266 deletions

View File

@@ -0,0 +1,46 @@
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;
}
}
}