init commit
This commit is contained in:
14
output/Libraries/AForge/AForge.csproj
Normal file
14
output/Libraries/AForge/AForge.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>AForge</AssemblyName>
|
||||
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
|
||||
<TargetFramework>net20</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<LangVersion>12.0</LangVersion>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup />
|
||||
<ItemGroup />
|
||||
<ItemGroup />
|
||||
</Project>
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
public class CommunicationBufferEventArgs : EventArgs
|
||||
{
|
||||
private readonly byte[] message;
|
||||
|
||||
private readonly int index;
|
||||
|
||||
private readonly int length;
|
||||
|
||||
public int MessageLength => length;
|
||||
|
||||
public CommunicationBufferEventArgs(byte[] message)
|
||||
{
|
||||
this.message = message;
|
||||
index = 0;
|
||||
length = message.Length;
|
||||
}
|
||||
|
||||
public CommunicationBufferEventArgs(byte[] buffer, int index, int length)
|
||||
{
|
||||
message = buffer;
|
||||
this.index = index;
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public byte[] GetMessage()
|
||||
{
|
||||
byte[] array = new byte[length];
|
||||
Array.Copy(message, index, array, 0, length);
|
||||
return array;
|
||||
}
|
||||
|
||||
public string GetMessageString()
|
||||
{
|
||||
return BitConverter.ToString(message, index, length);
|
||||
}
|
||||
}
|
||||
11
output/Libraries/AForge/AForge/ConnectionFailedException.cs
Normal file
11
output/Libraries/AForge/AForge/ConnectionFailedException.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
public class ConnectionFailedException : Exception
|
||||
{
|
||||
public ConnectionFailedException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
11
output/Libraries/AForge/AForge/ConnectionLostException.cs
Normal file
11
output/Libraries/AForge/AForge/ConnectionLostException.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
public class ConnectionLostException : Exception
|
||||
{
|
||||
public ConnectionLostException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
11
output/Libraries/AForge/AForge/DeviceBusyException.cs
Normal file
11
output/Libraries/AForge/AForge/DeviceBusyException.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
public class DeviceBusyException : Exception
|
||||
{
|
||||
public DeviceBusyException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
11
output/Libraries/AForge/AForge/DeviceErrorException.cs
Normal file
11
output/Libraries/AForge/AForge/DeviceErrorException.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
public class DeviceErrorException : Exception
|
||||
{
|
||||
public DeviceErrorException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
149
output/Libraries/AForge/AForge/DoublePoint.cs
Normal file
149
output/Libraries/AForge/AForge/DoublePoint.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
[Serializable]
|
||||
public struct DoublePoint
|
||||
{
|
||||
public double X;
|
||||
|
||||
public double Y;
|
||||
|
||||
public DoublePoint(double x, double y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public double DistanceTo(DoublePoint anotherPoint)
|
||||
{
|
||||
double num = X - anotherPoint.X;
|
||||
double num2 = Y - anotherPoint.Y;
|
||||
return Math.Sqrt(num * num + num2 * num2);
|
||||
}
|
||||
|
||||
public double SquaredDistanceTo(DoublePoint anotherPoint)
|
||||
{
|
||||
double num = X - anotherPoint.X;
|
||||
double num2 = Y - anotherPoint.Y;
|
||||
return num * num + num2 * num2;
|
||||
}
|
||||
|
||||
public static DoublePoint operator +(DoublePoint point1, DoublePoint point2)
|
||||
{
|
||||
return new DoublePoint(point1.X + point2.X, point1.Y + point2.Y);
|
||||
}
|
||||
|
||||
public static DoublePoint Add(DoublePoint point1, DoublePoint point2)
|
||||
{
|
||||
return new DoublePoint(point1.X + point2.X, point1.Y + point2.Y);
|
||||
}
|
||||
|
||||
public static DoublePoint operator -(DoublePoint point1, DoublePoint point2)
|
||||
{
|
||||
return new DoublePoint(point1.X - point2.X, point1.Y - point2.Y);
|
||||
}
|
||||
|
||||
public static DoublePoint Subtract(DoublePoint point1, DoublePoint point2)
|
||||
{
|
||||
return new DoublePoint(point1.X - point2.X, point1.Y - point2.Y);
|
||||
}
|
||||
|
||||
public static DoublePoint operator +(DoublePoint point, double valueToAdd)
|
||||
{
|
||||
return new DoublePoint(point.X + valueToAdd, point.Y + valueToAdd);
|
||||
}
|
||||
|
||||
public static DoublePoint Add(DoublePoint point, double valueToAdd)
|
||||
{
|
||||
return new DoublePoint(point.X + valueToAdd, point.Y + valueToAdd);
|
||||
}
|
||||
|
||||
public static DoublePoint operator -(DoublePoint point, double valueToSubtract)
|
||||
{
|
||||
return new DoublePoint(point.X - valueToSubtract, point.Y - valueToSubtract);
|
||||
}
|
||||
|
||||
public static DoublePoint Subtract(DoublePoint point, double valueToSubtract)
|
||||
{
|
||||
return new DoublePoint(point.X - valueToSubtract, point.Y - valueToSubtract);
|
||||
}
|
||||
|
||||
public static DoublePoint operator *(DoublePoint point, double factor)
|
||||
{
|
||||
return new DoublePoint(point.X * factor, point.Y * factor);
|
||||
}
|
||||
|
||||
public static DoublePoint Multiply(DoublePoint point, double factor)
|
||||
{
|
||||
return new DoublePoint(point.X * factor, point.Y * factor);
|
||||
}
|
||||
|
||||
public static DoublePoint operator /(DoublePoint point, double factor)
|
||||
{
|
||||
return new DoublePoint(point.X / factor, point.Y / factor);
|
||||
}
|
||||
|
||||
public static DoublePoint Divide(DoublePoint point, double factor)
|
||||
{
|
||||
return new DoublePoint(point.X / factor, point.Y / factor);
|
||||
}
|
||||
|
||||
public static bool operator ==(DoublePoint point1, DoublePoint point2)
|
||||
{
|
||||
if (point1.X == point2.X)
|
||||
{
|
||||
return point1.Y == point2.Y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator !=(DoublePoint point1, DoublePoint point2)
|
||||
{
|
||||
if (point1.X == point2.X)
|
||||
{
|
||||
return point1.Y != point2.Y;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is DoublePoint))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this == (DoublePoint)obj;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return X.GetHashCode() + Y.GetHashCode();
|
||||
}
|
||||
|
||||
public static explicit operator IntPoint(DoublePoint point)
|
||||
{
|
||||
return new IntPoint((int)point.X, (int)point.Y);
|
||||
}
|
||||
|
||||
public static explicit operator Point(DoublePoint point)
|
||||
{
|
||||
return new Point((float)point.X, (float)point.Y);
|
||||
}
|
||||
|
||||
public IntPoint Round()
|
||||
{
|
||||
return new IntPoint((int)Math.Round(X), (int)Math.Round(Y));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[2] { X, Y });
|
||||
}
|
||||
|
||||
public double EuclideanNorm()
|
||||
{
|
||||
return Math.Sqrt(X * X + Y * Y);
|
||||
}
|
||||
}
|
||||
125
output/Libraries/AForge/AForge/DoubleRange.cs
Normal file
125
output/Libraries/AForge/AForge/DoubleRange.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
[Serializable]
|
||||
public struct DoubleRange
|
||||
{
|
||||
private double min;
|
||||
|
||||
private double max;
|
||||
|
||||
public double Min
|
||||
{
|
||||
get
|
||||
{
|
||||
return min;
|
||||
}
|
||||
set
|
||||
{
|
||||
min = value;
|
||||
}
|
||||
}
|
||||
|
||||
public double Max
|
||||
{
|
||||
get
|
||||
{
|
||||
return max;
|
||||
}
|
||||
set
|
||||
{
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
|
||||
public double Length => max - min;
|
||||
|
||||
public DoubleRange(double min, double max)
|
||||
{
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public bool IsInside(double x)
|
||||
{
|
||||
if (x >= min)
|
||||
{
|
||||
return x <= max;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsInside(DoubleRange range)
|
||||
{
|
||||
if (IsInside(range.min))
|
||||
{
|
||||
return IsInside(range.max);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsOverlapping(DoubleRange range)
|
||||
{
|
||||
if (!IsInside(range.min) && !IsInside(range.max) && !range.IsInside(min))
|
||||
{
|
||||
return range.IsInside(max);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public IntRange ToIntRange(bool provideInnerRange)
|
||||
{
|
||||
int num;
|
||||
int num2;
|
||||
if (provideInnerRange)
|
||||
{
|
||||
num = (int)Math.Ceiling(min);
|
||||
num2 = (int)Math.Floor(max);
|
||||
}
|
||||
else
|
||||
{
|
||||
num = (int)Math.Floor(min);
|
||||
num2 = (int)Math.Ceiling(max);
|
||||
}
|
||||
return new IntRange(num, num2);
|
||||
}
|
||||
|
||||
public static bool operator ==(DoubleRange range1, DoubleRange range2)
|
||||
{
|
||||
if (range1.min == range2.min)
|
||||
{
|
||||
return range1.max == range2.max;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator !=(DoubleRange range1, DoubleRange range2)
|
||||
{
|
||||
if (range1.min == range2.min)
|
||||
{
|
||||
return range1.max != range2.max;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Range))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this == (DoubleRange)obj;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return min.GetHashCode() + max.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[2] { min, max });
|
||||
}
|
||||
}
|
||||
144
output/Libraries/AForge/AForge/IntPoint.cs
Normal file
144
output/Libraries/AForge/AForge/IntPoint.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
[Serializable]
|
||||
public struct IntPoint
|
||||
{
|
||||
public int X;
|
||||
|
||||
public int Y;
|
||||
|
||||
public IntPoint(int x, int y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public float DistanceTo(IntPoint anotherPoint)
|
||||
{
|
||||
int num = X - anotherPoint.X;
|
||||
int num2 = Y - anotherPoint.Y;
|
||||
return (float)Math.Sqrt(num * num + num2 * num2);
|
||||
}
|
||||
|
||||
public float SquaredDistanceTo(Point anotherPoint)
|
||||
{
|
||||
float num = (float)X - anotherPoint.X;
|
||||
float num2 = (float)Y - anotherPoint.Y;
|
||||
return num * num + num2 * num2;
|
||||
}
|
||||
|
||||
public static IntPoint operator +(IntPoint point1, IntPoint point2)
|
||||
{
|
||||
return new IntPoint(point1.X + point2.X, point1.Y + point2.Y);
|
||||
}
|
||||
|
||||
public static IntPoint Add(IntPoint point1, IntPoint point2)
|
||||
{
|
||||
return new IntPoint(point1.X + point2.X, point1.Y + point2.Y);
|
||||
}
|
||||
|
||||
public static IntPoint operator -(IntPoint point1, IntPoint point2)
|
||||
{
|
||||
return new IntPoint(point1.X - point2.X, point1.Y - point2.Y);
|
||||
}
|
||||
|
||||
public static IntPoint Subtract(IntPoint point1, IntPoint point2)
|
||||
{
|
||||
return new IntPoint(point1.X - point2.X, point1.Y - point2.Y);
|
||||
}
|
||||
|
||||
public static IntPoint operator +(IntPoint point, int valueToAdd)
|
||||
{
|
||||
return new IntPoint(point.X + valueToAdd, point.Y + valueToAdd);
|
||||
}
|
||||
|
||||
public static IntPoint Add(IntPoint point, int valueToAdd)
|
||||
{
|
||||
return new IntPoint(point.X + valueToAdd, point.Y + valueToAdd);
|
||||
}
|
||||
|
||||
public static IntPoint operator -(IntPoint point, int valueToSubtract)
|
||||
{
|
||||
return new IntPoint(point.X - valueToSubtract, point.Y - valueToSubtract);
|
||||
}
|
||||
|
||||
public static IntPoint Subtract(IntPoint point, int valueToSubtract)
|
||||
{
|
||||
return new IntPoint(point.X - valueToSubtract, point.Y - valueToSubtract);
|
||||
}
|
||||
|
||||
public static IntPoint operator *(IntPoint point, int factor)
|
||||
{
|
||||
return new IntPoint(point.X * factor, point.Y * factor);
|
||||
}
|
||||
|
||||
public static IntPoint Multiply(IntPoint point, int factor)
|
||||
{
|
||||
return new IntPoint(point.X * factor, point.Y * factor);
|
||||
}
|
||||
|
||||
public static IntPoint operator /(IntPoint point, int factor)
|
||||
{
|
||||
return new IntPoint(point.X / factor, point.Y / factor);
|
||||
}
|
||||
|
||||
public static IntPoint Divide(IntPoint point, int factor)
|
||||
{
|
||||
return new IntPoint(point.X / factor, point.Y / factor);
|
||||
}
|
||||
|
||||
public static bool operator ==(IntPoint point1, IntPoint point2)
|
||||
{
|
||||
if (point1.X == point2.X)
|
||||
{
|
||||
return point1.Y == point2.Y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator !=(IntPoint point1, IntPoint point2)
|
||||
{
|
||||
if (point1.X == point2.X)
|
||||
{
|
||||
return point1.Y != point2.Y;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is IntPoint))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this == (IntPoint)obj;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return X.GetHashCode() + Y.GetHashCode();
|
||||
}
|
||||
|
||||
public static implicit operator Point(IntPoint point)
|
||||
{
|
||||
return new Point(point.X, point.Y);
|
||||
}
|
||||
|
||||
public static implicit operator DoublePoint(IntPoint point)
|
||||
{
|
||||
return new DoublePoint(point.X, point.Y);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[2] { X, Y });
|
||||
}
|
||||
|
||||
public float EuclideanNorm()
|
||||
{
|
||||
return (float)Math.Sqrt(X * X + Y * Y);
|
||||
}
|
||||
}
|
||||
113
output/Libraries/AForge/AForge/IntRange.cs
Normal file
113
output/Libraries/AForge/AForge/IntRange.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
[Serializable]
|
||||
public struct IntRange
|
||||
{
|
||||
private int min;
|
||||
|
||||
private int max;
|
||||
|
||||
public int Min
|
||||
{
|
||||
get
|
||||
{
|
||||
return min;
|
||||
}
|
||||
set
|
||||
{
|
||||
min = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Max
|
||||
{
|
||||
get
|
||||
{
|
||||
return max;
|
||||
}
|
||||
set
|
||||
{
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Length => max - min;
|
||||
|
||||
public IntRange(int min, int max)
|
||||
{
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public bool IsInside(int x)
|
||||
{
|
||||
if (x >= min)
|
||||
{
|
||||
return x <= max;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsInside(IntRange range)
|
||||
{
|
||||
if (IsInside(range.min))
|
||||
{
|
||||
return IsInside(range.max);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsOverlapping(IntRange range)
|
||||
{
|
||||
if (!IsInside(range.min) && !IsInside(range.max) && !range.IsInside(min))
|
||||
{
|
||||
return range.IsInside(max);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static implicit operator Range(IntRange range)
|
||||
{
|
||||
return new Range(range.Min, range.Max);
|
||||
}
|
||||
|
||||
public static bool operator ==(IntRange range1, IntRange range2)
|
||||
{
|
||||
if (range1.min == range2.min)
|
||||
{
|
||||
return range1.max == range2.max;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator !=(IntRange range1, IntRange range2)
|
||||
{
|
||||
if (range1.min == range2.min)
|
||||
{
|
||||
return range1.max != range2.max;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is IntRange))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this == (IntRange)obj;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return min.GetHashCode() + max.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[2] { min, max });
|
||||
}
|
||||
}
|
||||
3
output/Libraries/AForge/AForge/MessageTransferHandler.cs
Normal file
3
output/Libraries/AForge/AForge/MessageTransferHandler.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace AForge;
|
||||
|
||||
public delegate void MessageTransferHandler(object sender, CommunicationBufferEventArgs eventArgs);
|
||||
11
output/Libraries/AForge/AForge/NotConnectedException.cs
Normal file
11
output/Libraries/AForge/AForge/NotConnectedException.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
public class NotConnectedException : Exception
|
||||
{
|
||||
public NotConnectedException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
141
output/Libraries/AForge/AForge/Parallel.cs
Normal file
141
output/Libraries/AForge/AForge/Parallel.cs
Normal file
@@ -0,0 +1,141 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
public sealed class Parallel
|
||||
{
|
||||
public delegate void ForLoopBody(int index);
|
||||
|
||||
private static int threadsCount = Environment.ProcessorCount;
|
||||
|
||||
private static object sync = new object();
|
||||
|
||||
private static volatile Parallel instance = null;
|
||||
|
||||
private Thread[] threads;
|
||||
|
||||
private AutoResetEvent[] jobAvailable;
|
||||
|
||||
private ManualResetEvent[] threadIdle;
|
||||
|
||||
private int currentIndex;
|
||||
|
||||
private int stopIndex;
|
||||
|
||||
private ForLoopBody loopBody;
|
||||
|
||||
public static int ThreadsCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return threadsCount;
|
||||
}
|
||||
set
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
threadsCount = Math.Max(1, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Parallel Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new Parallel();
|
||||
instance.Initialize();
|
||||
}
|
||||
else if (instance.threads.Length != threadsCount)
|
||||
{
|
||||
instance.Terminate();
|
||||
instance.Initialize();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static void For(int start, int stop, ForLoopBody loopBody)
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
Parallel parallel = Instance;
|
||||
parallel.currentIndex = start - 1;
|
||||
parallel.stopIndex = stop;
|
||||
parallel.loopBody = loopBody;
|
||||
for (int i = 0; i < threadsCount; i++)
|
||||
{
|
||||
parallel.threadIdle[i].Reset();
|
||||
parallel.jobAvailable[i].Set();
|
||||
}
|
||||
for (int j = 0; j < threadsCount; j++)
|
||||
{
|
||||
parallel.threadIdle[j].WaitOne();
|
||||
}
|
||||
parallel.loopBody = null;
|
||||
}
|
||||
}
|
||||
|
||||
private Parallel()
|
||||
{
|
||||
}
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
jobAvailable = new AutoResetEvent[threadsCount];
|
||||
threadIdle = new ManualResetEvent[threadsCount];
|
||||
threads = new Thread[threadsCount];
|
||||
for (int i = 0; i < threadsCount; i++)
|
||||
{
|
||||
jobAvailable[i] = new AutoResetEvent(initialState: false);
|
||||
threadIdle[i] = new ManualResetEvent(initialState: true);
|
||||
threads[i] = new Thread(WorkerThread);
|
||||
threads[i].Name = "AForge.Parallel";
|
||||
threads[i].IsBackground = true;
|
||||
threads[i].Start(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void Terminate()
|
||||
{
|
||||
loopBody = null;
|
||||
int i = 0;
|
||||
for (int num = threads.Length; i < num; i++)
|
||||
{
|
||||
jobAvailable[i].Set();
|
||||
threads[i].Join();
|
||||
jobAvailable[i].Close();
|
||||
threadIdle[i].Close();
|
||||
}
|
||||
jobAvailable = null;
|
||||
threadIdle = null;
|
||||
threads = null;
|
||||
}
|
||||
|
||||
private void WorkerThread(object index)
|
||||
{
|
||||
int num = (int)index;
|
||||
int num2 = 0;
|
||||
while (true)
|
||||
{
|
||||
jobAvailable[num].WaitOne();
|
||||
if (loopBody == null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
num2 = Interlocked.Increment(ref currentIndex);
|
||||
if (num2 >= stopIndex)
|
||||
{
|
||||
break;
|
||||
}
|
||||
loopBody(num2);
|
||||
}
|
||||
threadIdle[num].Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
149
output/Libraries/AForge/AForge/Point.cs
Normal file
149
output/Libraries/AForge/AForge/Point.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
[Serializable]
|
||||
public struct Point
|
||||
{
|
||||
public float X;
|
||||
|
||||
public float Y;
|
||||
|
||||
public Point(float x, float y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public float DistanceTo(Point anotherPoint)
|
||||
{
|
||||
float num = X - anotherPoint.X;
|
||||
float num2 = Y - anotherPoint.Y;
|
||||
return (float)Math.Sqrt(num * num + num2 * num2);
|
||||
}
|
||||
|
||||
public float SquaredDistanceTo(Point anotherPoint)
|
||||
{
|
||||
float num = X - anotherPoint.X;
|
||||
float num2 = Y - anotherPoint.Y;
|
||||
return num * num + num2 * num2;
|
||||
}
|
||||
|
||||
public static Point operator +(Point point1, Point point2)
|
||||
{
|
||||
return new Point(point1.X + point2.X, point1.Y + point2.Y);
|
||||
}
|
||||
|
||||
public static Point Add(Point point1, Point point2)
|
||||
{
|
||||
return new Point(point1.X + point2.X, point1.Y + point2.Y);
|
||||
}
|
||||
|
||||
public static Point operator -(Point point1, Point point2)
|
||||
{
|
||||
return new Point(point1.X - point2.X, point1.Y - point2.Y);
|
||||
}
|
||||
|
||||
public static Point Subtract(Point point1, Point point2)
|
||||
{
|
||||
return new Point(point1.X - point2.X, point1.Y - point2.Y);
|
||||
}
|
||||
|
||||
public static Point operator +(Point point, float valueToAdd)
|
||||
{
|
||||
return new Point(point.X + valueToAdd, point.Y + valueToAdd);
|
||||
}
|
||||
|
||||
public static Point Add(Point point, float valueToAdd)
|
||||
{
|
||||
return new Point(point.X + valueToAdd, point.Y + valueToAdd);
|
||||
}
|
||||
|
||||
public static Point operator -(Point point, float valueToSubtract)
|
||||
{
|
||||
return new Point(point.X - valueToSubtract, point.Y - valueToSubtract);
|
||||
}
|
||||
|
||||
public static Point Subtract(Point point, float valueToSubtract)
|
||||
{
|
||||
return new Point(point.X - valueToSubtract, point.Y - valueToSubtract);
|
||||
}
|
||||
|
||||
public static Point operator *(Point point, float factor)
|
||||
{
|
||||
return new Point(point.X * factor, point.Y * factor);
|
||||
}
|
||||
|
||||
public static Point Multiply(Point point, float factor)
|
||||
{
|
||||
return new Point(point.X * factor, point.Y * factor);
|
||||
}
|
||||
|
||||
public static Point operator /(Point point, float factor)
|
||||
{
|
||||
return new Point(point.X / factor, point.Y / factor);
|
||||
}
|
||||
|
||||
public static Point Divide(Point point, float factor)
|
||||
{
|
||||
return new Point(point.X / factor, point.Y / factor);
|
||||
}
|
||||
|
||||
public static bool operator ==(Point point1, Point point2)
|
||||
{
|
||||
if (point1.X == point2.X)
|
||||
{
|
||||
return point1.Y == point2.Y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator !=(Point point1, Point point2)
|
||||
{
|
||||
if (point1.X == point2.X)
|
||||
{
|
||||
return point1.Y != point2.Y;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Point))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this == (Point)obj;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return X.GetHashCode() + Y.GetHashCode();
|
||||
}
|
||||
|
||||
public static explicit operator IntPoint(Point point)
|
||||
{
|
||||
return new IntPoint((int)point.X, (int)point.Y);
|
||||
}
|
||||
|
||||
public static implicit operator DoublePoint(Point point)
|
||||
{
|
||||
return new DoublePoint(point.X, point.Y);
|
||||
}
|
||||
|
||||
public IntPoint Round()
|
||||
{
|
||||
return new IntPoint((int)Math.Round(X), (int)Math.Round(Y));
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[2] { X, Y });
|
||||
}
|
||||
|
||||
public float EuclideanNorm()
|
||||
{
|
||||
return (float)Math.Sqrt(X * X + Y * Y);
|
||||
}
|
||||
}
|
||||
65
output/Libraries/AForge/AForge/PolishExpression.cs
Normal file
65
output/Libraries/AForge/AForge/PolishExpression.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
public static class PolishExpression
|
||||
{
|
||||
public static double Evaluate(string expression, double[] variables)
|
||||
{
|
||||
string[] array = expression.Trim().Split(new char[1] { ' ' });
|
||||
Stack stack = new Stack();
|
||||
string[] array2 = array;
|
||||
foreach (string text in array2)
|
||||
{
|
||||
if (char.IsDigit(text[0]))
|
||||
{
|
||||
stack.Push(double.Parse(text));
|
||||
continue;
|
||||
}
|
||||
if (text[0] == '$')
|
||||
{
|
||||
stack.Push(variables[int.Parse(text.Substring(1))]);
|
||||
continue;
|
||||
}
|
||||
double num = (double)stack.Pop();
|
||||
switch (text)
|
||||
{
|
||||
case "+":
|
||||
stack.Push((double)stack.Pop() + num);
|
||||
break;
|
||||
case "-":
|
||||
stack.Push((double)stack.Pop() - num);
|
||||
break;
|
||||
case "*":
|
||||
stack.Push((double)stack.Pop() * num);
|
||||
break;
|
||||
case "/":
|
||||
stack.Push((double)stack.Pop() / num);
|
||||
break;
|
||||
case "sin":
|
||||
stack.Push(Math.Sin(num));
|
||||
break;
|
||||
case "cos":
|
||||
stack.Push(Math.Cos(num));
|
||||
break;
|
||||
case "ln":
|
||||
stack.Push(Math.Log(num));
|
||||
break;
|
||||
case "exp":
|
||||
stack.Push(Math.Exp(num));
|
||||
break;
|
||||
case "sqrt":
|
||||
stack.Push(Math.Sqrt(num));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unsupported function: " + text);
|
||||
}
|
||||
}
|
||||
if (stack.Count != 1)
|
||||
{
|
||||
throw new ArgumentException("Incorrect expression.");
|
||||
}
|
||||
return (double)stack.Pop();
|
||||
}
|
||||
}
|
||||
125
output/Libraries/AForge/AForge/Range.cs
Normal file
125
output/Libraries/AForge/AForge/Range.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
[Serializable]
|
||||
public struct Range
|
||||
{
|
||||
private float min;
|
||||
|
||||
private float max;
|
||||
|
||||
public float Min
|
||||
{
|
||||
get
|
||||
{
|
||||
return min;
|
||||
}
|
||||
set
|
||||
{
|
||||
min = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Max
|
||||
{
|
||||
get
|
||||
{
|
||||
return max;
|
||||
}
|
||||
set
|
||||
{
|
||||
max = value;
|
||||
}
|
||||
}
|
||||
|
||||
public float Length => max - min;
|
||||
|
||||
public Range(float min, float max)
|
||||
{
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public bool IsInside(float x)
|
||||
{
|
||||
if (x >= min)
|
||||
{
|
||||
return x <= max;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsInside(Range range)
|
||||
{
|
||||
if (IsInside(range.min))
|
||||
{
|
||||
return IsInside(range.max);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsOverlapping(Range range)
|
||||
{
|
||||
if (!IsInside(range.min) && !IsInside(range.max) && !range.IsInside(min))
|
||||
{
|
||||
return range.IsInside(max);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public IntRange ToIntRange(bool provideInnerRange)
|
||||
{
|
||||
int num;
|
||||
int num2;
|
||||
if (provideInnerRange)
|
||||
{
|
||||
num = (int)Math.Ceiling(min);
|
||||
num2 = (int)Math.Floor(max);
|
||||
}
|
||||
else
|
||||
{
|
||||
num = (int)Math.Floor(min);
|
||||
num2 = (int)Math.Ceiling(max);
|
||||
}
|
||||
return new IntRange(num, num2);
|
||||
}
|
||||
|
||||
public static bool operator ==(Range range1, Range range2)
|
||||
{
|
||||
if (range1.min == range2.min)
|
||||
{
|
||||
return range1.max == range2.max;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool operator !=(Range range1, Range range2)
|
||||
{
|
||||
if (range1.min == range2.min)
|
||||
{
|
||||
return range1.max != range2.max;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Range))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this == (Range)obj;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return min.GetHashCode() + max.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", new object[2] { min, max });
|
||||
}
|
||||
}
|
||||
35
output/Libraries/AForge/AForge/SystemTools.cs
Normal file
35
output/Libraries/AForge/AForge/SystemTools.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
public static class SystemTools
|
||||
{
|
||||
public unsafe static IntPtr CopyUnmanagedMemory(IntPtr dst, IntPtr src, int count)
|
||||
{
|
||||
CopyUnmanagedMemory((byte*)dst.ToPointer(), (byte*)src.ToPointer(), count);
|
||||
return dst;
|
||||
}
|
||||
|
||||
public unsafe static byte* CopyUnmanagedMemory(byte* dst, byte* src, int count)
|
||||
{
|
||||
return memcpy(dst, src, count);
|
||||
}
|
||||
|
||||
public unsafe static IntPtr SetUnmanagedMemory(IntPtr dst, int filler, int count)
|
||||
{
|
||||
SetUnmanagedMemory((byte*)dst.ToPointer(), filler, count);
|
||||
return dst;
|
||||
}
|
||||
|
||||
public unsafe static byte* SetUnmanagedMemory(byte* dst, int filler, int count)
|
||||
{
|
||||
return memset(dst, filler, count);
|
||||
}
|
||||
|
||||
[DllImport("ntdll.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
private unsafe static extern byte* memcpy(byte* dst, byte* src, int count);
|
||||
|
||||
[DllImport("ntdll.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||
private unsafe static extern byte* memset(byte* dst, int filler, int count);
|
||||
}
|
||||
57
output/Libraries/AForge/AForge/ThreadSafeRandom.cs
Normal file
57
output/Libraries/AForge/AForge/ThreadSafeRandom.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
|
||||
namespace AForge;
|
||||
|
||||
public sealed class ThreadSafeRandom : Random
|
||||
{
|
||||
private object sync = new object();
|
||||
|
||||
public ThreadSafeRandom()
|
||||
{
|
||||
}
|
||||
|
||||
public ThreadSafeRandom(int seed)
|
||||
: base(seed)
|
||||
{
|
||||
}
|
||||
|
||||
public override int Next()
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
return base.Next();
|
||||
}
|
||||
}
|
||||
|
||||
public override int Next(int maxValue)
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
return base.Next(maxValue);
|
||||
}
|
||||
}
|
||||
|
||||
public override int Next(int minValue, int maxValue)
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
return base.Next(minValue, maxValue);
|
||||
}
|
||||
}
|
||||
|
||||
public override void NextBytes(byte[] buffer)
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
base.NextBytes(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public override double NextDouble()
|
||||
{
|
||||
lock (sync)
|
||||
{
|
||||
return base.NextDouble();
|
||||
}
|
||||
}
|
||||
}
|
||||
18
output/Libraries/AForge/Properties/AssemblyInfo.cs
Normal file
18
output/Libraries/AForge/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Security.Permissions;
|
||||
|
||||
[assembly: AssemblyCopyright("AForge © 2012")]
|
||||
[assembly: AssemblyTitle("AForge")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("AForge")]
|
||||
[assembly: AssemblyProduct("AForge.NET")]
|
||||
[assembly: Guid("f37ad0d7-d32b-4096-841f-3c03dbbecde6")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: AssemblyFileVersion("2.2.5.0")]
|
||||
[assembly: AssemblyVersion("2.2.5.0")]
|
||||
Reference in New Issue
Block a user