Skip to content

Commit

Permalink
Renamed GenericImpl into GenericEaseImpl
Browse files Browse the repository at this point in the history
Moved GenericEaseImpl to GenericEaseImpl.cs
Updated documentation
  • Loading branch information
Jewelots committed Sep 27, 2014
1 parent 889145e commit a37afd7
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 118 deletions.
Binary file modified doc/Documentation.chm
Binary file not shown.
1 change: 1 addition & 0 deletions src/Betwixt/Betwixt.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<ItemGroup>
<Compile Include="Ease.cs" />
<Compile Include="EaseImplementations.cs" />
<Compile Include="GenericEaseImpl.cs" />
<Compile Include="GenericMath.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
6 changes: 3 additions & 3 deletions src/Betwixt/Ease.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static float InOut(float percent, EaseFunc Out)
[UsedImplicitly]
public static IEase CreateFromIn(EaseFunc easeInFunc, EaseFunc easeInOutFunc = null)
{
return GenericImpl.FromIn(easeInFunc, easeInOutFunc);
return GenericEaseImpl.FromIn(easeInFunc, easeInOutFunc);
}

/// <summary>
Expand All @@ -174,7 +174,7 @@ public static IEase CreateFromIn(EaseFunc easeInFunc, EaseFunc easeInOutFunc = n
[UsedImplicitly]
public static IEase CreateFromOut(EaseFunc easeOutFunc, EaseFunc easeInOutFunc = null)
{
return GenericImpl.FromOut(easeOutFunc, easeInOutFunc);
return GenericEaseImpl.FromOut(easeOutFunc, easeInOutFunc);
}

/// <summary>
Expand All @@ -191,7 +191,7 @@ public static IEase CreateFromOut(EaseFunc easeOutFunc, EaseFunc easeInOutFunc =
[UsedImplicitly]
public static IEase Create(EaseFunc easeInFunc, EaseFunc easeOutFunc, EaseFunc easeInOutFunc = null)
{
return GenericImpl.From(easeInFunc, easeOutFunc, easeInOutFunc);
return GenericEaseImpl.From(easeInFunc, easeOutFunc, easeInOutFunc);
}
}
}
Expand Down
115 changes: 0 additions & 115 deletions src/Betwixt/EaseImplementations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,123 +4,9 @@

namespace Betwixt
{
/// <summary>
/// Generic Implementation to help create IEase function sets, and pipes ease functions to eachother automatically
/// </summary>
[UsedImplicitly]
internal class GenericImpl : IEase
{
private readonly EaseFunc _easeInFunc;
private readonly EaseFunc _easeOutFunc;
private readonly EaseFunc _easeInOutFunc;

private GenericImpl(EaseFunc easeInFunc, EaseFunc easeOutFunc, EaseFunc easeInOutFunc)
{
if (easeInFunc == null && easeOutFunc == null)
{
throw new Exception("Both in and out arguments none, this should not happen! This is bad.");
}

// If there's no In function, create one generically (from Out)
_easeInFunc = easeInFunc ?? GenericIn;

// If there's no Out function, create one generically (from In)
_easeOutFunc = easeOutFunc ?? GenericOut;

// If there's no InOut function, create one generically (from Out)
_easeInOutFunc = easeInOutFunc ?? GenericInOut;
}

/// <summary>
/// Create a new Generic Implementation set from an Out ease, and an optional InOut ease.
/// </summary>
/// <param name="easeOutFunc">Out ease function</param>
/// <param name="easeInOutFunc">Optional InOut ease function</param>
/// <returns>A new Generic Ease Set</returns>
public static GenericImpl FromOut(EaseFunc easeOutFunc, EaseFunc easeInOutFunc = null)
{
return new GenericImpl(null, easeOutFunc, easeInOutFunc);
}

/// <summary>
/// Create a new Generic Implementation set from an In ease, and an optional InOut ease.
/// </summary>
/// <param name="easeInFunc">In ease function</param>
/// <param name="easeInOutFunc">Optional InOut ease function</param>
/// <returns>A new Generic Ease Set</returns>
public static GenericImpl FromIn(EaseFunc easeInFunc, EaseFunc easeInOutFunc = null)
{
return new GenericImpl(easeInFunc, null, easeInOutFunc);
}

/// <summary>
/// Create a new Generic Implementation set from a full set of ease functions, and an optional InOut ease.
/// </summary>
/// <param name="easeInFunc">In ease function</param>
/// <param name="easeOutFunc">Out ease function</param>
/// <param name="easeInOutFunc">Optional InOut ease function</param>
/// <returns>A new Generic Ease Set</returns>
public static GenericImpl From(EaseFunc easeInFunc, EaseFunc easeOutFunc, EaseFunc easeInOutFunc = null)
{
return new GenericImpl(easeInFunc, easeOutFunc, easeInOutFunc);
}

#region Generic Non-Specified Functions
/// <summary>
/// Create an In ease from an Out ease
/// </summary>
private float GenericIn(float percent)
{
return Ease.Generic.Reverse(percent, Out);
}

/// <summary>
/// Create an Out ease from an In ease
/// </summary>
private float GenericOut(float percent)
{
return Ease.Generic.Reverse(percent, In);
}

/// <summary>
/// Create an InOut ease from an Out ease
/// </summary>
private float GenericInOut(float percent)
{
return Ease.Generic.InOut(percent, Out);
}
#endregion

/// <summary>
/// Call the stored Ease In function
/// </summary>
public float In(float percent)
{
return _easeInFunc(percent);
}

/// <summary>
/// Call the stored Ease Out function
/// </summary>
public float Out(float percent)
{
return _easeOutFunc(percent);
}

/// <summary>
/// Call the stored Ease InOut function
/// </summary>
public float InOut(float percent)
{
return _easeInOutFunc(percent);
}
}

// Below are implementations.
// The implementations only specify an In or an Out (depending on which is easier to write)
// And the rest of the set is created via Generic Ease Creation

#region Ease Implementations
/// <summary>
/// Implementation of Quadratic Ease
/// </summary>
Expand Down Expand Up @@ -254,5 +140,4 @@ public static float Out(float percent)
return (float)(s * Math.Pow(percent, 2) + .984375);
}
}
#endregion
}
118 changes: 118 additions & 0 deletions src/Betwixt/GenericEaseImpl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System;

