public BBox Intersection(BBox other) { var x0 = Math.Max(Left, other.Left); var y0 = Math.Max(Bottom, other.Bottom); var x1 = Math.Min(Right, other.Right); var y1 = Math.Min(Top, other.Top); if (x0 <= x1 && y0 <= y1) { return(new BBox(x0, y0, x1, y1)); } else { return(null); } }
// BUGGO: Yikes this suddenly broke dramatically when I re-ordered the // constructor arguments for BBox's. I thought I fixed all the instances // where that mattered though! public override Intersection IntersectBBox(BBox other) { var intersectionBBox = bbox.Intersection(other); if (intersectionBBox == null) { return(null); } var contact = intersectionBBox.Center(); // XXX: rather kludgy and approximate; should take into account starting velocity, etc. var dx0 = contact.X - other.Left; var dx1 = other.Right - contact.X; var dx = Math.Min(dx0, dx1); var xside = dx0 < dx1 ? -Vector2d.UnitX : Vector2d.UnitX; var dy0 = contact.Y - other.Bottom; var dy1 = other.Top - contact.Y; var dy = Math.Min(dy0, dy1); var yside = dy0 < dy1 ? Vector2d.UnitY : -Vector2d.UnitY; var ds = Math.Min(dx, dy); var sideNormal = dx < dy ? xside : yside; var flat = dx < dy ? intersectionBBox.Dy : intersectionBBox.Dx; return(new Intersection(contact, sideNormal, 0.5 * ds, -0.5 * ds, flat, -flat)); }
public bool IntersectsBBox(BBox other) { return(((Left <= other.Left && other.Left <= Right) || (other.Left <= Left && Left <= other.Right)) && ((Bottom <= other.Bottom && other.Bottom <= Top) || (other.Bottom <= Bottom && Bottom <= other.Top))); }
public override void Translate(Vector2d delta) { this.bbox = bbox.Translated(delta); }
public BoxGeom(BBox bbox) { this.bbox = bbox; }
public BoxGeom(double x0, double y0, double x1, double y1) { bbox = new BBox(x0, y0, x1, y1); }
public override Intersection IntersectBBox(BBox other) { return(null); }
public abstract Intersection IntersectBBox(BBox other);