Skip to content

Commit

Permalink
Simplify and cleanup in small areas (#2755)
Browse files Browse the repository at this point in the history
* remove redundancy in FlxAnimation.play()

`finished` must be false in order for this to run which sets it to false again.

* remove redundancy in FlxColor.get_hue()

`hueRad` calculated this value already so, for readability, we don't need to put the whole formula again.

* Saturation isn't used in FlxColor.setHSChromaMatch()
  • Loading branch information
CrazyInfin8 committed Apr 5, 2023
1 parent 689f21f commit 38d1144
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion flixel/animation/FlxAnimation.hx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class FlxAnimation extends FlxBaseAnimation
if (!Force && !finished && reversed == Reversed)
{
paused = false;
finished = false;
return;
}

Expand Down
8 changes: 4 additions & 4 deletions flixel/util/FlxColor.hx
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ abstract FlxColor(Int) from Int from UInt to Int to UInt
{
var chroma = Brightness * Saturation;
var match = Brightness - chroma;
return setHSChromaMatch(Hue, Saturation, chroma, match, Alpha);
return setHueChromaMatch(Hue, chroma, match, Alpha);
}

/**
Expand All @@ -531,13 +531,13 @@ abstract FlxColor(Int) from Int from UInt to Int to UInt
{
var chroma = (1 - Math.abs(2 * Lightness - 1)) * Saturation;
var match = Lightness - chroma / 2;
return setHSChromaMatch(Hue, Saturation, chroma, match, Alpha);
return setHueChromaMatch(Hue, chroma, match, Alpha);
}

/**
* Private utility function to perform common operations between setHSB and setHSL
*/
inline function setHSChromaMatch(Hue:Float, Saturation:Float, Chroma:Float, Match:Float, Alpha:Float):FlxColor
inline function setHueChromaMatch(Hue:Float, Chroma:Float, Match:Float, Alpha:Float):FlxColor
{
Hue %= 360;
var hueD = Hue / 60;
Expand Down Expand Up @@ -730,7 +730,7 @@ abstract FlxColor(Int) from Int from UInt to Int to UInt
var hue:Float = 0;
if (hueRad != 0)
{
hue = 180 / Math.PI * Math.atan2(Math.sqrt(3) * (greenFloat - blueFloat), 2 * redFloat - greenFloat - blueFloat);
hue = 180 / Math.PI * hueRad;
}

return hue < 0 ? hue + 360 : hue;
Expand Down

0 comments on commit 38d1144

Please sign in to comment.