using LoaderCalculator.Data.Materials;
using LoaderCalculator.Data.Ndms;
using StructureHelper.Models.Materials;
using StructureHelperCommon.Models.Forces;
using StructureHelperCommon.Models.Parameters;
using StructureHelperCommon.Models.Shapes;
using StructureHelperLogics.Models.CrossSections;
using StructureHelperLogics.NdmCalculations.Triangulations;
namespace StructureHelperLogics.NdmCalculations.Primitives
{
public class EllipseNdmPrimitive : IEllipseNdmPrimitive
{
private static readonly EllipsePrimitiveUpdateStrategy updateStrategy = new();
private readonly RectangleShape rectangleShape = new();
///
public Guid Id { get; set; }
///
public string Name { get; set; }
///
public IPoint2D Center { get; set; } = new Point2D();
///
public IVisualProperty VisualProperty { get; } = new VisualProperty { Opacity = 0.8d };
///
public double Width
{
get
{
return rectangleShape.Width;
}
set
{
rectangleShape.Width = value;
rectangleShape.Height = value;
}
}
///
public double Height { get => rectangleShape.Height; set => rectangleShape.Height = value; }
///
public ICrossSection? CrossSection { get; set; }
///
public INdmElement NdmElement { get; } = new NdmElement();
///
public IDivisionSize DivisionSize { get; } = new DivisionSize(Guid.NewGuid());
///
public IShape Shape => rectangleShape;
///
public double RotationAngle { get; set; }
public EllipseNdmPrimitive(Guid id)
{
Id = id;
Name = "New Circle";
}
public EllipseNdmPrimitive() : this (Guid.NewGuid()) {}
///
public object Clone()
{
var primitive = new EllipseNdmPrimitive();
updateStrategy.Update(primitive, this);
return primitive;
}
///
public IEnumerable GetNdms(ITriangulationOptions triangulationOptions)
{
var ndms = new List();
var options = new CircleTriangulationLogicOptions(this)
{
triangulationOptions = triangulationOptions
};
var logic = new CircleTriangulationLogic(options);
ndms.AddRange(logic.GetNdmCollection());
return ndms;
}
///
public bool IsPointInside(IPoint2D point)
{
var dX = Center.X - point.X;
var dY = Center.Y - point.Y;
var distance = Math.Sqrt(dX * dX + dY * dY);
if (distance > Width / 2) { return false; }
return true;
}
List INdmPrimitive.GetValuePoints()
{
var points = new List();
INamedAreaPoint newPoint;
newPoint = new NamedAreaPoint
{
Name = "Center",
Point = Center.Clone() as Point2D,
Area = 0d
};
points.Add(newPoint);
newPoint = new NamedAreaPoint
{
Name = "Left",
Point = new Point2D() { X = Center.X - Width / 2d, Y = Center.Y},
Area = 0d
};
points.Add(newPoint);
newPoint = new NamedAreaPoint
{
Name = "Top",
Point = new Point2D() { X = Center.X, Y = Center.Y + Width / 2d },
Area = 0d
};
points.Add(newPoint);
newPoint = new NamedAreaPoint
{
Name = "Right",
Point = new Point2D() { X = Center.X + Width / 2d, Y = Center.Y },
Area = 0d
};
points.Add(newPoint);
newPoint = new NamedAreaPoint
{
Name = "Bottom",
Point = new Point2D() { X = Center.X, Y = Center.Y - Width / 2d },
Area = 0d
};
points.Add(newPoint);
return points;
}
}
}