public BoundingBox CalculateBounds() { recalced = false; if (Bounds == null) { Bounds = Face.GetBounds(Faces); recalced = true; } return Bounds; }
/** Returns whether the given bounding box is contained in this bounding box. * @param b The bounding box * @return Whether the given bounding box is contained */ public bool contains(BoundingBox b) { return !isValid() || (min.X <= b.min.X && min.Y <= b.min.Y && min.Z <= b.min.Z && max.X >= b.max.X && max.Y >= b.max.Y && max.Z >= b.max.Z); }
/** Constructs a new bounding box from the given bounding box. * * @param bounds The bounding box to copy */ public BoundingBox(BoundingBox bounds) { this.Set(bounds); }
/** Sets the given bounding box. * * @param bounds The bounds. * @return This bounding box for chaining. */ public BoundingBox Set(BoundingBox bounds) { return this.Set(bounds.min, bounds.max); }
/** Returns whether the given bounding box is intersecting this bounding box (at least one point in). * @param b The bounding box * @return Whether the given bounding box is intersected */ public bool intersects(BoundingBox b) { if (!isValid()) return false; // test using SAT (separating axis theorem) float lx = Math.Abs(this.cnt.X - b.cnt.X); float sumx = (this.dim.X / 2.0f) + (b.dim.X / 2.0f); float ly = Math.Abs(this.cnt.Y - b.cnt.Y); float sumy = (this.dim.Y / 2.0f) + (b.dim.Y / 2.0f); float lz = Math.Abs(this.cnt.Z - b.cnt.Z); float sumz = (this.dim.Z / 2.0f) + (b.dim.Z / 2.0f); return (lx <= sumx && ly <= sumy && lz <= sumz); }
/** Extends this bounding box by the given bounding box. * * @param a_bounds The bounding box * @return This bounding box for chaining. */ public BoundingBox ext(BoundingBox a_bounds) { return this.Set(min.Set(Math.Min(min.X, a_bounds.min.X), Math.Min(min.Y, a_bounds.min.Y), Math.Min(min.Z, a_bounds.min.Z)), max.Set(Math.Max(max.X, a_bounds.max.X), Math.Max(max.Y, a_bounds.max.Y), Math.Max(max.Z, a_bounds.max.Z))); }