/** * 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; }
private function injectBoundary(Container $container, $yStart = 0) { $parent = $container->getParent(); $point = $parent->getFirstPoint(); $boundary = new Boundary(); $boundary->setNext($point->translate(0, $yStart))->setNext($point->translate($container->getWidth(), $yStart))->setNext($point->translate($container->getWidth(), $yStart + $container->getHeight()))->setNext($point->translate(0, $yStart + $container->getHeight()))->close(); $this->invokeMethod($container, 'setBoundary', array($boundary)); }
private function getContainerMock($start, $end, array $methods = array()) { $methods = array_merge(array('getBoundary', 'getHeight'), $methods); $mock = $this->getMock('PHPPdf\\Core\\Node\\Container', $methods); $boundary = new Boundary(); $boundary->setNext($start[0], $start[1])->setNext($end[0], $start[1])->setNext($end[0], $end[1])->setNext($start[0], $end[1])->close(); $mock->expects($this->atLeastOnce())->method('getBoundary')->will($this->returnValue($boundary)); $mock->expects($this->any())->method('getHeight')->will($this->returnValue($start[1] - $end[1])); return $mock; }
private function getNodeMock($x, $y, $width, $height, array $methods = array(), $boundaryAtLeastOnce = true, $class = 'PHPPdf\\Core\\Node\\Container') { $methods = array_merge(array('getBoundary', 'getHeight', 'getWidth'), $methods); $mock = $this->getMock($class, $methods); $boundary = new Boundary(); $boundary->setNext($x, $y)->setNext($x + $width, $y)->setNext($x + $width, $y - $height)->setNext($x, $y - $height)->close(); $mock->expects($boundaryAtLeastOnce ? $this->atLeastOnce() : $this->any())->method('getBoundary')->will($this->returnValue($boundary)); $mock->expects($this->any())->method('getHeight')->will($this->returnValue($height)); $mock->expects($this->any())->method('getWidth')->will($this->returnValue($width)); return $mock; }
/** * @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)); }
/** * @return Boundary */ private function createBoundary(Node $node, $preferredXCoord, $preferredYCoord) { $dummyBoundary = new Boundary(); $dummyBoundary->setNext($preferredXCoord, $preferredYCoord)->setNext($preferredXCoord + $node->getWidth(), $preferredYCoord)->setNext($preferredXCoord + $node->getWidth(), $preferredYCoord - $node->getHeight())->setNext($preferredXCoord, $preferredYCoord - $node->getHeight()); return $dummyBoundary; }
/** * @test */ public function intersectingOccursWhenAtLeastOnePointIsContainedInBySecondBoundary() { $this->boundary->setNext(0, 100)->setNext(100, 100)->setNext(100, 0)->setNext(0, 0)->close(); $secondBoundary = new Boundary(); $secondBoundary->setNext(99, 100)->setNext(190, 100)->setNext(190, 50)->setNext(99, 50)->close(); $this->assertTrue($this->boundary->intersects($secondBoundary)); $this->assertTrue($secondBoundary->intersects($this->boundary)); }
private function getPointsWithPositionCorrection(UnitConverter $converter, Boundary $boundary) { $points = array(); $xSignMatrix = array(-1, 1, 1, -1, -1); $ySignMatrix = array(1, 1, -1, -1, 1); $position = $converter->convertUnit($this->position); foreach ($boundary->getPoints() as $index => $point) { $xSign = isset($xSignMatrix[$index]) ? $xSignMatrix[$index] : 1; $ySign = isset($ySignMatrix[$index]) ? $ySignMatrix[$index] : 1; $points[$index] = array($point->getX() + $position * $xSign, $point->getY() + $position * $ySign); } return $points; }
private function setPointsToBoundary(Boundary $source, Boundary $destination) { $destination->setNext($source[0])->setNext($source[1])->setNext($source[2])->setNext($source[3])->close(); }
private function createRowMock($start, $end, $break = false, $translate = false) { $methods = array('getHeight', 'getBoundary'); if ($break) { $methods[] = 'breakAt'; } if ($translate) { $methods[] = 'translate'; } $mock = $this->getMock('PHPPdf\\Core\\Node\\Table\\Row', $methods); if ($break) { $mock->expects($this->once())->method('breakAt')->will($this->returnValue(null)); } $boundary = new Boundary(); $boundary->setNext($start[0], $start[1])->setNext($end[0], $start[1])->setNext($end[0], $end[1])->setNext($start[0], $end[1])->close(); $height = $start[1] - $end[1]; $mock->expects($this->atLeastOnce())->method('getBoundary')->will($this->returnValue($boundary)); $mock->expects($this->any())->method('getHeight')->will($this->returnValue($height)); if ($translate) { $mock->expects($this->atLeastOnce())->method('translate'); } return $mock; }