Browse Source

Added docs for Chunk.cs, ChunkPool.cs, ChunkResolution.cs and ChunkResolutionEx.cs

CPKreuz 3 years ago
parent
commit
6a9c79e127

+ 20 - 1
src/ChunkyImageLib/Chunk.cs

@@ -12,10 +12,18 @@ public class Chunk : IDisposable
     /// </summary>
     public static int ChunkCounter => chunkCounter;
 
-
     private bool returned = false;
+    /// <summary>
+    /// The surface of the chunk
+    /// </summary>
     public Surface Surface { get; }
+    /// <summary>
+    /// The size of the chunk
+    /// </summary>
     public VecI PixelSize { get; }
+    /// <summary>
+    /// The resolution of the chunk
+    /// </summary>
     public ChunkResolution Resolution { get; }
     private Chunk(ChunkResolution resolution)
     {
@@ -26,6 +34,9 @@ public class Chunk : IDisposable
         Surface = new Surface(PixelSize);
     }
 
+    /// <summary>
+    /// Tries to take a chunk with the <paramref name="resolution"/> from the pool, or creates a new one
+    /// </summary>
     public static Chunk Create(ChunkResolution resolution = ChunkResolution.Full)
     {
         var chunk = ChunkPool.Instance.Get(resolution) ?? new Chunk(resolution);
@@ -34,11 +45,19 @@ public class Chunk : IDisposable
         return chunk;
     }
 
+    /// <summary>
+    /// Draw's on the <see cref="Surface"/> of the chunk
+    /// </summary>
+    /// <param name="pos">The destination for the <paramref name="surface"/></param>
+    /// <param name="paint">The paint to use while drawing</param>
     public void DrawOnSurface(SKSurface surface, VecI pos, SKPaint? paint = null)
     {
         surface.Canvas.DrawSurface(Surface.SkiaSurface, pos.X, pos.Y, paint);
     }
 
+    /// <summary>
+    /// Returns the chunk back to the pool
+    /// </summary>
     public void Dispose()
     {
         if (returned)

+ 12 - 2
src/ChunkyImageLib/ChunkPool.cs

@@ -10,6 +10,9 @@ internal class ChunkPool
 
     private static object lockObj = new();
     private static ChunkPool? instance;
+    /// <summary>
+    /// The instance of the <see cref="ChunkPool"/>
+    /// </summary>
     public static ChunkPool Instance
     {
         get
@@ -18,8 +21,7 @@ internal class ChunkPool
             {
                 lock (lockObj)
                 {
-                    if (instance is null)
-                        instance = new ChunkPool();
+                    instance ??= new ChunkPool();
                 }
             }
             return instance;
@@ -30,6 +32,11 @@ internal class ChunkPool
     private readonly ConcurrentBag<Chunk> halfChunks = new();
     private readonly ConcurrentBag<Chunk> quarterChunks = new();
     private readonly ConcurrentBag<Chunk> eighthChunks = new();
+    
+    /// <summary>
+    /// Tries to take a chunk from the pool, returns null if there's no Chunk available
+    /// </summary>
+    /// <param name="resolution">The resolution for the chunk</param>
     internal Chunk? Get(ChunkResolution resolution) => GetBag(resolution).TryTake(out Chunk? item) ? item : null;
 
     private ConcurrentBag<Chunk> GetBag(ChunkResolution resolution)
@@ -44,6 +51,9 @@ internal class ChunkPool
         };
     }
 
+    /// <summary>
+    /// Returns a chunk back to the pool
+    /// </summary>
     internal void Push(Chunk chunk)
     {
         var chunks = GetBag(chunk.Resolution);

+ 12 - 0
src/ChunkyImageLib/DataHolders/ChunkResolution.cs

@@ -3,8 +3,20 @@
 [Flags]
 public enum ChunkResolution
 {
+    /// <summary>
+    /// The full resolution of the chunk
+    /// </summary>
     Full = 1,
+    /// <summary>
+    /// Half of the chunks resolution
+    /// </summary>
     Half = 2,
+    /// <summary>
+    /// A quarter of the chunks resolution
+    /// </summary>
     Quarter = 4,
+    /// <summary>
+    /// An eighth of the chunks resolution
+    /// </summary>
     Eighth = 8
 }

+ 7 - 0
src/ChunkyImageLib/DataHolders/ChunkResolutionEx.cs

@@ -2,6 +2,9 @@
 
 public static class ChunkResolutionEx
 {
+    /// <summary>
+    /// Returns the multiplier of the <paramref name="resolution"/>.
+    /// </summary>
     public static double Multiplier(this ChunkResolution resolution)
     {
         return resolution switch
@@ -14,6 +17,10 @@ public static class ChunkResolutionEx
         };
     }
 
+    /// <summary>
+    /// Returns the <see cref="ChunkPool.FullChunkSize"/> for the <paramref name="resolution"/>
+    /// </summary>
+    /// <seealso cref="ChunkPool"/>
     public static int PixelSize(this ChunkResolution resolution)
     {
         return resolution switch