/** * Checks if boundaries have common points * * @param Boundary $boundary * @return boolean */ public function intersects(Boundary $boundary) { $firstPoint = $this->getFirstPoint(); $diagonalPoint = $this->getDiagonalPoint(); $compareFirstPoint = $boundary->getFirstPoint(); $compareDiagonalPoint = $boundary->getDiagonalPoint(); foreach ($boundary->points as $point) { if ($this->contains($point)) { return true; } } foreach ($this->points as $point) { if ($boundary->contains($point)) { return true; } } $centerPoint = $this->getPointBetween($firstPoint, $diagonalPoint); if ($boundary->contains($centerPoint)) { return true; } $centerPoint = $this->getPointBetween($compareFirstPoint, $compareDiagonalPoint); if ($this->contains($centerPoint)) { return true; } $centerPoint = $this->getPointBetween($firstPoint, $compareDiagonalPoint); if ($this->contains($centerPoint) && $boundary->contains($centerPoint)) { return true; } $centerPoint = $this->getPointBetween($compareFirstPoint, $diagonalPoint); if ($this->contains($centerPoint) && $boundary->contains($centerPoint)) { return true; } return false; }
/** * @test */ public function clearBoundaryAndAddOldFirstPoint() { $nodeMock = $this->getMock('\\PHPPdf\\Core\\Node\\Text', array('getBoundary')); $boundary = new Boundary(); $boundary->setNext(0, 100)->setNext(100, 100)->setNext(100, 0)->setNext(0, 0)->close(); $firstPoint = $boundary->getFirstPoint(); $nodeMock->expects($this->atLeastOnce())->method('getBoundary')->will($this->returnValue($boundary)); $this->formatter->format($nodeMock, $this->createDocumentStub()); $this->assertFalse($boundary->isClosed()); $this->assertEquals($firstPoint, $boundary->getFirstPoint()); $this->assertEquals(1, count($boundary)); }