using ImageMagick;
using System.Linq;

namespace Ocr.Tesseract.Extensions;

/// <summary>
/// Extensions for the <see cref="IConnectedComponent{TQuantumType}"/> type
/// </summary>
public static class ConnectedComponentExtensions
{
  /// <summary>
  /// Determine whether this <see cref="IConnectedComponent{TQuantumType}"/> is filled out
  /// </summary>
  public static bool IsFilled(
    this IConnectedComponent<ushort> component,
    IPixelCollection<ushort> pixels
  )
  {
    var initial = pixels[component.X, component.Y]!.GetChannel(0);
    return pixels
      .GetArea(component.X, component.Y, component.Width, component.Height)!
      .All(p => p == initial);
  }
}
