|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using Mesnac.Maths;
|
|
|
|
|
|
namespace Mesnac.Math.New
|
|
|
{
|
|
|
public class Straight : IMath
|
|
|
{
|
|
|
private object NullResult = null;
|
|
|
|
|
|
public string Name
|
|
|
{
|
|
|
get { return "直线"; }
|
|
|
}
|
|
|
|
|
|
public string Caption
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.AppendLine("生成从第一个值开始,第二个值结束的int类型数据");
|
|
|
sb.AppendLine("例:");
|
|
|
sb.Append(" ").Append(Name).AppendLine("(11,20)");
|
|
|
return sb.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public object Execute(string[] parameters, object[] buff)
|
|
|
{
|
|
|
if (buff.Length == 0)
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (buff[0] == null)
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
int index = 0;
|
|
|
if (!int.TryParse(buff[0].ToString(), out index))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (parameters.Length < 2)
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
int iStart = 0;
|
|
|
int iEnd = 0;
|
|
|
if (!int.TryParse(parameters[0], out iStart))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (!int.TryParse(parameters[1], out iEnd))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (iEnd == iStart)
|
|
|
{
|
|
|
return iStart;
|
|
|
}
|
|
|
if (iEnd > iStart)
|
|
|
{
|
|
|
iStart = iStart - 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
iStart = iStart + 1;
|
|
|
}
|
|
|
int iLen = System.Math.Abs(iEnd - iStart);
|
|
|
int Result = index;
|
|
|
if (Result > iLen)
|
|
|
{
|
|
|
Result = Result % iLen;
|
|
|
if (Result == 0)
|
|
|
{
|
|
|
Result = iLen;
|
|
|
}
|
|
|
}
|
|
|
if (iEnd > iStart)
|
|
|
{
|
|
|
return iStart + Result;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return iStart - Result;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public class BrokenLine : IMath
|
|
|
{
|
|
|
private object NullResult = null;
|
|
|
|
|
|
public string Name
|
|
|
{
|
|
|
get { return "折线"; }
|
|
|
}
|
|
|
|
|
|
public string Caption
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.AppendLine("生成从第一个值开始,到达第二个值后返回第一个值结束的int类型数据");
|
|
|
sb.AppendLine("例:");
|
|
|
sb.Append(" ").Append(Name).AppendLine("(11,20)");
|
|
|
return sb.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public object Execute(string[] parameters, object[] buff)
|
|
|
{
|
|
|
if (buff.Length == 0)
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (buff[0] == null)
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
int index = 0;
|
|
|
if (!int.TryParse(buff[0].ToString(), out index))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (parameters.Length < 2)
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
int iStart = 0;
|
|
|
int iEnd = 0;
|
|
|
if (!int.TryParse(parameters[0], out iStart))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (!int.TryParse(parameters[1], out iEnd))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (iEnd == iStart)
|
|
|
{
|
|
|
return iStart;
|
|
|
}
|
|
|
if (iEnd > iStart)
|
|
|
{
|
|
|
iStart = iStart - 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
iStart = iStart + 1;
|
|
|
}
|
|
|
int iLen = System.Math.Abs(iEnd - iStart) * 2 - 2;
|
|
|
int Result = index;
|
|
|
if (Result > iLen)
|
|
|
{
|
|
|
Result = Result % iLen;
|
|
|
if (Result == 0)
|
|
|
{
|
|
|
Result = iLen;
|
|
|
}
|
|
|
}
|
|
|
if (iEnd > iStart)
|
|
|
{
|
|
|
Result = iStart + Result;
|
|
|
if (Result > iEnd)
|
|
|
{
|
|
|
Result = iEnd - (Result - iEnd);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Result = iStart - Result;
|
|
|
if (Result < iEnd)
|
|
|
{
|
|
|
Result = iEnd + iEnd - Result;
|
|
|
}
|
|
|
}
|
|
|
return Result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public class Random : IMath
|
|
|
{
|
|
|
private object NullResult = null;
|
|
|
private static System.Random random = new System.Random((int)DateTime.Now.Ticks + +System.Threading.Thread.CurrentThread.ManagedThreadId);
|
|
|
|
|
|
public string Name
|
|
|
{
|
|
|
get { return "随机数"; }
|
|
|
}
|
|
|
|
|
|
public string Caption
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.AppendLine("产生一个两个参数之间的double类型的随机数");
|
|
|
sb.AppendLine("例:");
|
|
|
sb.Append(" ").Append(Name).AppendLine("(11,20)");
|
|
|
return sb.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public object Execute(string[] parameters, object[] buff)
|
|
|
{
|
|
|
|
|
|
if (buff.Length == 0)
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (buff[0] == null)
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
int index = 0;
|
|
|
if (!int.TryParse(buff[0].ToString(), out index))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (parameters.Length < 2)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
double iStart = 0;
|
|
|
double iEnd = 0;
|
|
|
if (!double.TryParse(parameters[0], out iStart))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (!double.TryParse(parameters[1], out iEnd))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
|
|
|
random.NextDouble();
|
|
|
double d = random.NextDouble();
|
|
|
return d * (iEnd - iStart) + iStart;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public class RandomInt : IMath
|
|
|
{
|
|
|
private object NullResult = null;
|
|
|
private static System.Random random = new System.Random((int)DateTime.Now.Ticks + System.Threading.Thread.CurrentThread.ManagedThreadId);
|
|
|
|
|
|
public string Name
|
|
|
{
|
|
|
get { return "整数随机数"; }
|
|
|
}
|
|
|
|
|
|
public string Caption
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.AppendLine("产生一个两个参数之间的int类型的随机数");
|
|
|
sb.AppendLine("例:");
|
|
|
sb.Append(" ").Append(Name).AppendLine("(11,20)");
|
|
|
return sb.ToString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public object Execute(string[] parameters, object[] buff)
|
|
|
{
|
|
|
|
|
|
if (buff.Length == 0)
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (buff[0] == null)
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
int index = 0;
|
|
|
if (!int.TryParse(buff[0].ToString(), out index))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (parameters.Length < 2)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
int iStart = 0;
|
|
|
int iEnd = 0;
|
|
|
if (!int.TryParse(parameters[0], out iStart))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
if (!int.TryParse(parameters[1], out iEnd))
|
|
|
{
|
|
|
return this.NullResult;
|
|
|
}
|
|
|
random.Next();
|
|
|
int result = 0;
|
|
|
if (iStart == iEnd)
|
|
|
{
|
|
|
result = iStart;
|
|
|
}
|
|
|
if (iStart > iEnd)
|
|
|
{
|
|
|
result = random.Next(iEnd, iStart);
|
|
|
}
|
|
|
result = random.Next(iStart, iEnd);
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
}
|