# HG changeset patch # User IBBoard # Date 1254855565 0 # Node ID f3bb5b77a7e4a510f649f25c32e7b7fb5d88df23 # Parent 966ba575d4e63998b3bf544182d7f5338009c218 Re #24: Add "limit" objects that can be used for numeric limits * Add simple rounded limit diff -r 966ba575d4e6 -r f3bb5b77a7e4 IBBoard.csproj --- a/IBBoard.csproj Tue Oct 06 18:49:04 2009 +0000 +++ b/IBBoard.csproj Tue Oct 06 18:59:25 2009 +0000 @@ -129,6 +129,7 @@ + diff -r 966ba575d4e6 -r f3bb5b77a7e4 Limits/SimpleRoundedPercentageLimit.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Limits/SimpleRoundedPercentageLimit.cs Tue Oct 06 18:59:25 2009 +0000 @@ -0,0 +1,38 @@ +// This file (SimpleRoundedPercentageLimit.cs) is a part of the IBBoard project and is copyright 2009 IBBoard +// +// The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license. + +using System; +using IBBoard.CustomMath; + +namespace IBBoard +{ + /// + /// A percentage-based limit that always either rounds up or down to the closest integer + /// + public class SimpleRoundedPercentageLimit + { + private double limit; + private bool roundUp; + + public SimpleRoundedPercentageLimit (double percentageLimit, bool roundFractionUp) + { + limit = percentageLimit; + roundUp = roundFractionUp; + } + + /// + /// Gets the limited number, based on the percentage limit that this Limit represents and the rounding direction + /// + /// + /// The maximum size + /// + /// + /// size or the numeric limit this object was created with, whichever is smaller. + /// + public int GetLimit(int size) + { + return (int)IBBMath.Round(size * limit / 100, roundUp); + } + } +}