using System;
using System.Collections.Generic;
using System.Text;

namespace Vortex.Utils {

	/// <summary>
	/// Flow Utils contains usefull methods for calculating function values used by flow control logic or animation
	/// </summary>
	public static class FlowUtils {

		/// <summary>
		/// Calculates some "ratio" (0...1) for two phase process: fade in/fade out. If value before split it is growing, after - decreasing.
		/// </summary>
		/// <param name="value">The curent value in range 0 .. 1.</param>
		/// <param name="splitValue">The split value in range 0 .. 1.</param>
		/// <returns>Phase ratio in range 0 .. 1</returns>
		public static float Get2PhaseRatio(float value, float splitValue) {
			if (value <= splitValue) {
				return value / splitValue;
			} else {
				return 1 - (value - splitValue) / (1 - splitValue);
			}
		}

		/// <summary>
		/// Calculates some "ratio" (0...1) for two phase process: fade in/fade out. If value before split it is growing, after - decreasing.
		/// </summary>
		/// <param name="value">The curent value in range 0 .. 1.</param>
		/// <param name="splitBeforePlainPoint">The split before plain point in range 0 .. 1..</param>
		/// <param name="splitAfterPlainPoint">The split after plain point in range 0 .. 1..</param>
		/// <returns>Phase ratio in range 0 .. 1</returns>
		public static float Get3PhaseRatio(float value, float splitBeforePlainPoint, float splitAfterPlainPoint) {
			if (value <= splitBeforePlainPoint) {
				return value / splitBeforePlainPoint;
			} else if (value <= splitAfterPlainPoint) {
				return 1;
			} else {
				return 1 - (value - splitAfterPlainPoint) / (1 - splitAfterPlainPoint);
			}
		}
	}
}
