/*============================================================================= Project: SharpImage Module: siMathHelper.cs Language: C# Author: Dan Mueller Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $ Revision: $Revision: 2 $ Copyright (c) Queensland University of Technology (QUT) 2007. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =============================================================================*/ using System; using System.Collections.Generic; using System.Text; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Windows.Forms; using System.Diagnostics; using SharpImage.Main; using SharpImage.Properties; namespace SharpImage.Rendering { public class siMathHelper { /// Multiply this number by a degree to convert to a radian. /// This value taken from Common/vtkMath.h. public const double DegreesToRadians = 0.017453292; /// Multiply this number by a radian to convert to a degree. /// This value taken from Common/vtkMath.h. public const double RadiansToDegrees = 57.2957795131; /// /// Rounds the given value to the next highest power of two. /// If the value is already a power of 2, the given value is returned. /// /// An integer less than or equal to 4096 to round to the next power of two. /// public static int RoundToNextHighestPowerOfTwo(int value) { if (value > 4096) throw new ArgumentOutOfRangeException("value", "The value could not be rounded to the next highest power of two because it is too large. The value must be less than or equal to 4096."); int[] powerOfTwo = { 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 }; int index = 0; while (index < 12) { if (value <= powerOfTwo[index]) return powerOfTwo[index]; else index++; } // We should not get here return value; } } }