add assertion for ASRelativeDimensionTypePercent value to be between 0-1 (#2009)

This commit is contained in:
Hannah Troisi
2016-07-29 10:38:20 -07:00
committed by Adlai Holler
parent 6a21daa80f
commit ff2c47c415

View File

@@ -18,16 +18,21 @@ ASRelativeDimension const ASRelativeDimensionUnconstrained = {};
ASRelativeDimension ASRelativeDimensionMake(ASRelativeDimensionType type, CGFloat value)
{
if (type == ASRelativeDimensionTypePoints) { ASDisplayNodeCAssertPositiveReal(@"Points", value); }
if (type == ASRelativeDimensionTypePercent) {
ASDisplayNodeCAssert( 0 <= value && value <= 1.0, @"ASRelativeDimension percent value (%f) must be between 0 and 1.", value);
}
ASRelativeDimension dimension; dimension.type = type; dimension.value = value; return dimension;
}
ASRelativeDimension ASRelativeDimensionMakeWithPoints(CGFloat points)
{
ASDisplayNodeCAssertPositiveReal(@"Points", points);
return ASRelativeDimensionMake(ASRelativeDimensionTypePoints, points);
}
ASRelativeDimension ASRelativeDimensionMakeWithPercent(CGFloat percent)
{
ASDisplayNodeCAssert( 0 <= percent && percent <= 1.0, @"ASRelativeDimension percent value (%f) must be between 0 and 1.", percent);
return ASRelativeDimensionMake(ASRelativeDimensionTypePercent, percent);
}