| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using UnityEngine;
- namespace MazeGen
- {
- /// <summary>
- /// One straight, axis-aligned leg of a rendered corridor (a consecutive pair from a
- /// hallway room's CorridorWaypoints), registered so later placements/overlap checks treat
- /// its full rectangular footprint as occupied space, not just a point at the bend.
- /// </summary>
- public class CorridorSegment
- {
- public readonly int OwnerRoomId; // the hallway Room.Id this leg belongs to
- public readonly Vector2 A, B;
- public readonly float HalfWidth;
- public readonly Vector2 Min, Max; // precomputed AABB, since legs are guaranteed axis-aligned
- public CorridorSegment(int ownerRoomId, Vector2 a, Vector2 b, float halfWidth)
- {
- OwnerRoomId = ownerRoomId;
- A = a;
- B = b;
- HalfWidth = halfWidth;
- float minX = Mathf.Min(a.x, b.x), maxX = Mathf.Max(a.x, b.x);
- float minY = Mathf.Min(a.y, b.y), maxY = Mathf.Max(a.y, b.y);
- // Pad only in the thin (perpendicular) axis; length axis stays exact so a leg's
- // AABB doesn't creep past the door it terminates at.
- if (Mathf.Approximately(minY, maxY))
- {
- minY -= halfWidth;
- maxY += halfWidth;
- }
- else
- {
- minX -= halfWidth;
- maxX += halfWidth;
- }
- Min = new Vector2(minX, minY);
- Max = new Vector2(maxX, maxY);
- }
- }
- }
|