Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new method ColorInterface::isClear() #1387

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}