/** * @test */ public function verticesOfOneRectArePartiallyInSecondRect_returnIntersection() { $rect1 = Rectangle::create(new Point(50, 50), new Box(100, 100)); $rect2 = Rectangle::create(new Point(40, 40), new Box(50, 50)); $this->assertIntersection(Rectangle::create(new Point(50, 50), new Box(40, 40)), $rect1, $rect2); }
private function pasteImage(ImageInterface $image, ImageInterface $imageToPaste, PointInterface $pastePoint) { if (!$this->boxContains($image->getSize(), $imageToPaste->getSize(), $pastePoint)) { $rectangle = Rectangle::createWithSize($image->getSize())->intersection(Rectangle::create($pastePoint, $imageToPaste->getSize())); if ($rectangle !== null) { $croppingPoint = new Point($rectangle->getStartingPoint()->getX() - $pastePoint->getX(), $rectangle->getStartingPoint()->getY() - $pastePoint->getY()); $imageToPaste->crop($croppingPoint, $rectangle->getSize()); $image->paste($imageToPaste, $this->ensureNonNegativePoint($pastePoint)); } } else { $image->paste($imageToPaste, $pastePoint); } }