Skip to content

Commit

Permalink
Fixed NaN bug when min/max is same value.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmowrer committed Oct 7, 2012
1 parent b9ad54d commit 83e88d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -100,7 +100,9 @@ package com.patrickmowrer.components.supportClasses

public function getNearestValidRatioFromValue(value:Number):Number
{
return (getNearestValidValueTo(value) - minimum) / boundsDelta;
var divisor:Number = boundsDelta == 0 ? 1 : boundsDelta;

return (getNearestValidValueTo(value) - minimum) / divisor;
}

public function getNearestValidValueTo(value:Number):Number
Expand Down
9 changes: 9 additions & 0 deletions test/src/com/patrickmowrer/components/test/ValueRangeTest.as
Expand Up @@ -111,5 +111,14 @@ package com.patrickmowrer.components.test
assertThat(valueRange.roundToNearestGreaterInterval(7), equalTo(7));
assertThat(valueRange.roundToNearestGreaterInterval(-3.999999), equalTo(-1));
}

[Test]
public function returnsValidRatioWhenMinAndMaxAreSameNumber():void
{
valueRange.minimum = 100;
valueRange.maximum = 100;

assertThat(valueRange.getNearestValidRatioFromValue(100), equalTo(0));
}
}
}

0 comments on commit 83e88d5

Please sign in to comment.