using Betwixt.Annotations;

namespace Betwixt
{
/// <summary>
/// Generic Implementation to help create IEase function sets, and pipes ease functions to eachother automatically
/// </summary>
[UsedImplicitly]
internal class GenericEaseImpl : IEase
{
private readonly EaseFunc _easeInFunc;
private readonly EaseFunc _easeOutFunc;
private readonly EaseFunc _easeInOutFunc;

private GenericEaseImpl(EaseFunc easeInFunc, EaseFunc easeOutFunc, EaseFunc easeInOutFunc)
{
if (easeInFunc == null && easeOutFunc == null)
{
throw new Exception("Both in and out arguments none, this should not happen! This is bad.");
}

// If there's no In function, create one generically (from Out)
_easeInFunc = easeInFunc ?? GenericIn;

// If there's no Out function, create one generically (from In)
_easeOutFunc = easeOutFunc ?? GenericOut;

// If there's no InOut function, create one generically (from Out)
_easeInOutFunc = easeInOutFunc ?? GenericInOut;
}

/// <summary>
/// Create a new Generic Implementation set from an Out ease, and an optional InOut ease.
/// </summary>
/// <param name="easeOutFunc">Out ease function</param>
/// <param name="easeInOutFunc">Optional InOut ease function</param>
/// <returns>A new Generic Ease Set</returns>
public static GenericEaseImpl FromOut(EaseFunc easeOutFunc, EaseFunc easeInOutFunc = null)
{
return new GenericEaseImpl(null, easeOutFunc, easeInOutFunc);
}

/// <summary>
/// Create a new Generic Implementation set from an In ease, and an optional InOut ease.
/// </summary>
/// <param name="easeInFunc">In ease function</param>
/// <param name="easeInOutFunc">Optional InOut ease function</param>
/// <returns>A new Generic Ease Set</returns>
public static GenericEaseImpl FromIn(EaseFunc easeInFunc, EaseFunc easeInOutFunc = null)
{
return new GenericEaseImpl(easeInFunc, null, easeInOutFunc);
}

/// <summary>
/// Create a new Generic Implementation set from a full set of ease functions, and an optional InOut ease.
/// </summary>
/// <param name="easeInFunc">In ease function</param>
/// <param name="easeOutFunc">Out ease function</param>
/// <param name="easeInOutFunc">Optional InOut ease function</param>
/// <returns>A new Generic Ease Set</returns>
public static GenericEaseImpl From(EaseFunc easeInFunc, EaseFunc easeOutFunc, EaseFunc easeInOutFunc = null)
{
return new GenericEaseImpl(easeInFunc, easeOutFunc, easeInOutFunc);
}

#region Generic Non-Specified Functions
/// <summary>
/// Create an In ease from an Out ease
/// </summary>
private float GenericIn(float percent)
{
return Ease.Generic.Reverse(percent, Out);
}

/// <summary>
/// Create an Out ease from an In ease
/// </summary>
private float GenericOut(float percent)
{
return Ease.Generic.Reverse(percent, In);
}

/// <summary>
/// Create an InOut ease from an Out ease
/// </summary>
private float GenericInOut(float percent)
{
return Ease.Generic.InOut(percent, Out);
}
#endregion

/// <summary>
/// Call the stored Ease In function
/// </summary>
public float In(float percent)
{
return _easeInFunc(percent);
}

/// <summary>
/// Call the stored Ease Out function
/// </summary>
public float Out(float percent)
{
return _easeOutFunc(percent);
}

/// <summary>
/// Call the stored Ease InOut function
/// </summary>
public float InOut(float percent)
{
return _easeInOutFunc(percent);
}
}
}

0 comments on commit a37afd7

Please sign in to comment.