2DLightPathSimulator/LensSimulatorCore/Optical/Element.cs

66 lines
1.8 KiB
C#

using LensSimulatorCore.Shapes;
namespace LensSimulatorCore.Optical;
/// <summary>
/// An Element contains two surfaces and material coefficients.
/// </summary>
public class Element
{
//This section is for display and rendering
public List<Point> Polygon { get; set; }
//This section is for calculation
private Material _material;
private readonly Surface[] _surfaces = new Surface[2];
public Surface[] Surfaces => _surfaces;
public Point Position { get; set; }
public bool IsValid => !(Polygon[(Polygon.Count / 2) - 1].X > Polygon[(Polygon.Count / 2)].X);
public double Depth { get; }
public double Diameter { get; }
public Element(Material material)
{
}
/// <summary>
///
/// </summary>
/// <param name="position">Element Position</param>
/// <param name="depth">Total Element depth at the centre.</param>
/// <param name="diameter">Diameter of the lens</param>
/// <param name="frontSurface"></param>
/// <param name="rearSurface"></param>
/// <param name="material"></param>
public Element(Point position, double depth, double diameter, Surface frontSurface, Surface rearSurface, Material material)
{
Polygon = new List<Point>();
Surfaces[0] = frontSurface;
Surfaces[0].Parent = this;
Surfaces[0].IsFront = true;
Surfaces[1] = rearSurface;
Surfaces[1].Parent = this;
Surfaces[1].IsFront = false;
Depth = depth;
Diameter = diameter;
_material = material;
Position = position;
foreach (var surface in Surfaces)
{
surface.UpdateSurfacePositions();
surface.GeneratePolyLine();
Polygon.AddRange(surface.PolyLine);
}
}
}