using System.Diagnostics.CodeAnalysis; namespace Hast.Samples.Kpz.Algorithms { /// /// This struct is used to built the grid that the KPZ algorithm works on. /// Every node on the grid stores the derivatives of a 2D function in X and Y direction. /// public class KpzNode { public bool Dx; // Right public bool Dy; // Bottom public uint SerializeToUInt32() => ((Dx) ? 1U : 0) | ((Dy) ? 2U : 0); public static KpzNode DeserializeFromUInt32(uint value) { var node = new KpzNode { Dx = (value & 1) != 0, Dy = (value & 2) != 0 }; return node; } } /// /// This struct stores the right and bottom neighbours of a particular node on the grid. /// It stores both their values and coordinates. /// [SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "The type's never checked for equality.")] public struct KpzNeighbours { public KpzNode Nx; // Right neighbour value public KpzNode Ny; // Left neighbour value public KpzCoords NxCoords; // Right neighbour coordinates public KpzCoords NyCoords; // Left neighbour coordinates } /// /// This struct stores the coordinates of a on the grid. /// [SuppressMessage("Performance", "CA1815:Override equals and operator equals on value types", Justification = "The type's never checked for equality.")] public struct KpzCoords { public int X; public int Y; } }