public static bool CheckOverlap(Bounds a, Bounds b, float minOverlap = 0) { Interval a_x = new Interval(a.min.x, a.max.x); Interval a_y = new Interval(a.min.y, a.max.y); Interval a_z = new Interval(a.min.z, a.max.z); Interval b_x = new Interval(b.min.x, b.max.x); Interval b_y = new Interval(b.min.y, b.max.y); Interval b_z = new Interval(b.min.z, b.max.z); if (!Interval.CheckOverlap(a_x, b_x, minOverlap)) { return(false); } if (!Interval.CheckOverlap(a_y, b_y, minOverlap)) { return(false); } if (!Interval.CheckOverlap(a_z, b_z, minOverlap)) { return(false); } return(true); }
//If touching, returns unit vector pointing from A towards B //else returns 0,0,0 public static Vector3 CheckRoomTouch(Bounds a, Bounds b, float minOverlap) { Interval a_x = new Interval(a.min.x, a.max.x); Interval a_y = new Interval(a.min.y, a.max.y); Interval a_z = new Interval(a.min.z, a.max.z); Interval b_x = new Interval(b.min.x, b.max.x); Interval b_y = new Interval(b.min.y, b.max.y); Interval b_z = new Interval(b.min.z, b.max.z); int roomTouchX = Interval.CheckTouching(a_x, b_x); int roomTouchY = Interval.CheckTouching(a_y, b_y); int roomTouchZ = Interval.CheckTouching(a_z, b_z); bool roomOverlapX = Interval.CheckOverlap(a_x, b_x, minOverlap); bool roomOverlapY = Interval.CheckOverlap(a_y, b_y, minOverlap); bool roomOverlapZ = Interval.CheckOverlap(a_z, b_z, minOverlap); //-.-- -.-- --.. if (roomOverlapX && roomOverlapY) { return(Vector3.forward * roomTouchZ); } if (roomOverlapZ && roomOverlapY) { return(Vector3.right * roomTouchX); } if (roomOverlapX && roomOverlapZ) { return(Vector3.up * roomTouchY); } return(Vector3.zero); }
public bool CheckOverlap(Interval interval, int threshold) { if (interval.m_End <= m_Start) { if (m_L == null) { return(true); } else if (m_L.m_End <= interval.m_Start) { return(true); } else { return(m_L.CheckOverlap(interval, threshold)); } } else if (m_End <= interval.m_Start) { if (m_R == null) { return(true); } else if (interval.m_End <= m_R.m_Start) { return(true); } else { return(m_R.CheckOverlap(interval, threshold)); } } else { if (interval.m_Start < m_Start) { Interval before = new Interval(interval.m_Start, m_Start, interval.m_Count); if (!CheckOverlap(before, threshold)) { return(false); } } if (m_End < interval.m_End) { Interval after = new Interval(m_End, interval.m_End, interval.m_Count); if (!CheckOverlap(after, threshold)) { return(false); } } return(m_Count + interval.m_Count < threshold); } }
public static Vector3 OverlapAxes(Bounds a, Bounds b, float minOverlap = 0) { Vector3 result = Vector3.zero; for (int i = 0; i < 3; i++) { Interval a_ = new Interval(a.min[i], a.max[i]); Interval b_ = new Interval(b.min[i], b.max[i]); if (Interval.CheckOverlap(a_, b_, minOverlap)) { result[i] = 1; } } return(result); }
public bool Book(int start, int end) { Interval interval = new Interval(start, end, 1); if (m_Interval == null) { m_Interval = interval; } else { if (!m_Interval.CheckOverlap(interval, 2)) { return(false); } m_Interval.Overlap(interval); m_Interval.Print(true, true); } return(true); }