Fixing indents and braces.
This commit is contained in:
parent
f738a42e11
commit
8d7cab032f
1 changed files with 323 additions and 333 deletions
|
@ -60,293 +60,294 @@ namespace LSLEditor
|
|||
Whisper, Say, Shout, OwnerSay, RegionSay, RegionSayTo
|
||||
}
|
||||
|
||||
public partial class SecondLife
|
||||
{
|
||||
// Make friends with my host
|
||||
public SecondLifeHost host;
|
||||
public partial class SecondLife
|
||||
{
|
||||
// Make friends with my host
|
||||
public SecondLifeHost host;
|
||||
|
||||
#region members
|
||||
// Random generator
|
||||
private Random m_random;
|
||||
#region members
|
||||
// Random generator
|
||||
private Random m_random;
|
||||
|
||||
private DateTime m_DateTimeScriptStarted;
|
||||
private DateTime m_DateTimeScriptStarted;
|
||||
|
||||
private Boolean m_AllowDrop = false;
|
||||
private Hashtable m_LandPassList;
|
||||
private Boolean m_AllowDrop = false;
|
||||
private Hashtable m_LandPassList;
|
||||
|
||||
private Hashtable m_LandBanList;
|
||||
private Hashtable m_LandBanList;
|
||||
|
||||
private Float m_Volume;
|
||||
private Float m_Volume;
|
||||
|
||||
private String m_ObjectName;
|
||||
private String m_ObjectName;
|
||||
private String m_ParcelMusicURL;
|
||||
private vector m_pos;
|
||||
private rotation m_rot;
|
||||
private rotation m_rotlocal;
|
||||
private vector m_scale;
|
||||
private String m_SitText;
|
||||
private Float m_SoundRadius;
|
||||
private vector m_pos;
|
||||
private rotation m_rot;
|
||||
private rotation m_rotlocal;
|
||||
private vector m_scale;
|
||||
private String m_SitText;
|
||||
private Float m_SoundRadius;
|
||||
|
||||
private vector m_RegionCorner;
|
||||
private vector m_RegionCorner;
|
||||
|
||||
private integer m_start_parameter;
|
||||
private integer m_start_parameter;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
public vector GetLocalPos
|
||||
{
|
||||
// TODO change this to use a call to llGetLocalPos specifying NOT to be Verbose. After all functions have been changed to allow verbose/silent option.
|
||||
get { return m_pos; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region constructor
|
||||
public SecondLife()
|
||||
{
|
||||
host = null;
|
||||
m_random = new Random();
|
||||
m_DateTimeScriptStarted = DateTime.Now.ToUniversalTime();
|
||||
m_LandPassList = new Hashtable();
|
||||
m_LandBanList = new Hashtable();
|
||||
m_Volume = 0.0;
|
||||
m_ObjectName = null;
|
||||
m_pos = new vector(127, 128, 20);
|
||||
m_rot = rotation.ZERO_ROTATION;
|
||||
m_rotlocal = rotation.ZERO_ROTATION;
|
||||
m_scale = vector.ZERO_VECTOR;
|
||||
m_SitText = "sittext";
|
||||
m_SoundRadius = 1.0;
|
||||
m_start_parameter = 0;
|
||||
{
|
||||
host = null;
|
||||
m_random = new Random();
|
||||
m_DateTimeScriptStarted = DateTime.Now.ToUniversalTime();
|
||||
m_LandPassList = new Hashtable();
|
||||
m_LandBanList = new Hashtable();
|
||||
m_Volume = 0.0;
|
||||
m_ObjectName = null;
|
||||
m_pos = new vector(127, 128, 20);
|
||||
m_rot = rotation.ZERO_ROTATION;
|
||||
m_rotlocal = rotation.ZERO_ROTATION;
|
||||
m_scale = vector.ZERO_VECTOR;
|
||||
m_SitText = "sittext";
|
||||
m_SoundRadius = 1.0;
|
||||
m_start_parameter = 0;
|
||||
|
||||
m_RegionCorner = vector.ZERO_VECTOR;
|
||||
}
|
||||
#endregion
|
||||
m_RegionCorner = vector.ZERO_VECTOR;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region internal routines
|
||||
private void Verbose(string strLine, params object[] parameters)
|
||||
{
|
||||
if (parameters.Length == 0)
|
||||
host.VerboseMessage(strLine);
|
||||
else
|
||||
host.VerboseMessage(string.Format(strLine, parameters));
|
||||
}
|
||||
#region internal routines
|
||||
private void Verbose(string strLine, params object[] parameters)
|
||||
{
|
||||
if (parameters.Length == 0) {
|
||||
host.VerboseMessage(strLine);
|
||||
} else {
|
||||
host.VerboseMessage(string.Format(strLine, parameters));
|
||||
}
|
||||
}
|
||||
|
||||
private void Chat(integer channel, string message, CommunicationType how)
|
||||
{
|
||||
host.Chat(host, channel, host.GetObjectName(), host.GetKey(), message, how);
|
||||
}
|
||||
private void Chat(integer iChannel, string sText, CommunicationType ctHow)
|
||||
{
|
||||
host.Chat(host, iChannel, host.GetObjectName(), host.GetKey(), sText, ctHow);
|
||||
}
|
||||
|
||||
public void state(string strStateName)
|
||||
{
|
||||
Verbose("state->" + strStateName);
|
||||
host.State(strStateName, false);
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
System.Windows.Forms.MessageBox.Show("If you see this, something is wrong", "Oops...");
|
||||
}
|
||||
#endregion
|
||||
public void state(string strStateName)
|
||||
{
|
||||
Verbose("state->" + strStateName);
|
||||
host.State(strStateName, false);
|
||||
System.Threading.Thread.Sleep(1000);
|
||||
System.Windows.Forms.MessageBox.Show("If you see this, something is wrong", "Oops...");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Helper Functions
|
||||
#region Helper Functions
|
||||
|
||||
#region List Functions
|
||||
#region List Functions
|
||||
|
||||
private bool CorrectIt(int length, ref int start, ref int end)
|
||||
{
|
||||
if (start < 0)
|
||||
start = length + start;
|
||||
private bool CorrectIt(int length, ref int start, ref int end)
|
||||
{
|
||||
if (start < 0) {
|
||||
start = length + start;
|
||||
}
|
||||
|
||||
if (end < 0)
|
||||
end = length + end;
|
||||
if (end < 0) {
|
||||
end = length + end;
|
||||
}
|
||||
|
||||
if (start <= end)
|
||||
{
|
||||
if (start >= length)
|
||||
return false;
|
||||
if (end < 0)
|
||||
return false;
|
||||
}
|
||||
if (start <= end) {
|
||||
if (start >= length) {
|
||||
return false;
|
||||
}
|
||||
if (end < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
start = Math.Max(0, start);
|
||||
end = Math.Min(length - 1, end);
|
||||
start = Math.Max(0, start);
|
||||
end = Math.Min(length - 1, end);
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public ArrayList RandomShuffle(ArrayList collection)
|
||||
{
|
||||
// We have to copy all items anyway, and there isn't a way to produce the items
|
||||
// on the fly that is linear. So copying to an array and shuffling it is as efficient as we can get.
|
||||
public ArrayList RandomShuffle(ArrayList collection)
|
||||
{
|
||||
// We have to copy all items anyway, and there isn't a way to produce the items
|
||||
// on the fly that is linear. So copying to an array and shuffling it is as efficient as we can get.
|
||||
|
||||
if (collection == null)
|
||||
throw new ArgumentNullException("collection");
|
||||
if (collection == null) {
|
||||
throw new ArgumentNullException("collection");
|
||||
}
|
||||
|
||||
int count = collection.Count;
|
||||
for (int i = count - 1; i >= 1; --i)
|
||||
{
|
||||
// Pick an random number 0 through i inclusive.
|
||||
int j = m_random.Next(i + 1);
|
||||
int count = collection.Count;
|
||||
for (int i = count - 1; i >= 1; --i) {
|
||||
// Pick an random number 0 through i inclusive.
|
||||
int j = m_random.Next(i + 1);
|
||||
|
||||
// Swap array[i] and array[j]
|
||||
object temp = collection[i];
|
||||
collection[i] = collection[j];
|
||||
collection[j] = temp;
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
// Swap array[i] and array[j]
|
||||
object temp = collection[i];
|
||||
collection[i] = collection[j];
|
||||
collection[j] = temp;
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
private ArrayList List2Buckets(list src, int stride)
|
||||
{
|
||||
ArrayList buckets = null;
|
||||
if ((src.Count % stride) == 0 && stride <= src.Count)
|
||||
{
|
||||
buckets = new ArrayList();
|
||||
for (int intI = 0; intI < src.Count; intI += stride)
|
||||
{
|
||||
object[] bucket = new object[stride];
|
||||
for (int intJ = 0; intJ < stride; intJ++)
|
||||
bucket[intJ] = src[intI + intJ];
|
||||
buckets.Add(bucket);
|
||||
}
|
||||
}
|
||||
return buckets;
|
||||
}
|
||||
private ArrayList List2Buckets(list src, int stride)
|
||||
{
|
||||
ArrayList buckets = null;
|
||||
if ((src.Count % stride) == 0 && stride <= src.Count) {
|
||||
buckets = new ArrayList();
|
||||
for (int intI = 0; intI < src.Count; intI += stride) {
|
||||
object[] bucket = new object[stride];
|
||||
for (int intJ = 0; intJ < stride; intJ++) {
|
||||
bucket[intJ] = src[intI + intJ];
|
||||
}
|
||||
buckets.Add(bucket);
|
||||
}
|
||||
}
|
||||
return buckets;
|
||||
}
|
||||
|
||||
private list Buckets2List(ArrayList buckets, int stride)
|
||||
{
|
||||
object[] items = new object[buckets.Count * stride];
|
||||
for (int intI = 0; intI < buckets.Count; intI++)
|
||||
{
|
||||
for (int intJ = 0; intJ < stride; intJ++)
|
||||
items[intI * stride + intJ] = ((object[])buckets[intI])[intJ];
|
||||
}
|
||||
return new list(items);
|
||||
}
|
||||
private list Buckets2List(ArrayList buckets, int stride)
|
||||
{
|
||||
object[] items = new object[buckets.Count * stride];
|
||||
for (int intI = 0; intI < buckets.Count; intI++) {
|
||||
for (int intJ = 0; intJ < stride; intJ++) {
|
||||
items[intI * stride + intJ] = ((object[])buckets[intI])[intJ];
|
||||
}
|
||||
}
|
||||
return new list(items);
|
||||
}
|
||||
|
||||
private class BucketComparer : IComparer
|
||||
{
|
||||
private integer ascending;
|
||||
public BucketComparer(integer ascending)
|
||||
{
|
||||
this.ascending = ascending;
|
||||
}
|
||||
public int Compare(object x, object y)
|
||||
{
|
||||
object[] xx = x as object[];
|
||||
object[] yy = y as object[];
|
||||
private class BucketComparer : IComparer
|
||||
{
|
||||
private integer ascending;
|
||||
public BucketComparer(integer ascending)
|
||||
{
|
||||
this.ascending = ascending;
|
||||
}
|
||||
public int Compare(object x, object y)
|
||||
{
|
||||
object[] xx = x as object[];
|
||||
object[] yy = y as object[];
|
||||
|
||||
object A, B;
|
||||
object A, B;
|
||||
|
||||
if (ascending == TRUE)
|
||||
{
|
||||
A = xx[0];
|
||||
B = yy[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
B = xx[0];
|
||||
A = yy[0];
|
||||
}
|
||||
if (ascending == TRUE) {
|
||||
A = xx[0];
|
||||
B = yy[0];
|
||||
} else {
|
||||
B = xx[0];
|
||||
A = yy[0];
|
||||
}
|
||||
|
||||
string strType = A.GetType().ToString();
|
||||
string strType = A.GetType().ToString();
|
||||
|
||||
if (((A is string) && (B is string)) ||
|
||||
((A is SecondLife.String) && (B is SecondLife.String)))
|
||||
return string.Compare(A.ToString(), B.ToString());
|
||||
if (((A is string) && (B is string)) || ((A is SecondLife.String) && (B is SecondLife.String))) {
|
||||
return string.Compare(A.ToString(), B.ToString());
|
||||
}
|
||||
|
||||
if ((A is SecondLife.integer) && (B is SecondLife.integer))
|
||||
return SecondLife.integer.Compare((SecondLife.integer)A, (SecondLife.integer)B);
|
||||
if ((A is SecondLife.integer) && (B is SecondLife.integer)) {
|
||||
return SecondLife.integer.Compare((SecondLife.integer)A, (SecondLife.integer)B);
|
||||
}
|
||||
|
||||
if ((A is SecondLife.Float) && (B is SecondLife.Float))
|
||||
return SecondLife.Float.Compare((SecondLife.Float)A, (SecondLife.Float)B);
|
||||
if ((A is SecondLife.Float) && (B is SecondLife.Float)) {
|
||||
return SecondLife.Float.Compare((SecondLife.Float)A, (SecondLife.Float)B);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region String Functions
|
||||
private list ParseString(String src, list separators, list spacers, bool blnKeepNulls)
|
||||
{
|
||||
list result = new list();
|
||||
int intFrom = 0;
|
||||
string s = src;
|
||||
for (int intI = 0; intI < s.Length; intI++)
|
||||
{
|
||||
string strTmp = s.Substring(intI);
|
||||
bool blnFound = false;
|
||||
for (int intJ = 0; intJ < separators.Count; intJ++)
|
||||
{
|
||||
string strSeparator = separators[intJ].ToString();
|
||||
if (strSeparator.Length == 0)
|
||||
continue; // check this
|
||||
if (strTmp.IndexOf(strSeparator) == 0)
|
||||
{
|
||||
string strBefore = s.Substring(intFrom, intI - intFrom);
|
||||
if (strBefore != "" || blnKeepNulls)
|
||||
result.Add(strBefore);
|
||||
intI += strSeparator.Length - 1;
|
||||
intFrom = intI + 1;
|
||||
blnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#region String Functions
|
||||
private list ParseString(String src, list separators, list spacers, bool blnKeepNulls)
|
||||
{
|
||||
list result = new list();
|
||||
int intFrom = 0;
|
||||
string s = src;
|
||||
for (int intI = 0; intI < s.Length; intI++) {
|
||||
string strTmp = s.Substring(intI);
|
||||
bool blnFound = false;
|
||||
for (int intJ = 0; intJ < separators.Count; intJ++) {
|
||||
string strSeparator = separators[intJ].ToString();
|
||||
if (strSeparator.Length == 0) {
|
||||
continue; // check this
|
||||
}
|
||||
if (strTmp.IndexOf(strSeparator) == 0) {
|
||||
string strBefore = s.Substring(intFrom, intI - intFrom);
|
||||
if (strBefore != "" || blnKeepNulls) {
|
||||
result.Add(strBefore);
|
||||
}
|
||||
intI += strSeparator.Length - 1;
|
||||
intFrom = intI + 1;
|
||||
blnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (blnFound)
|
||||
continue;
|
||||
if (blnFound) continue;
|
||||
|
||||
for (int intJ = 0; intJ < spacers.Count; intJ++)
|
||||
{
|
||||
string strSpacer = spacers[intJ].ToString();
|
||||
if (strSpacer.Length == 0)
|
||||
continue; // check this
|
||||
if (strTmp.IndexOf(strSpacer) == 0)
|
||||
{
|
||||
string strBefore = s.Substring(intFrom, intI - intFrom);
|
||||
if (strBefore != "" || blnKeepNulls)
|
||||
result.Add(strBefore);
|
||||
result.Add(strSpacer);
|
||||
intI += strSpacer.Length - 1;
|
||||
intFrom = intI + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
string strLast = s.Substring(intFrom);
|
||||
if (strLast != "" || blnKeepNulls)
|
||||
result.Add(strLast);
|
||||
return result;
|
||||
}
|
||||
for (int intJ = 0; intJ < spacers.Count; intJ++) {
|
||||
string strSpacer = spacers[intJ].ToString();
|
||||
if (strSpacer.Length == 0) {
|
||||
continue; // check this
|
||||
}
|
||||
if (strTmp.IndexOf(strSpacer) == 0) {
|
||||
string strBefore = s.Substring(intFrom, intI - intFrom);
|
||||
if (strBefore != "" || blnKeepNulls) {
|
||||
result.Add(strBefore);
|
||||
}
|
||||
result.Add(strSpacer);
|
||||
intI += strSpacer.Length - 1;
|
||||
intFrom = intI + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
string strLast = s.Substring(intFrom);
|
||||
if (strLast != "" || blnKeepNulls) {
|
||||
result.Add(strLast);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private string StringToBase64(string str)
|
||||
{
|
||||
byte[] data = Encoding.UTF8.GetBytes(str);
|
||||
return Convert.ToBase64String(data);
|
||||
}
|
||||
private string StringToBase64(string str)
|
||||
{
|
||||
byte[] data = Encoding.UTF8.GetBytes(str);
|
||||
return Convert.ToBase64String(data);
|
||||
}
|
||||
|
||||
private string Base64ToString(string str)
|
||||
{
|
||||
byte[] data = Convert.FromBase64String(str);
|
||||
int intLen = Array.IndexOf(data, (byte)0x00);
|
||||
if (intLen < 0)
|
||||
intLen = data.Length;
|
||||
return Encoding.UTF8.GetString(data, 0, intLen);
|
||||
}
|
||||
private string Base64ToString(string str)
|
||||
{
|
||||
byte[] data = Convert.FromBase64String(str);
|
||||
int intLen = Array.IndexOf(data, (byte)0x00);
|
||||
if (intLen < 0) {
|
||||
intLen = data.Length;
|
||||
}
|
||||
return Encoding.UTF8.GetString(data, 0, intLen);
|
||||
}
|
||||
|
||||
private int LookupBase64(string s, int intIndex)
|
||||
{
|
||||
if (intIndex < s.Length)
|
||||
{
|
||||
int intReturn = FastLookupBase64[s[intIndex]];
|
||||
if (intReturn == 0)
|
||||
if (s[intIndex] != 'A')
|
||||
throw new Exception();
|
||||
return intReturn;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
private int LookupBase64(string s, int intIndex)
|
||||
{
|
||||
if (intIndex < s.Length) {
|
||||
int intReturn = FastLookupBase64[s[intIndex]];
|
||||
if (intReturn == 0) {
|
||||
if (s[intIndex] != 'A') {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
return intReturn;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static readonly int[] FastLookupBase64 =
|
||||
{// 0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
|
@ -366,109 +367,98 @@ namespace LSLEditor
|
|||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // D0
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // E0
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // F0
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Math Functions
|
||||
#region Math Functions
|
||||
private integer ModPow1(integer a, integer b, integer c)
|
||||
{
|
||||
return (int)Math.Pow((int)a, (int)b & (int)0xffff) % (int)c;
|
||||
}
|
||||
|
||||
private integer ModPow2(integer x, integer y, integer m)
|
||||
{
|
||||
if (!x) return 0;
|
||||
integer k = 1 + (int)Math.Ceiling(Math.Log(Math.Abs(x)) / 0.69314718055994530941723212145818);//ceil(log2(x))
|
||||
integer w = 32;
|
||||
integer p = w / k;
|
||||
integer r = y / p;
|
||||
integer f = y % p;
|
||||
integer z = 1;
|
||||
if (r) z = ModPow2(ModPow1(x, p, m), r, m);
|
||||
if (f) z = (z * ModPow1(x, f, m)) % m;
|
||||
return z;
|
||||
}
|
||||
#endregion Math Functions
|
||||
|
||||
private integer ModPow1(integer a, integer b, integer c)
|
||||
{
|
||||
return (int)Math.Pow((int)a, (int)b & (int)0xffff) % (int)c;
|
||||
}
|
||||
private List<double> GetListOfNumbers(list input)
|
||||
{
|
||||
List<double> result = new List<double>();
|
||||
for (int intI = 0; intI < input.Count; intI++) {
|
||||
object objI = input[intI];
|
||||
string strType = objI.GetType().ToString().Replace("LSLEditor.SecondLife+", "");
|
||||
switch (strType) {
|
||||
case "Float":
|
||||
result.Add(Convert.ToDouble((Float)objI));
|
||||
break;
|
||||
case "System.Int32":
|
||||
result.Add(Convert.ToDouble((int)objI));
|
||||
break;
|
||||
case "System.Double":
|
||||
result.Add(Convert.ToDouble((double)objI));
|
||||
break;
|
||||
case "integer":
|
||||
result.Add(Convert.ToDouble((integer)objI));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private integer ModPow2(integer x, integer y, integer m)
|
||||
{
|
||||
if (!x) return 0;
|
||||
integer k = 1 + (int)Math.Ceiling(Math.Log(Math.Abs(x)) / 0.69314718055994530941723212145818);//ceil(log2(x))
|
||||
integer w = 32;
|
||||
integer p = w / k;
|
||||
integer r = y / p;
|
||||
integer f = y % p;
|
||||
integer z = 1;
|
||||
if (r) z = ModPow2(ModPow1(x, p, m), r, m);
|
||||
if (f) z = (z * ModPow1(x, f, m)) % m;
|
||||
return z;
|
||||
}
|
||||
private double GetAverage(double[] data)
|
||||
{
|
||||
try {
|
||||
double DataTotal = 0;
|
||||
for (int i = 0; i < data.Length; i++) {
|
||||
DataTotal += data[i];
|
||||
}
|
||||
return SafeDivide(DataTotal, data.Length);
|
||||
} catch (Exception) { throw; }
|
||||
}
|
||||
|
||||
#endregion Math Functions
|
||||
public double GetStandardDeviation(double[] num)
|
||||
{
|
||||
double Sum = 0.0, SumOfSqrs = 0.0;
|
||||
for (int i = 0; i < num.Length; i++) {
|
||||
Sum += num[i];
|
||||
SumOfSqrs += Math.Pow(num[i], 2);
|
||||
}
|
||||
double topSum = (num.Length * SumOfSqrs) - (Math.Pow(Sum, 2));
|
||||
double n = (double)num.Length;
|
||||
return Math.Sqrt(topSum / (n * (n - 1)));
|
||||
}
|
||||
|
||||
private List<double> GetListOfNumbers(list input)
|
||||
{
|
||||
List<double> result = new List<double>();
|
||||
for (int intI = 0; intI < input.Count; intI++)
|
||||
{
|
||||
object objI = input[intI];
|
||||
string strType = objI.GetType().ToString().Replace("LSLEditor.SecondLife+", "");
|
||||
switch (strType)
|
||||
{
|
||||
case "Float":
|
||||
result.Add(Convert.ToDouble((Float)objI));
|
||||
break;
|
||||
case "System.Int32":
|
||||
result.Add(Convert.ToDouble((int)objI));
|
||||
break;
|
||||
case "System.Double":
|
||||
result.Add(Convert.ToDouble((double)objI));
|
||||
break;
|
||||
case "integer":
|
||||
result.Add(Convert.ToDouble((integer)objI));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private double SafeDivide(double value1, double value2)
|
||||
{
|
||||
double ret = 0;
|
||||
try {
|
||||
if ((value1 == 0) || (value2 == 0)) { return ret; }
|
||||
ret = value1 / value2;
|
||||
} catch { }
|
||||
return ret;
|
||||
}
|
||||
|
||||
private double GetAverage(double[] data)
|
||||
{
|
||||
try
|
||||
{
|
||||
double DataTotal = 0;
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
{
|
||||
DataTotal += data[i];
|
||||
}
|
||||
return SafeDivide(DataTotal, data.Length);
|
||||
}
|
||||
catch (Exception) { throw; }
|
||||
}
|
||||
|
||||
public double GetStandardDeviation(double[] num)
|
||||
{
|
||||
double Sum = 0.0, SumOfSqrs = 0.0;
|
||||
for (int i = 0; i < num.Length; i++)
|
||||
{
|
||||
Sum += num[i];
|
||||
SumOfSqrs += Math.Pow(num[i], 2);
|
||||
}
|
||||
double topSum = (num.Length * SumOfSqrs) - (Math.Pow(Sum, 2));
|
||||
double n = (double)num.Length;
|
||||
return Math.Sqrt(topSum / (n * (n - 1)));
|
||||
}
|
||||
|
||||
private double SafeDivide(double value1, double value2)
|
||||
{
|
||||
double ret = 0;
|
||||
try
|
||||
{
|
||||
if ((value1 == 0) || (value2 == 0)) { return ret; }
|
||||
ret = value1 / value2;
|
||||
}
|
||||
catch { }
|
||||
return ret;
|
||||
}
|
||||
|
||||
private byte HexToInt(byte b)
|
||||
{
|
||||
if (b >= '0' && b <= '9')
|
||||
return (byte)(b - '0');
|
||||
else if ((b >= 'a' && b <= 'f') || (b >= 'A' && b <= 'F'))
|
||||
return (byte)((b & 0x5f) - 0x37);
|
||||
else
|
||||
return 0; // error
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
private byte HexToInt(byte b)
|
||||
{
|
||||
if (b >= '0' && b <= '9') {
|
||||
return (byte)(b - '0');
|
||||
} else if ((b >= 'a' && b <= 'f') || (b >= 'A' && b <= 'F')) {
|
||||
return (byte)((b & 0x5f) - 0x37);
|
||||
} else {
|
||||
return 0; // error
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue