Add polygon shape

This commit is contained in:
Evgeny Redikultsev
2025-09-14 19:47:23 +05:00
parent c31e56869c
commit 35fccfaa11
56 changed files with 867 additions and 113 deletions

View File

@@ -9,6 +9,18 @@ namespace StructureHelperCommon.Models.Shapes
{
public static class PolygonGeometryUtils
{
public static IPolygonShape GetTratsfromedPolygon(IPolygonShape polygon, double dx, double dy)
{
IPolygonShape newPolygon = new PolygonShape(Guid.Empty);
var updateLogic = new PolygonShapeUpdateStrategy();
updateLogic.Update(newPolygon, polygon);
foreach (var item in newPolygon.Vertices)
{
item.Point.X += dx;
item.Point.Y += dy;
}
return newPolygon;
}
public static bool DoPolygonsEdgesIntersect(IPolygonShape polygon)
{
var vertices = polygon.Vertices;

View File

@@ -9,7 +9,7 @@ using System.Windows.Shapes;
namespace StructureHelperCommon.Models.Shapes
{
public class PolygonUpdateStrategy : IUpdateStrategy<IPolygonShape>
public class PolygonShapeUpdateStrategy : IUpdateStrategy<IPolygonShape>
{
public void Update(IPolygonShape targetObject, IPolygonShape sourceObject)
{

View File

@@ -7,7 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Models.Shapes.Logics
namespace StructureHelperCommon.Models.Shapes
{
public class ShapeUpdateStrategy : IUpdateStrategy<IShape>
{
@@ -24,12 +24,29 @@ namespace StructureHelperCommon.Models.Shapes.Logics
{
ProcessCircles(targetObject, sourceCircle);
}
else if (sourceObject is IPolygonShape sourcePolygon)
{
ProcessPolygon(targetObject, sourcePolygon);
}
else
{
throw new StructureHelperException(ErrorStrings.ObjectTypeIsUnknown);
}
}
private void ProcessPolygon(IShape targetObject, IPolygonShape sourcePolygon)
{
if (targetObject is IPolygonShape targetPolygon)
{
var updateLogic = new PolygonShapeUpdateStrategy();
updateLogic.Update(targetPolygon, sourcePolygon);
}
else
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": target object is not a polygon");
}
}
private static void ProcessCircles(IShape targetObject, ICircleShape sourceCircle)
{
if (targetObject is ICircleShape targetCircle)

View File

@@ -10,7 +10,7 @@ namespace StructureHelperCommon.Models.Shapes
public Guid Id { get; }
public IReadOnlyList<IVertex> Vertices => _vertices;
public bool IsClosed { get; set; }
public bool IsClosed { get; set; } = true;
public PolygonShape(Guid id)
{
@@ -62,7 +62,6 @@ namespace StructureHelperCommon.Models.Shapes
{
throw new StructureHelperException("The specified vertex was not found in the polygon.");
}
return index;
}

View File

@@ -11,8 +11,17 @@ namespace StructureHelperCommon.Models.Shapes
{
Id = id;
}
/// <summary>
/// Creates new vertex with id = new Guid
/// </summary>
/// <param name="x">Coordinate x of vertex</param>
/// <param name="y">Coordinate y of vertex</param>
public Vertex(double x, double y) : this(Guid.NewGuid())
{
Point = new Point2D() { X = x, Y = y };
}
public IPoint2D Point { get; set; }
public IPoint2D Point { get; set; } = new Point2D(Guid.NewGuid()) { X = 0, Y = 0};
}