public AffineTransform(Box from_box, Box to_box) { _matrix = new double[6] { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 }; Translate(-from_box.X1, -from_box.Y1); Scale(to_box.Width / from_box.Width, to_box.Height / from_box.Height); Translate(to_box.X1, to_box.X1); }
public bool Intersects(Box rhs) { return ((rhs._x1 <= _x1 && _x1 <= rhs._x2) || (_x1 <= rhs._x1 && rhs._x1 <= _x2)) && ((rhs._y1 <= _y1 && _y1 <= rhs._y2) || (_y1 <= rhs._y1 && rhs._y1 <= _y2)); }
public void ExpandToInclude(Box rhs) { _x1 = Math.Min(_x1, rhs._x1); _y1 = Math.Min(_y1, rhs._y1); _x2 = Math.Max(_x2, rhs._x2); _y2 = Math.Max(_y2, rhs._y2); }
public double GetOverlappingArea(Box rhs) { double rightMostLeft = Math.Max(_x1, rhs._x1); double leftMostRight = Math.Min(_x2, rhs._x2); double bottomMostTop = Math.Max(_y1, rhs._y1); double topMostBottom = Math.Min(_y2, rhs._y2); if (leftMostRight <= rightMostLeft) return 0.0; if (topMostBottom <= bottomMostTop) return 0.0; return (leftMostRight - rightMostLeft) * (topMostBottom - bottomMostTop); }
public bool Contains(Box rhs) { return _x1 <= rhs._x1 && rhs._x1 <= _x2 && _x1 <= rhs._x2 && rhs._x2 <= _x2 && _y1 <= rhs._y1 && rhs._y1 <= _y2 && _y1 <= rhs._y2 && rhs._y2 <= _y2; }