diff --git a/Atomorph.NET.Demo/Program.cs b/Atomorph.NET.Demo/Program.cs index 676a0b0..a4cd7dd 100644 --- a/Atomorph.NET.Demo/Program.cs +++ b/Atomorph.NET.Demo/Program.cs @@ -122,7 +122,7 @@ public static class Program morph.AddPixel(frame, new Pixel() { - X = (ushort)(x), Y = (ushort)(y), Color = new Color(r, g, b, a), + X = (ushort)(x), Y = (ushort)(y), Color = new AtomorphColor(r, g, b, a), }); pixel++; empty = false; diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0001.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0001.png deleted file mode 100644 index ce04ee5..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0001.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0002.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0002.png deleted file mode 100644 index 4642a89..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0002.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0003.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0003.png deleted file mode 100644 index 959330f..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0003.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0004.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0004.png deleted file mode 100644 index 1999660..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0004.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0005.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0005.png deleted file mode 100644 index b1a6150..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0005.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0006.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0006.png deleted file mode 100644 index 3cb497b..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0006.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0007.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0007.png deleted file mode 100644 index fa065f1..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0007.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0008.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0008.png deleted file mode 100644 index aefe2ff..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0008.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0009.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0009.png deleted file mode 100644 index 8861056..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0009.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0010.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0010.png deleted file mode 100644 index 1de7d39..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0010.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0011.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0011.png deleted file mode 100644 index a5f1edc..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0011.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0012.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0012.png deleted file mode 100644 index 27b794f..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0012.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0013.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0013.png deleted file mode 100644 index 949629c..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0013.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0014.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0014.png deleted file mode 100644 index 2921660..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0014.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0015.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0015.png deleted file mode 100644 index 7da29d2..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0015.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0016.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0016.png deleted file mode 100644 index 8049662..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0016.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0017.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0017.png deleted file mode 100644 index f60fbe2..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0017.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0018.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0018.png deleted file mode 100644 index bfe861e..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0018.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0019.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0019.png deleted file mode 100644 index e161d26..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0019.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0020.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0020.png deleted file mode 100644 index d1ff017..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0020.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0021.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0021.png deleted file mode 100644 index 9369c83..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0021.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0022.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0022.png deleted file mode 100644 index 18f1408..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0022.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0023.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0023.png deleted file mode 100644 index da50eb4..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0023.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0024.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0024.png deleted file mode 100644 index e093a1e..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0024.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0025.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0025.png deleted file mode 100644 index ff0aca5..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0025.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0026.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0026.png deleted file mode 100644 index e77516d..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0026.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0027.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0027.png deleted file mode 100644 index c517711..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0027.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0028.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0028.png deleted file mode 100644 index 8c79e84..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0028.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0029.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0029.png deleted file mode 100644 index f8d0bd4..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0029.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0030.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0030.png deleted file mode 100644 index af036e8..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0030.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0031.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0031.png deleted file mode 100644 index db0e479..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0031.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0032.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0032.png deleted file mode 100644 index 8de5aad..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0032.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0033.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0033.png deleted file mode 100644 index ac056e3..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0033.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0034.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0034.png deleted file mode 100644 index 23e449e..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0034.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0035.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0035.png deleted file mode 100644 index 92285fe..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0035.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0036.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0036.png deleted file mode 100644 index 55ec121..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0036.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0037.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0037.png deleted file mode 100644 index ecdb92b..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0037.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0038.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0038.png deleted file mode 100644 index a2c6f3a..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0038.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0039.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0039.png deleted file mode 100644 index 1b7d033..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0039.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0040.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0040.png deleted file mode 100644 index fc19dae..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0040.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0041.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0041.png deleted file mode 100644 index 2322ec5..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0041.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0042.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0042.png deleted file mode 100644 index 39521d6..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0042.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0043.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0043.png deleted file mode 100644 index 5c01583..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0043.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0044.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0044.png deleted file mode 100644 index 35adcf0..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0044.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0045.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0045.png deleted file mode 100644 index 2a140f9..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0045.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0046.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0046.png deleted file mode 100644 index 5559cfd..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0046.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0047.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0047.png deleted file mode 100644 index 1bf0607..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0047.png and /dev/null differ diff --git a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0048.png b/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0048.png deleted file mode 100644 index 0e91f0e..0000000 Binary files a/Atomorph.NET.Demo/Tests/output/test_${TITLE}_0048.png and /dev/null differ diff --git a/Atomorph.NET/AtomorphThread.cs b/Atomorph.NET/AtomorphThread.cs index 8b64292..42a0d58 100644 --- a/Atomorph.NET/AtomorphThread.cs +++ b/Atomorph.NET/AtomorphThread.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; using Atomorph.Models; +using Atomorph.Utilities; using Pcg; namespace Atomorph; @@ -87,10 +83,10 @@ public class AtomorphThread : IDisposable } - public Frame? GetFrame(ulong nr) => _frames.GetValueOrDefault(nr); - public IReadOnlyDictionary Chains => _chains; + internal Frame? GetFrame(ulong nr) => _frames.GetValueOrDefault(nr); + internal IReadOnlyDictionary Chains => _chains; - public void SetFrame(ulong nr, Frame framePt) + internal void SetFrame(ulong nr, Frame framePt) { if (_running && !_paused) return; @@ -333,15 +329,15 @@ public class AtomorphThread : IDisposable { var p1 = new Pixel() { - X = (ushort)b1.X, Y = (ushort)b1.Y, Color = ColorUtilities.CreateColor(b1.R, b1.G, b1.B, b1.A), + X = (ushort)b1.X, Y = (ushort)b1.Y, Color = AtomorphColorUtilities.CreateColor(b1.R, b1.G, b1.B, b1.A), }; var p2 = new Pixel() { - X = (ushort)b2.X, Y = (ushort)b2.Y, Color = ColorUtilities.CreateColor(b2.R, b2.G, b2.B, b2.A), + X = (ushort)b2.X, Y = (ushort)b2.Y, Color = AtomorphColorUtilities.CreateColor(b2.R, b2.G, b2.B, b2.A), }; pix_dist = Math.Sqrt((double)(AtomorphUtilities.PixelDistance(p1, p2)) / _bBoxD); - col_dist = ColorUtilities.ColorDistance(p1.Color, p2.Color); + col_dist = AtomorphColorUtilities.ColorDistance(p1.Color, p2.Color); } return (_blobXyWeight * pix_dist + _blobRgbaWeight * col_dist + _blobSizeWeight * siz_dist); @@ -747,9 +743,9 @@ public class AtomorphThread : IDisposable if (owner != bl) { double dist; - var c1 = ColorUtilities.CreateColor(owner.R, owner.G, owner.B, owner.A); - var c2 = ColorUtilities.CreateColor(bl.R, bl.G, bl.B, bl.A); - dist = ColorUtilities.ColorDistance(c1, c2); + var c1 = AtomorphColorUtilities.CreateColor(owner.R, owner.G, owner.B, owner.A); + var c2 = AtomorphColorUtilities.CreateColor(bl.R, bl.G, bl.B, bl.A); + dist = AtomorphColorUtilities.ColorDistance(c1, c2); if ((dist <= _blobThreshold || !checkThreshold) && (!bestFound || dist <= bestDist)) { @@ -1304,7 +1300,7 @@ public class AtomorphThread : IDisposable var p1 = GetPixel(frame, fromPos); var p2 = GetPixel(frame, toPos); - return ColorUtilities.ColorDistance(p1.Color, p2.Color) <= _blobThreshold; + return AtomorphColorUtilities.ColorDistance(p1.Color, p2.Color) <= _blobThreshold; } private void Run() diff --git a/Atomorph.NET/AtomorphUtilities.cs b/Atomorph.NET/AtomorphUtilities.cs index 8359123..95a2d4d 100644 --- a/Atomorph.NET/AtomorphUtilities.cs +++ b/Atomorph.NET/AtomorphUtilities.cs @@ -1,22 +1,21 @@ -using System; using System.Runtime.CompilerServices; using Atomorph.GLNemo; using Atomorph.Models; namespace Atomorph; -public static class AtomorphUtilities +internal static class AtomorphUtilities { - public static ulong XY2Pos(ushort x, ushort y) => (ulong)(y * (ushort.MaxValue + 1) + x); + internal static ulong XY2Pos(ushort x, ushort y) => (ulong)(y * (ushort.MaxValue + 1) + x); - public static void Point2XY(Point pt, out float x, out float y) + internal static void Point2XY(Point pt, out float x, out float y) { x = pt.X + pt.XFract/(float)(byte.MaxValue+1); y = pt.Y + pt.YFract/(float)(byte.MaxValue+1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong PointDistance(Point p1, Point p2) + internal static ulong PointDistance(Point p1, Point p2) { var xd = (ulong)Math.Abs(((byte.MaxValue+1)*p1.X+p1.XFract) - ((byte.MaxValue+1)*p2.X+p2.XFract)); var yd = (ulong)Math.Abs(((byte.MaxValue+1)*p1.Y+p1.YFract) - ((byte.MaxValue+1)*p2.Y+p2.YFract)); @@ -24,7 +23,7 @@ public static class AtomorphUtilities return (xd*xd + yd*yd); } - public static ulong PixelDistance(Pixel p1, Pixel p2) + internal static ulong PixelDistance(Pixel p1, Pixel p2) { var xd = p1.X-p2.X; var yd = p1.Y-p2.Y; @@ -33,13 +32,13 @@ public static class AtomorphUtilities } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool PointHasPixel(this Point p) => p.Flags.HasFlag(PointFlags.HasPixel); + internal static bool PointHasPixel(this Point p) => p.Flags.HasFlag(PointFlags.HasPixel); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool PointHasFluid(this Point p) => p.Flags.HasFlag(PointFlags.HasFluid); + internal static bool PointHasFluid(this Point p) => p.Flags.HasFlag(PointFlags.HasFluid); - public static bool ClearChain(Chain c) + internal static bool ClearChain(Chain c) { c.Points = null; c.Places = null; @@ -54,7 +53,7 @@ public static class AtomorphUtilities return true; } - public static bool RenewChain(Chain c, ulong width, ulong height) + internal static bool RenewChain(Chain c, ulong width, ulong height) { ClearChain(c); c.Points = new Point[width][]; diff --git a/Atomorph.NET/FluidModel/FluidModel.cs b/Atomorph.NET/FluidModel/FluidModel.cs index 2242190..dd74d89 100644 --- a/Atomorph.NET/FluidModel/FluidModel.cs +++ b/Atomorph.NET/FluidModel/FluidModel.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using Pcg; namespace Atomorph.FluidModel; diff --git a/Atomorph.NET/FluidModel/Node.cs b/Atomorph.NET/FluidModel/Node.cs index 69652d8..cf392e6 100644 --- a/Atomorph.NET/FluidModel/Node.cs +++ b/Atomorph.NET/FluidModel/Node.cs @@ -1,5 +1,3 @@ -using Atomorph.Models; - namespace Atomorph.FluidModel; internal class Node diff --git a/Atomorph.NET/FluidModel/Particle.cs b/Atomorph.NET/FluidModel/Particle.cs index 369519e..95b2f60 100644 --- a/Atomorph.NET/FluidModel/Particle.cs +++ b/Atomorph.NET/FluidModel/Particle.cs @@ -1,5 +1,3 @@ -using Atomorph.Models; - namespace Atomorph.FluidModel; internal class Particle diff --git a/Atomorph.NET/GLNemo/Spline.cs b/Atomorph.NET/GLNemo/Spline.cs index 8d6b380..74a7f1b 100644 --- a/Atomorph.NET/GLNemo/Spline.cs +++ b/Atomorph.NET/GLNemo/Spline.cs @@ -1,8 +1,6 @@ -using System.Collections.Generic; - namespace Atomorph.GLNemo; -public class Spline +internal class Spline { private List _vp = []; private double _deltaT; diff --git a/Atomorph.NET/GLNemo/Vec3D.cs b/Atomorph.NET/GLNemo/Vec3D.cs index 325f461..af091ff 100644 --- a/Atomorph.NET/GLNemo/Vec3D.cs +++ b/Atomorph.NET/GLNemo/Vec3D.cs @@ -1,9 +1,8 @@ -using System; using System.Runtime.CompilerServices; namespace Atomorph.GLNemo; -public record struct Vec3D +internal record struct Vec3D { public Vec3D(double x, double y, double z) { diff --git a/Atomorph.NET/Models/Color.cs b/Atomorph.NET/Models/AtomorphColor.cs similarity index 85% rename from Atomorph.NET/Models/Color.cs rename to Atomorph.NET/Models/AtomorphColor.cs index c02b594..6c41abe 100644 --- a/Atomorph.NET/Models/Color.cs +++ b/Atomorph.NET/Models/AtomorphColor.cs @@ -1,14 +1,12 @@ -using System; - namespace Atomorph.Models; -public readonly record struct Color +public readonly record struct AtomorphColor { - public Color() + public AtomorphColor() { } - public Color(byte r, byte g, byte b, byte a) + public AtomorphColor(byte r, byte g, byte b, byte a) { R = r; G = g; @@ -22,9 +20,9 @@ public readonly record struct Color public byte A { get; } } -public static class ColorUtilities +public static class AtomorphColorUtilities { - public static double ColorDistance(Color c1, Color c2) + public static double ColorDistance(AtomorphColor c1, AtomorphColor c2) { var rd = c1.R - c2.R; var gd = c1.G - c2.G; @@ -34,25 +32,25 @@ public static class ColorUtilities return Math.Sqrt(rd * rd + gd * gd + bd * bd + ad * ad) / 510.0; } - public static Color CreateColor(double r, double g, double b, double a) + public static AtomorphColor CreateColor(double r, double g, double b, double a) { - return new Color((byte)Math.Round(r * 255.0), (byte)Math.Round(g * 255.0), (byte)Math.Round(b * 255.0), + return new AtomorphColor((byte)Math.Round(r * 255.0), (byte)Math.Round(g * 255.0), (byte)Math.Round(b * 255.0), (byte)Math.Round(a * 255.0)); } - public static Color RgbToHsp(Color color) + public static AtomorphColor RgbToHsp(AtomorphColor atomorphColor) { - RGBToHSP(color.R / 255.0, color.G / 255.0, color.B / 255.0, out var h, out var s, out var p); - return CreateColor(h, s, p, color.A / 255.0); + RGBToHSP(atomorphColor.R / 255.0, atomorphColor.G / 255.0, atomorphColor.B / 255.0, out var h, out var s, out var p); + return CreateColor(h, s, p, atomorphColor.A / 255.0); } - public static Color HspToRgb(Color color) + public static AtomorphColor HspToRgb(AtomorphColor atomorphColor) { - HSPtoRGB(color.R / 255.0, color.G / 255.0, color.B / 255.0, out var r, out var g, out var b); - return new Color((byte)Math.Min(Math.Round(r * 255.0), 255), + HSPtoRGB(atomorphColor.R / 255.0, atomorphColor.G / 255.0, atomorphColor.B / 255.0, out var r, out var g, out var b); + return new AtomorphColor((byte)Math.Min(Math.Round(r * 255.0), 255), (byte)Math.Min(Math.Round(g * 255.0), 255), (byte)Math.Min(Math.Round(b * 255.0), 255), - color.A); + atomorphColor.A); } private const double Pr = 0.299; diff --git a/Atomorph.NET/Models/Blob.cs b/Atomorph.NET/Models/Blob.cs index a4d96ed..8a15525 100644 --- a/Atomorph.NET/Models/Blob.cs +++ b/Atomorph.NET/Models/Blob.cs @@ -1,8 +1,6 @@ -using System.Collections.Generic; - namespace Atomorph.Models; -public class Blob +internal class Blob { /// /// Position in the nest vector diff --git a/Atomorph.NET/Models/Chain.cs b/Atomorph.NET/Models/Chain.cs index 8a4a10b..4a6e81f 100644 --- a/Atomorph.NET/Models/Chain.cs +++ b/Atomorph.NET/Models/Chain.cs @@ -1,10 +1,8 @@ -using System; -using System.Drawing; using Atomorph.GLNemo; namespace Atomorph.Models; -public class Chain +internal class Chain { public ulong Width { get; set; } public ulong Height { get; set; } diff --git a/Atomorph.NET/Models/Frame.cs b/Atomorph.NET/Models/Frame.cs index 8052cb4..e3c7df7 100644 --- a/Atomorph.NET/Models/Frame.cs +++ b/Atomorph.NET/Models/Frame.cs @@ -1,8 +1,6 @@ -using System.Collections.Generic; - namespace Atomorph.Models; -public class Frame +internal class Frame { public List Blobs { get; init; } = []; diff --git a/Atomorph.NET/Models/Pixel.cs b/Atomorph.NET/Models/Pixel.cs index d861ffb..6864038 100644 --- a/Atomorph.NET/Models/Pixel.cs +++ b/Atomorph.NET/Models/Pixel.cs @@ -5,6 +5,6 @@ public record struct Pixel public ushort X { get; set; } public ushort Y { get; set; } - public Color Color { get; set; } + public AtomorphColor Color { get; set; } } diff --git a/Atomorph.NET/Models/Point.cs b/Atomorph.NET/Models/Point.cs index 6649b62..dfcefcc 100644 --- a/Atomorph.NET/Models/Point.cs +++ b/Atomorph.NET/Models/Point.cs @@ -2,7 +2,7 @@ using System.Runtime.CompilerServices; namespace Atomorph.Models; -public record struct Point +internal record struct Point { // typedef union key_point { // struct { diff --git a/Atomorph.NET/Morph.cs b/Atomorph.NET/Morph.cs index c2bdc62..0eb90ca 100644 --- a/Atomorph.NET/Morph.cs +++ b/Atomorph.NET/Morph.cs @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; using Atomorph.FluidModel; using Atomorph.GLNemo; using Atomorph.Models; using Atomorph.Perlin; +using Atomorph.Utilities; using Pcg; namespace Atomorph; @@ -88,7 +85,7 @@ public class Morph : IDisposable { if (BlobDelimiter == ColorMethod.HSP) { - px.Color = ColorUtilities.RgbToHsp(px.Color); + px.Color = AtomorphColorUtilities.RgbToHsp(px.Color); } AddFrame(frame_key); @@ -195,11 +192,11 @@ public class Morph : IDisposable var g = Math.Round(255.0 * _frames[f].G); var b = Math.Round(255.0 * _frames[f].B); var a = Math.Round(255.0 * _frames[f].A); - var color = new Color((byte)r, (byte)g, (byte)b, (byte)a); + var color = new AtomorphColor((byte)r, (byte)g, (byte)b, (byte)a); if (BlobDelimiter == ColorMethod.RGB) { - color = ColorUtilities.RgbToHsp(color); + color = AtomorphColorUtilities.RgbToHsp(color); } return new Pixel { X = (ushort)x, Y = (ushort)y, Color = color, }; @@ -220,10 +217,10 @@ public class Morph : IDisposable var b = Math.Round(255.0 * blob.B); var a = Math.Round(255.0 * blob.A); - var color = new Color((byte)r, (byte)g, (byte)b, (byte)a); + var color = new AtomorphColor((byte)r, (byte)g, (byte)b, (byte)a); if (BlobDelimiter == ColorMethod.HSP) { - color = ColorUtilities.RgbToHsp(color); + color = AtomorphColorUtilities.RgbToHsp(color); } return new Pixel { X = (ushort)x, Y = (ushort)y, Color = color, }; @@ -234,13 +231,13 @@ public class Morph : IDisposable if (!HasPixel(f, pos)) return new Pixel(); var px = _frames[f].Pixels[pos]; if (BlobDelimiter == ColorMethod.HSP) - px.Color = ColorUtilities.HspToRgb(px.Color); + px.Color = AtomorphColorUtilities.HspToRgb(px.Color); return px; } - public Color GetBackground(ushort x, ushort y, double time) + public AtomorphColor GetBackground(ushort x, ushort y, double time) { - if (!_frames.Any()) return ColorUtilities.CreateColor(0.0, 0.0, 0.0, 0.0); + if (!_frames.Any()) return AtomorphColorUtilities.CreateColor(0.0, 0.0, 0.0, 0.0); ulong position = AtomorphUtilities.XY2Pos(x, y); time = NormalizeTime(time); @@ -275,7 +272,7 @@ public class Morph : IDisposable return Interpolate(c1, c2, 1.0 - t); } - public Point Interpolate(Point pt1, Point pt2, double pt1Weight) + internal Point Interpolate(Point pt1, Point pt2, double pt1Weight) { Point pt = new(); @@ -300,7 +297,7 @@ public class Morph : IDisposable { X = (ushort)Math.Round(px1Weight * px1.X + (1.0 - px1Weight) * px2.X), Y = (ushort)Math.Round(px1Weight * px1.Y + (1.0 - px1Weight) * px2.Y), - Color = new Color((byte)Math.Round(px1Weight * px1.Color.R + (1.0 - px1Weight) * px2.Color.R), + Color = new AtomorphColor((byte)Math.Round(px1Weight * px1.Color.R + (1.0 - px1Weight) * px2.Color.R), (byte)Math.Round(px1Weight * px1.Color.G + (1.0 - px1Weight) * px2.Color.G), (byte)Math.Round(px1Weight * px1.Color.B + (1.0 - px1Weight) * px2.Color.B), (byte)Math.Round(px1Weight * px1.Color.A + (1.0 - px1Weight) * px2.Color.A)), @@ -308,16 +305,16 @@ public class Morph : IDisposable return px; } - public Color Interpolate(Color c1, Color c2, double c1Weight) + public AtomorphColor Interpolate(AtomorphColor c1, AtomorphColor c2, double c1Weight) { - Color c = new((byte)Math.Round(c1Weight * c1.R + (1.0 - c1Weight) * c2.R), + AtomorphColor c = new((byte)Math.Round(c1Weight * c1.R + (1.0 - c1Weight) * c2.R), (byte)Math.Round(c1Weight * c1.G + (1.0 - c1Weight) * c2.G), (byte)Math.Round(c1Weight * c1.B + (1.0 - c1Weight) * c2.B), (byte)Math.Round(c1Weight * c1.A + (1.0 - c1Weight) * c2.A)); return c; } - public Color Interpolate(Color c1, Color c2, double lag, double slope, double str) + public AtomorphColor Interpolate(AtomorphColor c1, AtomorphColor c2, double lag, double slope, double str) { if (Fading is InterpolationMethod.Cosine or InterpolationMethod.Perlin) { const double pi = 3.14159265358; @@ -332,7 +329,7 @@ public class Morph : IDisposable return Interpolate(c1, c2, str); } - public Blob? GetPixels(ulong blob_index, double time, out List? to) + internal Blob? GetPixels(ulong blob_index, double time, out List? to) { time = NormalizeTime(time); double t = time; @@ -361,7 +358,7 @@ public class Morph : IDisposable } else { - Dictionary> colors = new(); + Dictionary> colors = new(); Dictionary> weights = new(); if (!_chains.ContainsKey(bl.Group)) @@ -391,7 +388,7 @@ public class Morph : IDisposable px2 = px1; px2.X = pt2.X; px2.Y = pt2.Y; - px2.Color = new Color(px2.Color.R, px2.Color.G, px2.Color.B, 0); + px2.Color = new AtomorphColor(px2.Color.R, px2.Color.G, px2.Color.B, 0); } else if (pt2.PointHasPixel() && !pt1.PointHasPixel()) { @@ -399,7 +396,7 @@ public class Morph : IDisposable px1 = px2; px1.X = pt1.X; px1.Y = pt1.Y; - px1.Color = new Color(px1.Color.R, px1.Color.G, px1.Color.B, 0); + px1.Color = new AtomorphColor(px1.Color.R, px1.Color.G, px1.Color.B, 0); } else { @@ -519,7 +516,7 @@ public class Morph : IDisposable var px = new Pixel { - X = (ushort)x, Y = (ushort)y, Color = new Color((byte)r, (byte)g, (byte)b, (byte)a) + X = (ushort)x, Y = (ushort)y, Color = new AtomorphColor((byte)r, (byte)g, (byte)b, (byte)a) }; if (Feather > 0) blob[pos] = px; @@ -570,7 +567,7 @@ public class Morph : IDisposable { var px = blob[lt]; var a = Math.Round((double)(px.Color.A) * ((double)(l + 1) / (double)(Feather + 1))); - px.Color = new Color(px.Color.R, px.Color.G, px.Color.B, (byte)a); + px.Color = new AtomorphColor(px.Color.R, px.Color.G, px.Color.B, (byte)a); to.Add(px); } } @@ -594,7 +591,7 @@ public class Morph : IDisposable { for (ulong x = 0; x < _width; ++x) { - var px = new Pixel() { X = (ushort)x, Y = (ushort)y, Color = new Color(0, 0, 0, 0), }; + var px = new Pixel() { X = (ushort)x, Y = (ushort)y, Color = new AtomorphColor(0, 0, 0, 0), }; if (KeepBackground) px.Color = GetBackground((ushort)x, (ushort)y, t); image.Add(px); } @@ -645,18 +642,18 @@ public class Morph : IDisposable public ushort GetHeight() => _height; public ulong GetFrameCount() => (ulong)_frames.Count; public void NextState() => _skipState = true; - public Blob? GetBlob(ulong f, ulong b) => HasBlob(f, b) ? _frames[f].Blobs[(int)b] : null; + internal Blob? GetBlob(ulong f, ulong b) => HasBlob(f, b) ? _frames[f].Blobs[(int)b] : null; public double GetEnergy() => _energy; - public Pixel Blob2Pixel(Blob bl) + internal Pixel Blob2Pixel(Blob bl) { var px = new Pixel() { - X = (ushort)bl.X, Y = (ushort)bl.Y, Color = ColorUtilities.CreateColor(bl.R, bl.G, bl.B, bl.A) + X = (ushort)bl.X, Y = (ushort)bl.Y, Color = AtomorphColorUtilities.CreateColor(bl.R, bl.G, bl.B, bl.A) }; if (BlobDelimiter == ColorMethod.HSP) { - px.Color = ColorUtilities.HspToRgb(px.Color); + px.Color = AtomorphColorUtilities.HspToRgb(px.Color); } return px; } @@ -997,7 +994,7 @@ public class Morph : IDisposable private void DrawAtoms(double t, List image) { - Dictionary> colors = new(); + Dictionary> colors = new(); Blob? bl = null; ulong blockIterator = 0; @@ -1042,7 +1039,7 @@ public class Morph : IDisposable if (aa == 0) continue; - colors.AddToDictionaryList(pos, new Color(rr, gg, bb, aa)); + colors.AddToDictionaryList(pos, new AtomorphColor(rr, gg, bb, aa)); } } @@ -1104,7 +1101,7 @@ public class Morph : IDisposable a = bga + (1.0 - bga) * a; } var px = image[(int)pos]; - px.Color = ColorUtilities.CreateColor(r, g, b, a); + px.Color = AtomorphColorUtilities.CreateColor(r, g, b, a); image[(int)pos] = px; } } @@ -1126,12 +1123,12 @@ public class Morph : IDisposable StepFluid(frame_key, t, time); - Dictionary image_buffer = new(); + Dictionary image_buffer = new(); var particles = _fluid.Particles; ulong particle_count = _fluid.ParticleCount; - Dictionary> colors = new(); + Dictionary> colors = new(); Dictionary> weights = new(); Dictionary> startups = new(); @@ -1190,7 +1187,7 @@ public class Morph : IDisposable double weight_x1y2 = ((1.0 - x_fract) * y_fract); double weight_x2y2 = (x_fract * y_fract); - var c = ColorUtilities.CreateColor(p.r, p.g, p.b, p.a); + var c = AtomorphColorUtilities.CreateColor(p.r, p.g, p.b, p.a); if (weight_x1y1 > 0.0) { @@ -1222,7 +1219,7 @@ public class Morph : IDisposable } } - Dictionary blob = new(); + Dictionary blob = new(); foreach (var cit in colors) { var cs = cit.Value; @@ -1259,7 +1256,7 @@ public class Morph : IDisposable ushort x = (ushort)(pos % (ushort.MaxValue + 1)); ushort y = (ushort)(pos / (ushort.MaxValue + 1)); - var px = new Pixel() { X = x, Y = y, Color = ColorUtilities.CreateColor(r, g, b, a) }; + var px = new Pixel() { X = x, Y = y, Color = AtomorphColorUtilities.CreateColor(r, g, b, a) }; ulong imgpos = (ulong)(y * _width + x); if (Feather > 0) blob[pos] = px.Color; @@ -1291,7 +1288,7 @@ public class Morph : IDisposable if (!border.Any()) break; - Dictionary blob_buf = new(); + Dictionary blob_buf = new(); foreach (var pos in border) { @@ -1323,7 +1320,7 @@ public class Morph : IDisposable a *= alpha; - blob_buf[pos] = ColorUtilities.CreateColor(r, g, b, a); + blob_buf[pos] = AtomorphColorUtilities.CreateColor(r, g, b, a); } foreach (var color in blob_buf) @@ -1367,7 +1364,7 @@ public class Morph : IDisposable b = a * b + (1.0 - a) * bgb; a = bga + (1.0 - bga) * a; - c = new Color((byte)Math.Round(r * 255.0), (byte)Math.Round(g * 255.0), (byte)Math.Round(b * 255.0), + c = new AtomorphColor((byte)Math.Round(r * 255.0), (byte)Math.Round(g * 255.0), (byte)Math.Round(b * 255.0), (byte)Math.Round(a * 255.0)); } @@ -1660,7 +1657,7 @@ public class Morph : IDisposable px2.X = pt2.X; px2.Y = pt2.Y; if (next_surface > 0.0) - px2.Color = new Color(px2.Color.R, px2.Color.G, px2.Color.B, 0); + px2.Color = new AtomorphColor(px2.Color.R, px2.Color.G, px2.Color.B, 0); } else if (AtomorphUtilities.PointHasPixel(pt2) && !AtomorphUtilities.PointHasPixel(pt1)) { @@ -1669,7 +1666,7 @@ public class Morph : IDisposable px1.X = pt1.X; px1.Y = pt1.Y; if (previous_surface > 0.0) - px1.Color = new Color(px1.Color.R, px1.Color.G, px1.Color.B, 0); + px1.Color = new AtomorphColor(px1.Color.R, px1.Color.G, px1.Color.B, 0); } else { @@ -1677,7 +1674,7 @@ public class Morph : IDisposable px2 = GetPixel(nextFrameKey, AtomorphUtilities.XY2Pos(pt2.X, pt2.Y)); } - Color c; + AtomorphColor c; if (Fading == InterpolationMethod.Perlin) { diff --git a/Atomorph.NET/Perlin/PerlinNoise.cs b/Atomorph.NET/Perlin/PerlinNoise.cs index d2bdf43..842f689 100644 --- a/Atomorph.NET/Perlin/PerlinNoise.cs +++ b/Atomorph.NET/Perlin/PerlinNoise.cs @@ -1,12 +1,11 @@ -using System; using System.Runtime.CompilerServices; using Pcg; namespace Atomorph.Perlin; -public class PerlinNoise +internal class PerlinNoise { - private int[] _p = new int[512]; + private readonly int[] _p = new int[512]; public PerlinNoise(uint seed = 1) { diff --git a/Atomorph.NET/PointFlags.cs b/Atomorph.NET/PointFlags.cs index 33182a1..e7b7065 100644 --- a/Atomorph.NET/PointFlags.cs +++ b/Atomorph.NET/PointFlags.cs @@ -1,5 +1,3 @@ -using System; - namespace Atomorph; [Flags] diff --git a/Atomorph.NET/Utilities/IOrderedDictionary.cs b/Atomorph.NET/Utilities/IOrderedDictionary.cs deleted file mode 100644 index 319443f..0000000 --- a/Atomorph.NET/Utilities/IOrderedDictionary.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.Specialized; - -namespace Atomorph.Utilities; - -/// -/// Represents a generic collection of key/value pairs that are ordered independently of the key and value. -/// -/// The type of the keys in the dictionary -/// The type of the values in the dictionary -public interface IOrderedDictionary : IOrderedDictionary, IDictionary -{ - /// - /// Adds an entry with the specified key and value into the IOrderedDictionary<TKey,TValue> collection with the lowest available index. - /// - /// The key of the entry to add. - /// The value of the entry to add. - /// The index of the newly added entry - /// - /// You can also use the property to add new elements by setting the value of a key that does not exist in the IOrderedDictionary<TKey,TValue> collection; however, if the specified key already exists in the IOrderedDictionary<TKey,TValue>, setting the property overwrites the old value. In contrast, the method does not modify existing elements. - /// An element with the same key already exists in the IOrderedDictionary<TKey,TValue> - /// The IOrderedDictionary<TKey,TValue> is read-only.
- /// -or-
- /// The IOrderedDictionary<TKey,TValue> has a fized size.
- new int Add(TKey key, TValue value); - - /// - /// Inserts a new entry into the IOrderedDictionary<TKey,TValue> collection with the specified key and value at the specified index. - /// - /// The zero-based index at which the element should be inserted. - /// The key of the entry to add. - /// The value of the entry to add. The value can be if the type of the values in the dictionary is a reference type. - /// is less than 0.
- /// -or-
- /// is greater than .
- /// An element with the same key already exists in the IOrderedDictionary<TKey,TValue>. - /// The IOrderedDictionary<TKey,TValue> is read-only.
- /// -or-
- /// The IOrderedDictionary<TKey,TValue> has a fized size.
- void Insert(int index, TKey key, TValue value); - - /// - /// Gets or sets the value at the specified index. - /// - /// The zero-based index of the value to get or set. - /// The value of the item at the specified index. - /// is less than 0.
- /// -or-
- /// is equal to or greater than .
- new TValue this[int index] - { - get; - set; - } -} \ No newline at end of file diff --git a/Atomorph.NET/Utilities/OrderedDictionary.cs b/Atomorph.NET/Utilities/OrderedDictionary.cs deleted file mode 100644 index 90f6cc1..0000000 --- a/Atomorph.NET/Utilities/OrderedDictionary.cs +++ /dev/null @@ -1,641 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; - -namespace Atomorph.Utilities; - -/// -/// Represents a generic collection of key/value pairs that are ordered independently of the key and value. -/// -/// The type of the keys in the dictionary -/// The type of the values in the dictionary -internal class OrderedDictionary : IOrderedDictionary -{ - private const int DefaultInitialCapacity = 0; - - private static readonly string _keyTypeName = typeof(TKey).FullName; - private static readonly string _valueTypeName = typeof(TValue).FullName; - private static readonly bool _valueTypeIsReferenceType = !typeof(ValueType).IsAssignableFrom(typeof(TValue)); - - private Dictionary _dictionary; - private List> _list; - private IEqualityComparer _comparer; - private object _syncRoot; - private int _initialCapacity; - - /// - /// Initializes a new instance of the OrderedDictionary<TKey,TValue> class. - /// - public OrderedDictionary() - : this(DefaultInitialCapacity, null) - { - } - - /// - /// Initializes a new instance of the OrderedDictionary<TKey,TValue> class using the specified initial capacity. - /// - /// The initial number of elements that the OrderedDictionary<TKey,TValue> can contain. - /// is less than 0 - public OrderedDictionary(int capacity) - : this(capacity, null) - { - } - - /// - /// Initializes a new instance of the OrderedDictionary<TKey,TValue> class using the specified comparer. - /// - /// The IEqualityComparer<TKey> to use when comparing keys, or to use the default EqualityComparer<TKey> for the type of the key. - public OrderedDictionary(IEqualityComparer comparer) - : this(DefaultInitialCapacity, comparer) - { - } - - /// - /// Initializes a new instance of the OrderedDictionary<TKey,TValue> class using the specified initial capacity and comparer. - /// - /// The initial number of elements that the OrderedDictionary<TKey,TValue> collection can contain. - /// The IEqualityComparer<TKey> to use when comparing keys, or to use the default EqualityComparer<TKey> for the type of the key. - /// is less than 0 - public OrderedDictionary(int capacity, IEqualityComparer comparer) - { - if(0 > capacity) - throw new ArgumentOutOfRangeException("capacity", "'capacity' must be non-negative"); - - _initialCapacity = capacity; - _comparer = comparer; - } - - /// - /// Converts the object passed as a key to the key type of the dictionary - /// - /// The key object to check - /// The key object, cast as the key type of the dictionary - /// is . - /// The key type of the OrderedDictionary<TKey,TValue> is not in the inheritance hierarchy of . - private static TKey ConvertToKeyType(object keyObject) - { - if(null == keyObject) - { - throw new ArgumentNullException("key"); - } - else - { - if(keyObject is TKey) - return (TKey)keyObject; - } - throw new ArgumentException("'key' must be of type " + _keyTypeName, "key"); - } - - /// - /// Converts the object passed as a value to the value type of the dictionary - /// - /// The object to convert to the value type of the dictionary - /// The value object, converted to the value type of the dictionary - /// is , and the value type of the OrderedDictionary<TKey,TValue> is a value type. - /// The value type of the OrderedDictionary<TKey,TValue> is not in the inheritance hierarchy of . - private static TValue ConvertToValueType(object value) - { - if(null == value) - { - if(_valueTypeIsReferenceType) - return default(TValue); - else - throw new ArgumentNullException("value"); - } - else - { - if(value is TValue) - return (TValue)value; - } - throw new ArgumentException("'value' must be of type " + _valueTypeName, "value"); - } - - /// - /// Gets the dictionary object that stores the keys and values - /// - /// The dictionary object that stores the keys and values for the OrderedDictionary<TKey,TValue> - /// Accessing this property will create the dictionary object if necessary - private Dictionary Dictionary - { - get - { - if(null == _dictionary) - { - _dictionary = new Dictionary(_initialCapacity, _comparer); - } - return _dictionary; - } - } - - /// - /// Gets the list object that stores the key/value pairs. - /// - /// The list object that stores the key/value pairs for the OrderedDictionary<TKey,TValue> - /// Accessing this property will create the list object if necessary. - private List> List - { - get - { - if(null == List) - { - _list = new List>(_initialCapacity); - } - return _list; - } - } - - IDictionaryEnumerator IOrderedDictionary.GetEnumerator() - { - return Dictionary.GetEnumerator(); - } - - IDictionaryEnumerator IDictionary.GetEnumerator() - { - return Dictionary.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return List.GetEnumerator(); - } - - IEnumerator> IEnumerable>.GetEnumerator() - { - return List.GetEnumerator(); - } - - /// - /// Inserts a new entry into the OrderedDictionary<TKey,TValue> collection with the specified key and value at the specified index. - /// - /// The zero-based index at which the element should be inserted. - /// The key of the entry to add. - /// The value of the entry to add. The value can be if the type of the values in the dictionary is a reference type. - /// is less than 0.
- /// -or-
- /// is greater than .
- /// is . - /// An element with the same key already exists in the OrderedDictionary<TKey,TValue>. - public void Insert(int index, TKey key, TValue value) - { - if(index > Count || index < 0) - throw new ArgumentOutOfRangeException("index"); - - Dictionary.Add(key, value); - List.Insert(index, new KeyValuePair(key, value)); - } - - /// - /// Inserts a new entry into the OrderedDictionary<TKey,TValue> collection with the specified key and value at the specified index. - /// - /// The zero-based index at which the element should be inserted. - /// The key of the entry to add. - /// The value of the entry to add. The value can be if the type of the values in the dictionary is a reference type. - /// is less than 0.
- /// -or-
- /// is greater than .
- /// is .
- /// -or-
- /// is , and the value type of the OrderedDictionary<TKey,TValue> is a value type.
- /// The key type of the OrderedDictionary<TKey,TValue> is not in the inheritance hierarchy of .
- /// -or-
- /// The value type of the OrderedDictionary<TKey,TValue> is not in the inheritance hierarchy of .
- /// -or-
- /// An element with the same key already exists in the OrderedDictionary<TKey,TValue>.
- void IOrderedDictionary.Insert(int index, object key, object value) - { - Insert(index, ConvertToKeyType(key), ConvertToValueType(value)); - } - - /// - /// Removes the entry at the specified index from the OrderedDictionary<TKey,TValue> collection. - /// - /// The zero-based index of the entry to remove. - /// is less than 0.
- /// -or-
- /// index is equal to or greater than .
- public void RemoveAt(int index) - { - if(index >= Count || index < 0) - throw new ArgumentOutOfRangeException("index", "'index' must be non-negative and less than the size of the collection"); - - TKey key = List[index].Key; - - List.RemoveAt(index); - Dictionary.Remove(key); - } - - /// - /// Gets or sets the value at the specified index. - /// - /// The zero-based index of the value to get or set. - /// The value of the item at the specified index. - /// is less than 0.
- /// -or-
- /// index is equal to or greater than .
- public TValue this[int index] - { - get - { - return List[index].Value; - } - - set - { - if(index >= Count || index < 0) - throw new ArgumentOutOfRangeException("index", "'index' must be non-negative and less than the size of the collection"); - - TKey key = List[index].Key; - - List[index] = new KeyValuePair(key, value); - Dictionary[key] = value; - } - } - - /// - /// Gets or sets the value at the specified index. - /// - /// The zero-based index of the value to get or set. - /// The value of the item at the specified index. - /// is less than 0.
- /// -or-
- /// index is equal to or greater than .
- /// is a null reference, and the value type of the OrderedDictionary<TKey,TValue> is a value type. - /// The value type of the OrderedDictionary<TKey,TValue> is not in the inheritance hierarchy of . - object IOrderedDictionary.this[int index] - { - get - { - return this[index]; - } - - set - { - this[index] = ConvertToValueType(value); - } - } - - /// - /// Adds an entry with the specified key and value into the OrderedDictionary<TKey,TValue> collection with the lowest available index. - /// - /// The key of the entry to add. - /// The value of the entry to add. This value can be . - /// A key cannot be , but a value can be. - /// You can also use the property to add new elements by setting the value of a key that does not exist in the OrderedDictionary<TKey,TValue> collection; however, if the specified key already exists in the OrderedDictionary<TKey,TValue>, setting the property overwrites the old value. In contrast, the method does not modify existing elements. - /// is - /// An element with the same key already exists in the OrderedDictionary<TKey,TValue> - void IDictionary.Add(TKey key, TValue value) - { - Add(key, value); - } - - /// - /// Adds an entry with the specified key and value into the OrderedDictionary<TKey,TValue> collection with the lowest available index. - /// - /// The key of the entry to add. - /// The value of the entry to add. This value can be . - /// The index of the newly added entry - /// A key cannot be , but a value can be. - /// You can also use the property to add new elements by setting the value of a key that does not exist in the OrderedDictionary<TKey,TValue> collection; however, if the specified key already exists in the OrderedDictionary<TKey,TValue>, setting the property overwrites the old value. In contrast, the method does not modify existing elements. - /// is - /// An element with the same key already exists in the OrderedDictionary<TKey,TValue> - public int Add(TKey key, TValue value) - { - Dictionary.Add(key, value); - List.Add(new KeyValuePair(key, value)); - return Count - 1; - } - - /// - /// Adds an entry with the specified key and value into the OrderedDictionary<TKey,TValue> collection with the lowest available index. - /// - /// The key of the entry to add. - /// The value of the entry to add. This value can be . - /// is .
- /// -or-
- /// is , and the value type of the OrderedDictionary<TKey,TValue> is a value type.
- /// The key type of the OrderedDictionary<TKey,TValue> is not in the inheritance hierarchy of .
- /// -or-
- /// The value type of the OrderedDictionary<TKey,TValue> is not in the inheritance hierarchy of .
- void IDictionary.Add(object key, object value) - { - Add(ConvertToKeyType(key), ConvertToValueType(value)); - } - - /// - /// Removes all elements from the OrderedDictionary<TKey,TValue> collection. - /// - /// The capacity is not changed as a result of calling this method. - public void Clear() - { - Dictionary.Clear(); - List.Clear(); - } - - /// - /// Determines whether the OrderedDictionary<TKey,TValue> collection contains a specific key. - /// - /// The key to locate in the OrderedDictionary<TKey,TValue> collection. - /// if the OrderedDictionary<TKey,TValue> collection contains an element with the specified key; otherwise, . - /// is - public bool ContainsKey(TKey key) - { - return Dictionary.ContainsKey(key); - } - /// - /// Determines whether the OrderedDictionary<TKey,TValue> collection contains a specific key. - /// - /// The key to locate in the OrderedDictionary<TKey,TValue> collection. - /// if the OrderedDictionary<TKey,TValue> collection contains an element with the specified key; otherwise, . - /// is - /// The key type of the OrderedDictionary<TKey,TValue> is not in the inheritance hierarchy of . - bool IDictionary.Contains(object key) - { - return ContainsKey(ConvertToKeyType(key)); - } - - /// - /// Gets a value indicating whether the OrderedDictionary<TKey,TValue> has a fixed size. - /// - /// if the OrderedDictionary<TKey,TValue> has a fixed size; otherwise, . The default is . - bool IDictionary.IsFixedSize - { - get - { - return false; - } - } - - /// - /// Gets a value indicating whether the OrderedDictionary<TKey,TValue> collection is read-only. - /// - /// if the OrderedDictionary<TKey,TValue> is read-only; otherwise, . The default is . - /// - /// A collection that is read-only does not allow the addition, removal, or modification of elements after the collection is created. - /// A collection that is read-only is simply a collection with a wrapper that prevents modification of the collection; therefore, if changes are made to the underlying collection, the read-only collection reflects those changes. - /// - public bool IsReadOnly - { - get - { - return false; - } - } - - /// - /// Gets an object containing the keys in the OrderedDictionary<TKey,TValue>. - /// - /// An object containing the keys in the OrderedDictionary<TKey,TValue>. - /// The returned object is not a static copy; instead, the collection refers back to the keys in the original OrderedDictionary<TKey,TValue>. Therefore, changes to the OrderedDictionary<TKey,TValue> continue to be reflected in the key collection. - ICollection IDictionary.Keys - { - get - { - return (ICollection)Keys; - } - } - - /// - /// Returns the zero-based index of the specified key in the OrderedDictionary<TKey,TValue> - /// - /// The key to locate in the OrderedDictionary<TKey,TValue> - /// The zero-based index of , if is found in the OrderedDictionary<TKey,TValue>; otherwise, -1 - /// This method performs a linear search; therefore it has a cost of O(n) at worst. - public int IndexOfKey(TKey key) - { - if(null == key) - throw new ArgumentNullException("key"); - - for(int index = 0; index < List.Count; index++) - { - KeyValuePair entry = List[index]; - TKey next = entry.Key; - if(null != _comparer) - { - if(_comparer.Equals(next, key)) - { - return index; - } - } - else if(next.Equals(key)) - { - return index; - } - } - - return -1; - } - - /// - /// Removes the entry with the specified key from the OrderedDictionary<TKey,TValue> collection. - /// - /// The key of the entry to remove - /// if the key was found and the corresponding element was removed; otherwise, - public bool Remove(TKey key) - { - if(null == key) - throw new ArgumentNullException("key"); - - int index = IndexOfKey(key); - if(index >= 0) - { - if(Dictionary.Remove(key)) - { - List.RemoveAt(index); - return true; - } - } - return false; - } - - /// - /// Removes the entry with the specified key from the OrderedDictionary<TKey,TValue> collection. - /// - /// The key of the entry to remove - void IDictionary.Remove(object key) - { - Remove(ConvertToKeyType(key)); - } - - /// - /// Gets an object containing the values in the OrderedDictionary<TKey,TValue> collection. - /// - /// An object containing the values in the OrderedDictionary<TKey,TValue> collection. - /// The returned object is not a static copy; instead, the refers back to the values in the original OrderedDictionary<TKey,TValue> collection. Therefore, changes to the OrderedDictionary<TKey,TValue> continue to be reflected in the . - ICollection IDictionary.Values - { - get - { - return (ICollection)Values; - } - } - - /// - /// Gets or sets the value with the specified key. - /// - /// The key of the value to get or set. - /// The value associated with the specified key. If the specified key is not found, attempting to get it returns , and attempting to set it creates a new element using the specified key. - public TValue this[TKey key] - { - get - { - return Dictionary[key]; - } - set - { - if(Dictionary.ContainsKey(key)) - { - Dictionary[key] = value; - List[IndexOfKey(key)] = new KeyValuePair(key, value); - } - else - { - Add(key, value); - } - } - } - - /// - /// Gets or sets the value with the specified key. - /// - /// The key of the value to get or set. - /// The value associated with the specified key. If the specified key is not found, attempting to get it returns , and attempting to set it creates a new element using the specified key. - object IDictionary.this[object key] - { - get - { - return this[ConvertToKeyType(key)]; - } - set - { - this[ConvertToKeyType(key)] = ConvertToValueType(value); - } - } - - /// - /// Copies the elements of the OrderedDictionary<TKey,TValue> elements to a one-dimensional Array object at the specified index. - /// - /// The one-dimensional object that is the destination of the objects copied from the OrderedDictionary<TKey,TValue>. The must have zero-based indexing. - /// The zero-based index in at which copying begins. - /// The method preserves the order of the elements in the OrderedDictionary<TKey,TValue> - void ICollection.CopyTo(Array array, int index) - { - ((ICollection)List).CopyTo(array, index); - } - - /// - /// Gets the number of key/values pairs contained in the OrderedDictionary<TKey,TValue> collection. - /// - /// The number of key/value pairs contained in the OrderedDictionary<TKey,TValue> collection. - public int Count - { - get - { - return List.Count; - } - } - - /// - /// Gets a value indicating whether access to the OrderedDictionary<TKey,TValue> object is synchronized (thread-safe). - /// - /// This method always returns false. - bool ICollection.IsSynchronized - { - get - { - return false; - } - } - - /// - /// Gets an object that can be used to synchronize access to the OrderedDictionary<TKey,TValue> object. - /// - /// An object that can be used to synchronize access to the OrderedDictionary<TKey,TValue> object. - object ICollection.SyncRoot - { - get - { - if(this._syncRoot == null) - { - System.Threading.Interlocked.CompareExchange(ref this._syncRoot, new object(), null); - } - return this._syncRoot; - } - } - - /// - /// Gets an ICollection<TKey> object containing the keys in the OrderedDictionary<TKey,TValue>. - /// - /// An ICollection<TKey> object containing the keys in the OrderedDictionary<TKey,TValue>. - /// The returned ICollection<TKey> object is not a static copy; instead, the collection refers back to the keys in the original OrderedDictionary<TKey,TValue>. Therefore, changes to the OrderedDictionary<TKey,TValue> continue to be reflected in the key collection. - public ICollection Keys - { - get - { - return Dictionary.Keys; - } - } - - /// - /// Gets the value associated with the specified key. - /// - /// The key of the value to get. - /// When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of . This parameter can be passed uninitialized. - /// if the OrderedDictionary<TKey,TValue> contains an element with the specified key; otherwise, . - public bool TryGetValue(TKey key, out TValue value) - { - return Dictionary.TryGetValue(key, out value); - } - - /// - /// Gets an ICollection<TValue> object containing the values in the OrderedDictionary<TKey,TValue>. - /// - /// An ICollection<TValue> object containing the values in the OrderedDictionary<TKey,TValue>. - /// The returned ICollection<TKey> object is not a static copy; instead, the collection refers back to the values in the original OrderedDictionary<TKey,TValue>. Therefore, changes to the OrderedDictionary<TKey,TValue> continue to be reflected in the value collection. - public ICollection Values - { - get - { - return Dictionary.Values; - } - } - - /// - /// Adds the specified value to the OrderedDictionary<TKey,TValue> with the specified key. - /// - /// The KeyValuePair<TKey,TValue> structure representing the key and value to add to the OrderedDictionary<TKey,TValue>. - void ICollection>.Add(KeyValuePair item) - { - Add(item.Key, item.Value); - } - - /// - /// Determines whether the OrderedDictionary<TKey,TValue> contains a specific key and value. - /// - /// The KeyValuePair<TKey,TValue> structure to locate in the OrderedDictionary<TKey,TValue>. - /// if is found in the OrderedDictionary<TKey,TValue>; otherwise, . - bool ICollection>.Contains(KeyValuePair item) - { - return ((ICollection>)Dictionary).Contains(item); - } - - /// - /// Copies the elements of the OrderedDictionary<TKey,TValue> to an array of type , starting at the specified index. - /// - /// The one-dimensional array of type KeyValuePair<TKey,TValue> that is the destination of the KeyValuePair<TKey,TValue> elements copied from the OrderedDictionary<TKey,TValue>. The array must have zero-based indexing. - /// The zero-based index in at which copying begins. - void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) - { - ((ICollection>)Dictionary).CopyTo(array, arrayIndex); - } - - /// - /// Removes a key and value from the dictionary. - /// - /// The KeyValuePair<TKey,TValue> structure representing the key and value to remove from the OrderedDictionary<TKey,TValue>. - /// if the key and value represented by is successfully found and removed; otherwise, . This method returns if is not found in the OrderedDictionary<TKey,TValue>. - bool ICollection>.Remove(KeyValuePair item) - { - return Remove(item.Key); - } -} \ No newline at end of file diff --git a/Atomorph.NET/Utilities/PortUtilities.cs b/Atomorph.NET/Utilities/PortUtilities.cs index 263729d..c2de38c 100644 --- a/Atomorph.NET/Utilities/PortUtilities.cs +++ b/Atomorph.NET/Utilities/PortUtilities.cs @@ -1,15 +1,13 @@ -using System; using System.Collections; -using System.Collections.Generic; using Pcg; -namespace Atomorph; +namespace Atomorph.Utilities; internal static class PortUtilities { - private static readonly PcgRandom Rng = new PcgRandom(); + private static readonly PcgRandom Rng = new(); - public static void RandomShuffle(this IList list, PcgRandom? rng = null) + internal static void RandomShuffle(this IList list, PcgRandom? rng = null) { rng ??= Rng; for (var i = list.Count - 1; i > 0; i--) @@ -22,13 +20,13 @@ internal static class PortUtilities } } - public static double ModF(this double value, out double integerPart) + internal static double ModF(this double value, out double integerPart) { integerPart = Math.Floor(value); return value - integerPart; } - public static void AddToDictionaryList(this Dictionary> dictionary, TKey key, TValue value) + internal static void AddToDictionaryList(this Dictionary> dictionary, TKey key, TValue value) { if (!dictionary.TryGetValue(key, out var list)) {