public static function containedByBoth(BoundingBox $bb1, BoundingBox $bb2) { $left = max($bb1->getLeft(), $bb2->getLeft()); $top = max($bb1->getLeft(), $bb2->getLeft()); $right = min($bb1->getRight(), $bb2->getRight()); $bottom = min($bb1->getBottom(), $bb2->getBottom()); $bb = new self($left, $top, 0, 0); $bb->setWidthByRight($right); $bb->setHeightByBottom($bottom); return $bb; }