Skip to content

Commit

Permalink
Implement new method ColorInterface::isClear()
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Aug 5, 2024
1 parent 5e9b4aa commit 9564d59
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Colors/Cmyk/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,14 @@ public function isTransparent(): bool
{
return false;
}

/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return false;
}
}
10 changes: 10 additions & 0 deletions src/Colors/Hsl/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,14 @@ public function isTransparent(): bool
{
return false;
}

/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return false;
}
}
10 changes: 10 additions & 0 deletions src/Colors/Hsv/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,14 @@ public function isTransparent(): bool
{
return false;
}

/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return false;
}
}
10 changes: 10 additions & 0 deletions src/Colors/Rgb/Color.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,14 @@ public function isTransparent(): bool
{
return $this->alpha()->value() < $this->alpha()->max();
}

/**
* {@inheritdoc}
*
* @see ColorInterface::isClear()
*/
public function isClear(): bool
{
return $this->alpha()->value() == 0;
}
}
7 changes: 7 additions & 0 deletions src/Interfaces/ColorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,11 @@ public function isGreyscale(): bool;
* @return bool
*/
public function isTransparent(): bool;

/**
* Determine whether the current color is completely transparent
*
* @return bool
*/
public function isClear(): bool;
}
6 changes: 6 additions & 0 deletions tests/Unit/Colors/Cmyk/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,10 @@ public function testIsTransparent(): void
$color = new Color(100, 50, 50, 0);
$this->assertFalse($color->isTransparent());
}

public function testIsClear(): void
{
$color = new Color(0, 0, 0, 0);
$this->assertFalse($color->isClear());
}
}
6 changes: 6 additions & 0 deletions tests/Unit/Colors/Hsl/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ public function testIsTransparent(): void
$color = new Color(0, 1, 0);
$this->assertFalse($color->isTransparent());
}

public function testIsClear(): void
{
$color = new Color(0, 1, 0);
$this->assertFalse($color->isClear());
}
}
6 changes: 6 additions & 0 deletions tests/Unit/Colors/Hsv/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ public function testIsTransparent(): void
$color = new Color(1, 0, 0);
$this->assertFalse($color->isTransparent());
}

public function testIsClear(): void
{
$color = new Color(0, 1, 0);
$this->assertFalse($color->isClear());
}
}
15 changes: 15 additions & 0 deletions tests/Unit/Colors/Rgb/ColorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,19 @@ public function testIsTransparent(): void
$color = new Color(255, 255, 255, 0);
$this->assertTrue($color->isTransparent());
}

public function testIsClear(): void
{
$color = new Color(255, 255, 255);
$this->assertFalse($color->isClear());

$color = new Color(255, 255, 255, 255);
$this->assertFalse($color->isClear());

$color = new Color(255, 255, 255, 85);
$this->assertFalse($color->isClear());

$color = new Color(255, 255, 255, 0);
$this->assertTrue($color->isClear());
}
}

0 comments on commit 9564d59

Please sign in to comment.