Skip to content

Commit

Permalink
Merge pull request #9 from gstankov/rotation-status
Browse files Browse the repository at this point in the history
Rotation status property of block added.
  • Loading branch information
Padam87 authored Sep 5, 2023
2 parents 274e95a + 5414e35 commit 3360ec9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":947:{a:2:{s:7:"defects";a:7:{s:49:"Padam87\BinPacker\Tests\BinPackerTest::testSimple";i:4;s:51:"Padam87\BinPacker\Tests\BinPackerTest::testRotation";i:3;s:51:"Padam87\BinPacker\Tests\BinPackerTest::testOverflow";i:3;s:49:"Padam87\BinPacker\Tests\BinPackerTest::testGrowth";i:3;s:50:"Padam87\BinPacker\Tests\VisualizerTest::testSimple";i:5;s:54:"Padam87\BinPacker\Tests\VisualizerTest::testStepByStep";i:5;s:52:"Padam87\BinPacker\Tests\GifMakerTest::testStepByStep";i:4;}s:5:"times";a:7:{s:49:"Padam87\BinPacker\Tests\BinPackerTest::testSimple";d:0.003;s:51:"Padam87\BinPacker\Tests\BinPackerTest::testRotation";d:0;s:51:"Padam87\BinPacker\Tests\BinPackerTest::testOverflow";d:0.009;s:49:"Padam87\BinPacker\Tests\BinPackerTest::testGrowth";d:0.01;s:50:"Padam87\BinPacker\Tests\VisualizerTest::testSimple";d:0.116;s:54:"Padam87\BinPacker\Tests\VisualizerTest::testStepByStep";d:0.232;s:52:"Padam87\BinPacker\Tests\GifMakerTest::testStepByStep";d:3.206;}}}
{"version":1,"defects":[],"times":{"Padam87\\BinPacker\\Tests\\BinPackerTest::testSimple":0.237,"Padam87\\BinPacker\\Tests\\BinPackerTest::testRotation":0.011,"Padam87\\BinPacker\\Tests\\BinPackerTest::testRotationStatus":0,"Padam87\\BinPacker\\Tests\\BinPackerTest::testOverflow":0.021,"Padam87\\BinPacker\\Tests\\BinPackerTest::testGrowth":0.024}}
12 changes: 12 additions & 0 deletions src/Model/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class Block
*/
private $rotatable;

/**
* @var bool
*/
private $rotated = false;

/**
* An ID or name to identify the block for your own purposes.
*
Expand Down Expand Up @@ -76,6 +81,11 @@ public function isRotatable(): ?bool
return $this->rotatable;
}

public function isRotated()
{
return $this->rotated;
}

public function setRotatable(?bool $rotatable): self
{
$this->rotatable = $rotatable;
Expand Down Expand Up @@ -106,6 +116,8 @@ public function rotate(): self
$this->setWidth($this->getHeight());
$this->setHeight($w);

$this->rotated = !$this->rotated;

return $this;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/Functional/BinPackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ public function testRotation()
$this->assertFalse($nonRotatable->getNode() && $nonRotatable->getNode()->isUsed());
}

public function testRotationStatus()
{
$bin = new Bin(2000, 100);

$rotatable = new Block(100, 1000);

$blocks = [$rotatable];

$packer = new BinPacker();

$blocks = $packer->pack($bin, $blocks);

$this->assertTrue($rotatable->getNode() && $rotatable->isRotated());

}

public function testOverflow()
{
$bin = new Bin(1000, 1000);
Expand Down

0 comments on commit 3360ec9

Please sign in to comment.