CellData.cs 1008 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. namespace Day18;
  2. public class CellData
  3. {
  4. public Vec TopLeft { get; }
  5. public Vec BottomRight { get; }
  6. public List<Line>? Lines { get; set; }
  7. public bool HasCrossing { get; private set; }
  8. public CellData(Vec tl, Vec br)
  9. {
  10. TopLeft = tl;
  11. BottomRight = br;
  12. }
  13. public long Size()
  14. {
  15. return (BottomRight.X - TopLeft.X) * (BottomRight.Y - TopLeft.Y);
  16. }
  17. public void Calculate()
  18. {
  19. foreach (var l in Lines!)
  20. {
  21. if (l.Dir.IsVertical && l.Start.X == TopLeft.X)
  22. {
  23. var start = Math.Min(l.Start.Y, l.Start.Y + l.Length * l.Dir.Y);
  24. var end = Math.Max(l.Start.Y, l.Start.Y + l.Length * l.Dir.Y);
  25. if (start <= TopLeft.Y && end >= TopLeft.Y && start <= BottomRight.Y && end >= BottomRight.Y)
  26. {
  27. HasCrossing = true;
  28. break;
  29. }
  30. }
  31. }
  32. }
  33. }