CorridorSegment.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using UnityEngine;
  2. namespace MazeGen
  3. {
  4. /// <summary>
  5. /// One straight, axis-aligned leg of a rendered corridor (a consecutive pair from a
  6. /// hallway room's CorridorWaypoints), registered so later placements/overlap checks treat
  7. /// its full rectangular footprint as occupied space, not just a point at the bend.
  8. /// </summary>
  9. public class CorridorSegment
  10. {
  11. public readonly int OwnerRoomId; // the hallway Room.Id this leg belongs to
  12. public readonly Vector2 A, B;
  13. public readonly float HalfWidth;
  14. public readonly Vector2 Min, Max; // precomputed AABB, since legs are guaranteed axis-aligned
  15. public CorridorSegment(int ownerRoomId, Vector2 a, Vector2 b, float halfWidth)
  16. {
  17. OwnerRoomId = ownerRoomId;
  18. A = a;
  19. B = b;
  20. HalfWidth = halfWidth;
  21. float minX = Mathf.Min(a.x, b.x), maxX = Mathf.Max(a.x, b.x);
  22. float minY = Mathf.Min(a.y, b.y), maxY = Mathf.Max(a.y, b.y);
  23. // Pad only in the thin (perpendicular) axis; length axis stays exact so a leg's
  24. // AABB doesn't creep past the door it terminates at.
  25. if (Mathf.Approximately(minY, maxY))
  26. {
  27. minY -= halfWidth;
  28. maxY += halfWidth;
  29. }
  30. else
  31. {
  32. minX -= halfWidth;
  33. maxX += halfWidth;
  34. }
  35. Min = new Vector2(minX, minY);
  36. Max = new Vector2(maxX, maxY);
  37. }
  38. }
  39. }