patternphpMinor
Finding similarities between images
Viewed 0 times
similaritiesimagesbetweenfinding
Problem
I've posted here before and got pretty helpful reviews. How does my code look now? To keep it really helpful, I just copied this from the middle of one of my projects.
= $c-2 && $color Solution
Since your question is about coding style, consider to adhere to PSR-2.
Your color comparision function is bloated. 'If the expression is true, then return true, else, if the expression is false, then return false.' Just return the expression.
Next, I'd make the literal '2' variable, and add some DocBlock documentation:
Your color comparision function is bloated. 'If the expression is true, then return true, else, if the expression is false, then return false.' Just return the expression.
return ($color >= $c-2 && $color <= $c+2);Next, I'd make the literal '2' variable, and add some DocBlock documentation:
/**
* Check if two color components are similar
*
* @param int $color The first color component's value
* @param int $c The second color component's value
* @param int $dist The maximum difference for two values to be considered equal
*
* @return boolean True, if the color components are similar.
*/
function colorComp($color, $c, $dist)
{
return ($color >= $c-$dist && $color <= $c+$dist);
}Code Snippets
return ($color >= $c-2 && $color <= $c+2);/**
* Check if two color components are similar
*
* @param int $color The first color component's value
* @param int $c The second color component's value
* @param int $dist The maximum difference for two values to be considered equal
*
* @return boolean True, if the color components are similar.
*/
function colorComp($color, $c, $dist)
{
return ($color >= $c-$dist && $color <= $c+$dist);
}Context
StackExchange Code Review Q#25660, answer score: 5
Revisions (0)
No revisions yet.