Skip to content

Commit

Permalink
Split SizePadding methods to separate support class;
Browse files Browse the repository at this point in the history
  • Loading branch information
onepiecefreak3 committed Jan 14, 2025
1 parent f8e046e commit 00cc91b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public ISizePaddingConfigurationBuilder To(CreatePaddedSizeDimensionDelegate dim

public ISizePaddingConfigurationBuilder ToPowerOfTwo(int steps = 1)
{
_setDelegate.Invoke(value => 2 << (int)Math.Log(value - 1, 2) << (steps - 1));
_setDelegate.Invoke(value => SizePadding.MultipleOfTwo(value, steps));
return _parent;
}

public ISizePaddingConfigurationBuilder ToMultiple(int multiple)
{
_setDelegate.Invoke(value => (value + (multiple - 1)) / multiple * multiple);
_setDelegate.Invoke(value => SizePadding.Multiple(value, multiple));
return _parent;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Kanvas/Kanvas.Debug.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Kanvas</id>
<version>2.1.4</version>
<version>2.1.5</version>
<description>A library containing image transcodings and quantizations usable in the Kuriimu2 eco-system.</description>

<authors>onepiecefreak;IcySon55</authors>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Kanvas/Kanvas.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>Kanvas</id>
<version>2.1.4</version>
<version>2.1.5</version>
<description>A library containing image transcodings and quantizations usable in the Kuriimu2 eco-system.</description>

<authors>onepiecefreak;IcySon55</authors>
Expand Down
29 changes: 29 additions & 0 deletions src/lib/Kanvas/SizePadding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Kanvas
{
public static class SizePadding
{
/// <summary>
/// Rounds up a given value to the next multiple of two.
/// </summary>
/// <param name="value">The value to round up.</param>
/// <param name="steps">The amount of power of two's to round up to.</param>
/// <returns>The rounded up value.</returns>
/// <remarks>Eg. 34 with 1 step is 64, 121 with 2 steps is 256.</remarks>
public static int MultipleOfTwo(int value, int steps)
{
return 2 << (int)Math.Log(value - 1, 2) << (steps - 1);
}

/// <summary>
/// Rounds up a given value to the next value dividable by <param name="multiple" />.
/// </summary>
/// <param name="value">The value to round up.</param>
/// <param name="multiple">The multiple to round up to.</param>
/// <returns>The rounded up value.</returns>
/// <remarks>Eg. 34 with multiple 3 is 36, 121 with multiple 6 is 126.</remarks>
public static int Multiple(int value, int multiple)
{
return (value + (multiple - 1)) / multiple * multiple;
}
}
}

0 comments on commit 00cc91b

Please sign in to comment.