OSDN Git Service

5
authorHOSOKAWA Kenchi <hskwk@users.sourceforge.jp>
Wed, 28 Mar 2012 16:46:02 +0000 (01:46 +0900)
committerHOSOKAWA Kenchi <hskwk@users.sourceforge.jp>
Wed, 28 Mar 2012 16:46:02 +0000 (01:46 +0900)
80 files changed:
dev4/Pages/BinomialSolver.xaml [moved from dev5/Pages/BinomialSolver.xaml with 100% similarity]
dev4/Pages/BinomialSolver.xaml.cs [moved from dev5/Pages/BinomialSolver.xaml.cs with 100% similarity]
dev4/Properties/AssemblyInfo.cs [new file with mode: 0644]
dev4/PsychlopsSilverlight4.csproj [moved from dev5/PsychlopsSilverlight4.csproj with 100% similarity]
dev4/PsychlopsSilverlight4.sln [moved from dev5/PsychlopsSilverlight4.sln with 100% similarity]
dev4/Shader/Gabor.fx [new file with mode: 0644]
dev4/Shader/Gabor.ps [new file with mode: 0644]
dev4/Shader/GaborAlpha.fx [new file with mode: 0644]
dev4/Shader/GaborAlpha.ps [new file with mode: 0644]
dev4/Shader/Grating.fx [new file with mode: 0644]
dev4/Shader/Grating.ps [new file with mode: 0644]
dev4/Shader/Plaid.fx [new file with mode: 0644]
dev4/Shader/Plaid.ps [new file with mode: 0644]
dev4/WriteableBitmapEx/License.txt [moved from dev5/WriteableBitmapEx/License.txt with 100% similarity]
dev4/WriteableBitmapEx/Readme.txt [moved from dev5/WriteableBitmapEx/Readme.txt with 100% similarity]
dev4/WriteableBitmapEx/WriteableBitmapEx.XML [new file with mode: 0644]
dev4/WriteableBitmapEx/WriteableBitmapEx.dll [new file with mode: 0644]
dev4/WriteableBitmapEx/WriteableBitmapEx.pdb [new file with mode: 0644]
dev4/psychlops/core/app/app.cs [new file with mode: 0644]
dev4/psychlops/core/app/misc.cs [new file with mode: 0644]
dev4/psychlops/core/device/clock.cs [moved from dev5/psychlops/core/device/clock.cs with 100% similarity]
dev4/psychlops/core/device/hid.cs [moved from dev5/psychlops/core/device/hid.cs with 100% similarity]
dev4/psychlops/core/graphic/canvas.cs [new file with mode: 0644]
dev4/psychlops/core/graphic/font.cs [new file with mode: 0644]
dev4/psychlops/core/graphic/image.cs [new file with mode: 0644]
dev4/psychlops/core/graphic/module.cs [new file with mode: 0644]
dev4/psychlops/core/graphic/shape.cs [new file with mode: 0644]
dev4/psychlops/core/math/interval.cs [new file with mode: 0644]
dev4/psychlops/core/math/matrix.cs [new file with mode: 0644]
dev4/psychlops/core/math/util.cs [new file with mode: 0644]
dev4/psychlops/extention/compatibility/compatibility.cs [moved from dev5/psychlops/extention/compatibility/compatibility.cs with 100% similarity]
dev4/psychlops/extention/experiments/experiments.cs [moved from dev5/psychlops/extention/experiments/experiments.cs with 100% similarity]
dev4/psychlops/extention/math/BigFloat.cs [moved from dev5/psychlops/extention/math/BigFloat.cs with 100% similarity]
dev4/psychlops/extention/math/BigInt.cs [moved from dev5/psychlops/extention/math/BigInt.cs with 100% similarity]
dev4/psychlops/extention/math/solver.cs [moved from dev5/psychlops/extention/math/solver.cs with 100% similarity]
dev4/psychlops/extention/media/dom.cs [moved from dev5/psychlops/extention/media/dom.cs with 100% similarity]
dev4/psychlops/extention/media/svg.cs [moved from dev5/psychlops/extention/media/svg.cs with 100% similarity]
dev4/psychlops/extention/standard/CIEColor.cs [moved from dev5/psychlops/extention/standard/CIEColor.cs with 100% similarity]
dev4/psychlops/extention/standard/figures.cs [moved from dev5/psychlops/extention/standard/figures.cs with 100% similarity]
dev4/psychlops/extention/standard/shader.cs [moved from dev5/psychlops/extention/standard/shader.cs with 100% similarity]
dev4/psychlops/extention/standard/widget.cs [moved from dev5/psychlops/extention/standard/widget.cs with 100% similarity]
dev4/psychlops/psychlops.cs [new file with mode: 0644]
dev5/Properties/AssemblyInfo.cs
dev5/PsychlopsSilverlight5.csproj [new file with mode: 0644]
dev5/WriteableBitmapEx/WriteableBitmapEx.XML
dev5/WriteableBitmapEx/WriteableBitmapEx.dll
dev5/WriteableBitmapEx/WriteableBitmapEx.pdb
dev5/psychlops/core/devices/clock.cs [new file with mode: 0644]
dev5/psychlops/core/devices/hid.cs [new file with mode: 0644]
dev5/psychlops/core/graphic/canvas.cs
dev5/psychlops/extension/compatibility/compatibility.cs [new file with mode: 0644]
dev5/psychlops/extension/experiments/experiments.cs [new file with mode: 0644]
dev5/psychlops/extension/math/BigFloat.cs [new file with mode: 0644]
dev5/psychlops/extension/math/BigInt.cs [new file with mode: 0644]
dev5/psychlops/extension/math/solver.cs [new file with mode: 0644]
dev5/psychlops/extension/media/dom.cs [new file with mode: 0644]
dev5/psychlops/extension/media/svg.cs [new file with mode: 0644]
dev5/psychlops/extension/standard/CIEColor.cs [new file with mode: 0644]
dev5/psychlops/extension/standard/figures.cs [new file with mode: 0644]
dev5/psychlops/extension/standard/shader.cs [new file with mode: 0644]
dev5/psychlops/extension/standard/widget.cs [new file with mode: 0644]
test4/App.xaml [new file with mode: 0644]
test4/App.xaml.cs [new file with mode: 0644]
test4/MainPage.xaml [new file with mode: 0644]
test4/MainPage.xaml.cs [new file with mode: 0644]
test4/Properties/AppManifest.xml [new file with mode: 0644]
test4/Properties/AssemblyInfo.cs [new file with mode: 0644]
test4/PsychlopsMain.cs [new file with mode: 0644]
test4/PsychlopsSilverlight4test.csproj [moved from test5/PsychlopsSilverlight4test.csproj with 100% similarity]
test4/PsychlopsSilverlight4test.sln [moved from test5/PsychlopsSilverlight4test.sln with 100% similarity]
test4/Store.cs [new file with mode: 0644]
test4/TestPage.html [new file with mode: 0644]
test5/App.xaml
test5/App.xaml.cs
test5/MainPage.xaml
test5/MainPage.xaml.cs
test5/Properties/AppManifest.xml
test5/Properties/AssemblyInfo.cs
test5/PsychlopsMain.cs
test5/PsychlopsSilverlight5test.csproj [new file with mode: 0644]

diff --git a/dev4/Properties/AssemblyInfo.cs b/dev4/Properties/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..100e216
--- /dev/null
@@ -0,0 +1,35 @@
+using System.Reflection;\r
+using System.Runtime.CompilerServices;\r
+using System.Runtime.InteropServices;\r
+\r
+// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。\r
+// アセンブリに関連付けられている情報を変更するには、\r
+// これらの属性値を変更してください。\r
+[assembly: AssemblyTitle("PsychlopsSilverlight4")]\r
+[assembly: AssemblyDescription("")]\r
+[assembly: AssemblyConfiguration("")]\r
+[assembly: AssemblyCompany("")]\r
+[assembly: AssemblyProduct("PsychlopsSilverlight4")]\r
+[assembly: AssemblyCopyright("Copyright ©  2010")]\r
+[assembly: AssemblyTrademark("")]\r
+[assembly: AssemblyCulture("")]\r
+\r
+// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから\r
+// 見えなくなります。このアセンブリ内で COM から型にアクセスする必要がある場合は、\r
+// その型の ComVisible 属性を true に設定してください。\r
+[assembly: ComVisible(false)]\r
+\r
+// このプロジェクトが COM に公開される場合、次の GUID がタイプ ライブラリの ID になります。\r
+[assembly: Guid("a37cfddf-f475-42fb-804c-66fa131de7fb")]\r
+\r
+// アセンブリのバージョン情報は、以下の 4 つの値で構成されています。\r
+//\r
+//      Major Version\r
+//      Minor Version \r
+//      Build Number\r
+//      Revision\r
+//\r
+// すべての値を指定するか、下のように '*' を使ってリビジョンおよびビルド番号を\r
+// 既定値にすることができます。\r
+[assembly: AssemblyVersion("1.0.0.0")]\r
+[assembly: AssemblyFileVersion("1.0.0.0")]\r
diff --git a/dev4/Shader/Gabor.fx b/dev4/Shader/Gabor.fx
new file mode 100644 (file)
index 0000000..5ec9fbf
--- /dev/null
@@ -0,0 +1,59 @@
+/// <summary>Amplitude of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>1</maxValue>\r
+/// <defaultValue>1</defaultValue>\r
+float contrast : register(C1);\r
+\r
+/// <summary>Phase of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>100</maxValue>\r
+/// <defaultValue>100</defaultValue>\r
+float frequency: register(C2);\r
+\r
+/// <summary>Phase of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float phase: register(C3);\r
+\r
+/// <summary>Orientation of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float orientation: register(C4);\r
+\r
+/// <summary>Half bandwidth of envelope</summary>\r
+/// <minValue>2</minValue>\r
+/// <maxValue>8</maxValue>\r
+/// <defaultValue>4</defaultValue>\r
+float sigma : register(C5);\r
+\r
+/// <summary>Transparency of Figure</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>1</maxValue>\r
+/// <defaultValue>1</defaultValue>\r
+float alpha : register(C6);\r
+\r
+\r
+float rp(float2 uv)\r
+{\r
+       const float2 Center = float2(0.5,0.5);\r
+       float2 dir = uv - Center; // vector from center to pixel\r
+       float dist = length(dir);\r
+       //dir /= dist;\r
+       return dist;\r
+}\r
+\r
+float4 main(float2 uv : TEXCOORD) : COLOR\r
+{\r
+      float _r = rp(uv)*8;\r
+      float env = exp( -(_r*_r) / (2.0) ) * alpha;\r
+\r
+      float _x = sin(orientation)*uv[0]-cos(orientation)*uv[1];\r
+      float cl = 127.0/255.0+env*contrast*127.0/255.0*cos(frequency*_x + phase);\r
+      if(_r>3.2) if(abs(cl-127.0/255.0)<0.005) cl=127.0/255.0;\r
+      float l = cl;\r
+     \r
+      float4 color = float4(l,l,l,1.0);\r
+      return color;\r
+}
\ No newline at end of file
diff --git a/dev4/Shader/Gabor.ps b/dev4/Shader/Gabor.ps
new file mode 100644 (file)
index 0000000..e937ad4
Binary files /dev/null and b/dev4/Shader/Gabor.ps differ
diff --git a/dev4/Shader/GaborAlpha.fx b/dev4/Shader/GaborAlpha.fx
new file mode 100644 (file)
index 0000000..0a162e8
--- /dev/null
@@ -0,0 +1,60 @@
+/// <summary>Amplitude of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>1</maxValue>\r
+/// <defaultValue>1</defaultValue>\r
+float contrast : register(C1);\r
+\r
+/// <summary>Phase of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>100</maxValue>\r
+/// <defaultValue>100</defaultValue>\r
+float frequency: register(C2);\r
+\r
+/// <summary>Phase of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float phase: register(C3);\r
+\r
+/// <summary>Orientation of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float orientation: register(C4);\r
+\r
+/// <summary>Half bandwidth of envelope</summary>\r
+/// <minValue>2</minValue>\r
+/// <maxValue>8</maxValue>\r
+/// <defaultValue>4</defaultValue>\r
+float sigma : register(C5);\r
+\r
+/// <summary>Transparency of Figure</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>1</maxValue>\r
+/// <defaultValue>1</defaultValue>\r
+float alpha : register(C6);\r
+\r
+\r
+float rp(float2 uv)\r
+{\r
+       const float2 Center = float2(0.5,0.5);\r
+       float2 dir = uv - Center; // vector from center to pixel\r
+       float dist = length(dir);\r
+       //dir /= dist;\r
+       return dist;\r
+}\r
+\r
+float4 main(float2 uv : TEXCOORD) : COLOR\r
+//float4 main(float2 uv : VPOS ) : COLOR\r
+{\r
+       //float _r = rp(uv)*sigma*4.0;\r
+       //float env = exp( -(_r*_r) / 2.0 ) * alpha;\r
+       float _r = rp(uv)*8;\r
+       float env = exp( -(_r*_r) / (2.0) ) * alpha;\r
+\r
+       float _x = sin(orientation)*uv[0]-cos(orientation)*uv[1];\r
+       float l = 0.5+contrast*0.5*cos(frequency*_x + phase);\r
+       \r
+       float4 color = float4(l,l,l,1.0);\r
+       return color;\r
+}\r
diff --git a/dev4/Shader/GaborAlpha.ps b/dev4/Shader/GaborAlpha.ps
new file mode 100644 (file)
index 0000000..cdc54db
Binary files /dev/null and b/dev4/Shader/GaborAlpha.ps differ
diff --git a/dev4/Shader/Grating.fx b/dev4/Shader/Grating.fx
new file mode 100644 (file)
index 0000000..f3ddd05
--- /dev/null
@@ -0,0 +1,54 @@
+/// <summary>Amplitude of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>1</maxValue>\r
+/// <defaultValue>1</defaultValue>\r
+float contrast : register(C1);\r
+\r
+/// <summary>Phase of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>100</maxValue>\r
+/// <defaultValue>100</defaultValue>\r
+float frequency: register(C2);\r
+\r
+/// <summary>Phase of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float phase: register(C3);\r
+\r
+/// <summary>Orientation of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float orientation: register(C4);\r
+\r
+/// <summary>Width of envelope</summary>\r
+/// <minValue>1</minValue>\r
+/// <maxValue>1024</maxValue>\r
+/// <defaultValue>32</defaultValue>\r
+float SizeH : register(C5);\r
+\r
+/// <summary>Height of envelope</summary>\r
+/// <minValue>1</minValue>\r
+/// <maxValue>1024</maxValue>\r
+/// <defaultValue>32</defaultValue>\r
+float SizeV : register(C6);\r
+\r
+float rp(float2 uv)\r
+{\r
+       const float2 Center = float2(0.5,0.5);\r
+       float2 dir = uv - Center; // vector from center to pixel\r
+       float dist = length(dir);\r
+       //dir /= dist;\r
+       return dist;\r
+}\r
+\r
+float4 main(float2 uv : TEXCOORD) : COLOR\r
+{\r
+       float _x = sin(orientation)*uv[0]-cos(orientation)*uv[1];\r
+       float l = 0.5\r
+                 + contrast*0.5*cos(frequency*_x + phase);\r
+       \r
+       float4 color = float4(l,l,l,1.0);\r
+       return color;\r
+}\r
diff --git a/dev4/Shader/Grating.ps b/dev4/Shader/Grating.ps
new file mode 100644 (file)
index 0000000..1d39b76
Binary files /dev/null and b/dev4/Shader/Grating.ps differ
diff --git a/dev4/Shader/Plaid.fx b/dev4/Shader/Plaid.fx
new file mode 100644 (file)
index 0000000..1441994
--- /dev/null
@@ -0,0 +1,81 @@
+/// <summary>Amplitude of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>1</maxValue>\r
+/// <defaultValue>0.5</defaultValue>\r
+float contrast : register(C1);\r
+\r
+/// <summary>Phase of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>100</maxValue>\r
+/// <defaultValue>100</defaultValue>\r
+float frequency: register(C2);\r
+\r
+/// <summary>Phase of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float phase: register(C3);\r
+\r
+/// <summary>Orientation of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float orientation: register(C4);\r
+\r
+/// <summary>Amplitude of Grating2</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>1</maxValue>\r
+/// <defaultValue>0.5</defaultValue>\r
+float contrast2 : register(C5);\r
+\r
+/// <summary>Phase of Grating2</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>100</maxValue>\r
+/// <defaultValue>100</defaultValue>\r
+float frequency2: register(C6);\r
+\r
+/// <summary>Phase of Grating2</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float phase2: register(C7);\r
+\r
+/// <summary>Orientation of Grating2</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0.785398</defaultValue>\r
+float orientation2: register(C8);\r
+\r
+/// <summary>Width of envelope</summary>\r
+/// <minValue>1</minValue>\r
+/// <maxValue>1024</maxValue>\r
+/// <defaultValue>32</defaultValue>\r
+float SizeH : register(C9);\r
+\r
+/// <summary>Height of envelope</summary>\r
+/// <minValue>1</minValue>\r
+/// <maxValue>1024</maxValue>\r
+/// <defaultValue>32</defaultValue>\r
+float SizeV : register(C10);\r
+\r
+\r
+float rp(float2 uv)\r
+{\r
+       const float2 Center = float2(0.5,0.5);\r
+       float2 dir = uv - Center; // vector from center to pixel\r
+       float dist = length(dir);\r
+       //dir /= dist;\r
+       return dist;\r
+}\r
+\r
+float4 main(float2 uv : TEXCOORD) : COLOR\r
+{\r
+       float _x1 = sin(orientation)*uv[0]-cos(orientation)*uv[1];\r
+       float _x2 = sin(orientation2)*uv[0]-cos(orientation2)*uv[1];\r
+       float l = 0.5\r
+                 + contrast*0.5*cos(frequency*_x1 + phase)\r
+                 + contrast2*0.5*cos(frequency2*_x2 + phase2);\r
+       \r
+       float4 color = float4(l,l,l,1.0);\r
+       return color;\r
+}\r
diff --git a/dev4/Shader/Plaid.ps b/dev4/Shader/Plaid.ps
new file mode 100644 (file)
index 0000000..31eee86
Binary files /dev/null and b/dev4/Shader/Plaid.ps differ
diff --git a/dev4/WriteableBitmapEx/WriteableBitmapEx.XML b/dev4/WriteableBitmapEx/WriteableBitmapEx.XML
new file mode 100644 (file)
index 0000000..a307dd7
--- /dev/null
@@ -0,0 +1,940 @@
+<?xml version="1.0"?>\r
+<doc>\r
+    <assembly>\r
+        <name>WriteableBitmapEx</name>\r
+    </assembly>\r
+    <members>\r
+        <member name="T:System.Windows.Media.Imaging.WriteableBitmapExtensions">\r
+            <summary>\r
+            Collection of interchange extension methods for the Silverlight WriteableBitmap class.\r
+            </summary>\r
+            <summary>\r
+            Collection of draw extension methods for the Silverlight WriteableBitmap class.\r
+            </summary>\r
+            <summary>\r
+            Collection of draw extension methods for the Silverlight WriteableBitmap class.\r
+            </summary>\r
+            <summary>\r
+            Collection of blit (copy) extension methods for the Silverlight WriteableBitmap class.\r
+            </summary>\r
+            <summary>\r
+            Collection of draw extension methods for the Silverlight WriteableBitmap class.\r
+            </summary>\r
+            <summary>\r
+            Collection of draw spline extension methods for the Silverlight WriteableBitmap class.\r
+            </summary>\r
+            <summary>\r
+            Collection of transformation extension methods for the Silverlight WriteableBitmap class.\r
+            </summary>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ToByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
+            <summary>\r
+            Copies the Pixels from the WriteableBitmap into a ARGB byte array starting at a specific Pixels index.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="offset">The starting Pixels index.</param>\r
+            <param name="count">The number of Pixels to copy.</param>\r
+            <returns>The color buffer as byte ARGB values.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ToByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Int32)">\r
+            <summary>\r
+            Copies the Pixels from the WriteableBitmap into a ARGB byte array.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="count">The number of pixels to copy.</param>\r
+            <returns>The color buffer as byte ARGB values.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ToByteArray(System.Windows.Media.Imaging.WriteableBitmap)">\r
+            <summary>\r
+            Copies all the Pixels from the WriteableBitmap into a ARGB byte array.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <returns>The color buffer as byte ARGB values.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Byte[],System.Int32,System.Int32)">\r
+            <summary>\r
+            Copies color information from an ARGB byte array into this WriteableBitmap starting at a specific buffer index.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="offset">The starting index in the buffer.</param>\r
+            <param name="count">The number of bytes to copy from the buffer.</param>\r
+            <param name="buffer">The color buffer as byte ARGB values.</param>\r
+            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Byte[],System.Int32)">\r
+            <summary>\r
+            Copies color information from an ARGB byte array into this WriteableBitmap.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="count">The number of bytes to copy from the buffer.</param>\r
+            <param name="buffer">The color buffer as byte ARGB values.</param>\r
+            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Byte[])">\r
+            <summary>\r
+            Copies all the color information from an ARGB byte array into this WriteableBitmap.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="buffer">The color buffer as byte ARGB values.</param>\r
+            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.WriteTga(System.Windows.Media.Imaging.WriteableBitmap,System.IO.Stream)">\r
+            <summary>\r
+            Writes the WriteableBitmap as a TGA image to a stream. \r
+            Used with permission from Nokola: http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="destination">The destination stream.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromResource(System.Windows.Media.Imaging.WriteableBitmap,System.String)">\r
+            <summary>\r
+            Loads an image from the applications resource file and fills this WriteableBitmap with it.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="relativePath">Only the relative path to the resource file. The assembly name is retrieved automatically.</param>\r
+            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLineBresenham(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a colored line by connecting two points using the Bresenham algorithm.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLineBresenham(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a colored line by connecting two points using the Bresenham algorithm.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLineDDA(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a colored line by connecting two points using a DDA algorithm (Digital Differential Analyzer).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLineDDA(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a colored line by connecting two points using a DDA algorithm (Digital Differential Analyzer).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLine(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a colored line by connecting two points using an optimized DDA.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLine(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a colored line by connecting two points using an optimized DDA.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLine(System.Int32[],System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a colored line by connecting two points using an optimized DDA. \r
+            Uses the pixels array and the width directly for best performance.\r
+            </summary>\r
+            <param name="pixels">An array containing the pixels as int RGBA value.</param>\r
+            <param name="pixelWidth">The width of one scanline in the pixels array.</param>\r
+            <param name="pixelHeight">The height of the bitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawPolyline(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a polyline. Add the first point also at the end of the array if the line should be closed.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points of the polyline in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, ..., xn, yn).</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawPolyline(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Int32)">\r
+            <summary>\r
+            Draws a polyline. Add the first point also at the end of the array if the line should be closed.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points of the polyline in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, ..., xn, yn).</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawTriangle(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a triangle.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the 1st point.</param>\r
+            <param name="y1">The y-coordinate of the 1st point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawTriangle(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a triangle.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the 1st point.</param>\r
+            <param name="y1">The y-coordinate of the 1st point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawQuad(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a quad.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the 1st point.</param>\r
+            <param name="y1">The y-coordinate of the 1st point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd point.</param>\r
+            <param name="x4">The x-coordinate of the 4th point.</param>\r
+            <param name="y4">The y-coordinate of the 4th point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawQuad(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a quad.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the 1st point.</param>\r
+            <param name="y1">The y-coordinate of the 1st point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd point.</param>\r
+            <param name="x4">The x-coordinate of the 4th point.</param>\r
+            <param name="y4">The y-coordinate of the 4th point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawRectangle(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a rectangle.\r
+            x2 has to be greater than x1 and y2 has to be greater than y1.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
+            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
+            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
+            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawRectangle(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a rectangle.\r
+            x2 has to be greater than x1 and y2 has to be greater than y1.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
+            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
+            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
+            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipse(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
+            x2 has to be greater than x1 and y2 has to be greater than y1.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
+            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
+            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
+            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipse(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
+            x2 has to be greater than x1 and y2 has to be greater than y1.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
+            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
+            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
+            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipseCentered(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf\r
+            Uses a different parameter representation than DrawEllipse().\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="xc">The x-coordinate of the ellipses center.</param>\r
+            <param name="yc">The y-coordinate of the ellipses center.</param>\r
+            <param name="xr">The radius of the ellipse in x-direction.</param>\r
+            <param name="yr">The radius of the ellipse in y-direction.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipseCentered(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
+            Uses a different parameter representation than DrawEllipse().\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="xc">The x-coordinate of the ellipses center.</param>\r
+            <param name="yc">The y-coordinate of the ellipses center.</param>\r
+            <param name="xr">The radius of the ellipse in x-direction.</param>\r
+            <param name="yr">The radius of the ellipse in y-direction.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Clear(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Media.Color)">\r
+            <summary>\r
+            Fills the whole WriteableBitmap with a color.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="color">The color used for filling.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Clear(System.Windows.Media.Imaging.WriteableBitmap)">\r
+            <summary>\r
+            Fills the whole WriteableBitmap with an empty color (0).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Clone(System.Windows.Media.Imaging.WriteableBitmap)">\r
+            <summary>\r
+            Clones the specified WriteableBitmap.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <returns>A copy of the WriteableBitmap.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ForEach(System.Windows.Media.Imaging.WriteableBitmap,System.Func{System.Int32,System.Int32,System.Windows.Media.Color})">\r
+            <summary>\r
+            Applies the given function to all the pixels of the bitmap in \r
+            order to set their color.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="func">The function to apply. With parameters x, y and a color as a result</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ForEach(System.Windows.Media.Imaging.WriteableBitmap,System.Func{System.Int32,System.Int32,System.Windows.Media.Color,System.Windows.Media.Color})">\r
+            <summary>\r
+            Applies the given function to all the pixels of the bitmap in \r
+            order to set their color.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="func">The function to apply. With parameters x, y, source color and a color as a result</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.GetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
+            <summary>\r
+            Gets the color of the pixel at the x, y coordinate as integer.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate of the pixel.</param>\r
+            <param name="y">The y coordinate of the pixel.</param>\r
+            <returns>The color of the pixel at x, y.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.GetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
+            <summary>\r
+            Gets the color of the pixel at the x, y coordinate as a Color struct.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate of the pixel.</param>\r
+            <param name="y">The y coordinate of the pixel.</param>\r
+            <returns>The color of the pixel at x, y as a Color struct.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Byte,System.Byte,System.Byte)">\r
+            <summary>\r
+            Sets the color of the pixel using a precalculated index (faster).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="index">The coordinate index.</param>\r
+            <param name="r">The red value of the color.</param>\r
+            <param name="g">The green value of the color.</param>\r
+            <param name="b">The blue value of the color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Byte,System.Byte,System.Byte)">\r
+            <summary>\r
+            Sets the color of the pixel.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate (row).</param>\r
+            <param name="y">The y coordinate (column).</param>\r
+            <param name="r">The red value of the color.</param>\r
+            <param name="g">The green value of the color.</param>\r
+            <param name="b">The blue value of the color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Byte,System.Byte,System.Byte,System.Byte)">\r
+            <summary>\r
+            Sets the color of the pixel including the alpha value and using a precalculated index (faster).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="index">The coordinate index.</param>\r
+            <param name="a">The alpha value of the color.</param>\r
+            <param name="r">The red value of the color.</param>\r
+            <param name="g">The green value of the color.</param>\r
+            <param name="b">The blue value of the color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Byte,System.Byte,System.Byte,System.Byte)">\r
+            <summary>\r
+            Sets the color of the pixel including the alpha value.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate (row).</param>\r
+            <param name="y">The y coordinate (column).</param>\r
+            <param name="a">The alpha value of the color.</param>\r
+            <param name="r">The red value of the color.</param>\r
+            <param name="g">The green value of the color.</param>\r
+            <param name="b">The blue value of the color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Sets the color of the pixel using a precalculated index (faster).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="index">The coordinate index.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Sets the color of the pixel.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate (row).</param>\r
+            <param name="y">The y coordinate (column).</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Byte,System.Windows.Media.Color)">\r
+            <summary>\r
+            Sets the color of the pixel using an extra alpha value and a precalculated index (faster).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="index">The coordinate index.</param>\r
+            <param name="a">The alpha value of the color.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Byte,System.Windows.Media.Color)">\r
+            <summary>\r
+            Sets the color of the pixel using an extra alpha value.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate (row).</param>\r
+            <param name="y">The y coordinate (column).</param>\r
+            <param name="a">The alpha value of the color.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
+            <summary>\r
+            Sets the color of the pixel using a precalculated index (faster).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="index">The coordinate index.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Sets the color of the pixel.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate (row).</param>\r
+            <param name="y">The y coordinate (column).</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode)">\r
+            <summary>\r
+            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            </summary>\r
+            <param name="bmp">The destination WriteableBitmap.</param>\r
+            <param name="destRect">The rectangle that defines the destination region.</param>\r
+            <param name="source">The source WriteableBitmap.</param>\r
+            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
+            <param name="BlendMode">The blending mode <see cref="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode"/>.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect)">\r
+            <summary>\r
+            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            </summary>\r
+            <param name="bmp">The destination WriteableBitmap.</param>\r
+            <param name="destRect">The rectangle that defines the destination region.</param>\r
+            <param name="source">The source WriteableBitmap.</param>\r
+            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Point,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Color,System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode)">\r
+            <summary>\r
+            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            </summary>\r
+            <param name="bmp">The destination WriteableBitmap.</param>\r
+            <param name="destPosition">The destination position in the destination bitmap.</param>\r
+            <param name="source">The source WriteableBitmap.</param>\r
+            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
+            <param name="color">If not Colors.White, will tint the source image. A partially transparent color and the image will be drawn partially transparent.</param>\r
+            <param name="BlendMode">The blending mode <see cref="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode"/>.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Color,System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode)">\r
+            <summary>\r
+            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            </summary>\r
+            <param name="bmp">The destination WriteableBitmap.</param>\r
+            <param name="destRect">The rectangle that defines the destination region.</param>\r
+            <param name="source">The source WriteableBitmap.</param>\r
+            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
+            <param name="color">If not Colors.White, will tint the source image. A partially transparent color and the image will be drawn partially transparent.</param>\r
+            <param name="BlendMode">The blending mode <see cref="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode"/>.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillRectangle(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a filled rectangle.\r
+            x2 has to be greater than x1 and y2 has to be greater than y1.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
+            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
+            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
+            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillRectangle(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a filled rectangle.\r
+            x2 has to be greater than x1 and y2 has to be greater than y1.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
+            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
+            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
+            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillEllipse(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            A Fast Bresenham Type Algorithm For Drawing filled ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
+            x2 has to be greater than x1 and y2 has to be greater than y1.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
+            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
+            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
+            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillEllipse(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            A Fast Bresenham Type Algorithm For Drawing filled ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
+            x2 has to be greater than x1 and y2 has to be greater than y1.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
+            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
+            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
+            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillEllipseCentered(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            A Fast Bresenham Type Algorithm For Drawing filled ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
+            Uses a different parameter representation than DrawEllipse().\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="xc">The x-coordinate of the ellipses center.</param>\r
+            <param name="yc">The y-coordinate of the ellipses center.</param>\r
+            <param name="xr">The radius of the ellipse in x-direction.</param>\r
+            <param name="yr">The radius of the ellipse in y-direction.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillEllipseCentered(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            A Fast Bresenham Type Algorithm For Drawing filled ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
+            Uses a different parameter representation than DrawEllipse().\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="xc">The x-coordinate of the ellipses center.</param>\r
+            <param name="yc">The y-coordinate of the ellipses center.</param>\r
+            <param name="xr">The radius of the ellipse in x-direction.</param>\r
+            <param name="yr">The radius of the ellipse in y-direction.</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillPolygon(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a filled polygon. Add the first point also at the end of the array if the line should be closed.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points of the polygon in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, ..., xn, yn).</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillPolygon(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Int32)">\r
+            <summary>\r
+            Draws a filled polygon. Add the first point also at the end of the array if the line should be closed.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points of the polygon in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, ..., xn, yn).</param>\r
+            <param name="color">The color for the line.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillQuad(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a filled quad.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the 1st point.</param>\r
+            <param name="y1">The y-coordinate of the 1st point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd point.</param>\r
+            <param name="x4">The x-coordinate of the 4th point.</param>\r
+            <param name="y4">The y-coordinate of the 4th point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillQuad(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a filled quad.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the 1st point.</param>\r
+            <param name="y1">The y-coordinate of the 1st point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd point.</param>\r
+            <param name="x4">The x-coordinate of the 4th point.</param>\r
+            <param name="y4">The y-coordinate of the 4th point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillTriangle(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a filled triangle.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the 1st point.</param>\r
+            <param name="y1">The y-coordinate of the 1st point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillTriangle(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a filled triangle.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the 1st point.</param>\r
+            <param name="y1">The y-coordinate of the 1st point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ComputeBezierPoints(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32[],System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a filled, cubic Beziér spline defined by start, end and two control points.\r
+            </summary>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="cx1">The x-coordinate of the 1st control point.</param>\r
+            <param name="cy1">The y-coordinate of the 1st control point.</param>\r
+            <param name="cx2">The x-coordinate of the 2nd control point.</param>\r
+            <param name="cy2">The y-coordinate of the 2nd control point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color.</param>\r
+            <param name="pixels">The pixels array.</param>\r
+            <param name="w">The width of the bitmap.</param>\r
+            <param name="h">The height of the bitmap.</param> \r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillBeziers(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a series of filled, cubic Beziér splines each defined by start, end and two control points. \r
+            The ending point of the previous curve is used as starting point for the next. \r
+            Therfore the inital curve needs four points and the subsequent 3 (2 control and 1 end point).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, cx1, cy1, cx2, cy2, x2, y2, cx3, cx4 ..., xn, yn).</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillBeziers(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Int32)">\r
+            <summary>\r
+            Draws a series of filled, cubic Beziér splines each defined by start, end and two control points. \r
+            The ending point of the previous curve is used as starting point for the next. \r
+            Therfore the inital curve needs four points and the subsequent 3 (2 control and 1 end point).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, cx1, cy1, cx2, cy2, x2, y2, cx3, cx4 ..., xn, yn).</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ComputeSegmentPoints(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Single,System.Int32,System.Int32[],System.Int32,System.Int32)">\r
+            <summary>\r
+            Computes the discrete segment points of a Cardinal spline (cubic) defined by four control points.\r
+            </summary>\r
+            <param name="x1">The x-coordinate of the 1st control point.</param>\r
+            <param name="y1">The y-coordinate of the 1st control point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd control point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd control point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd control point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd control point.</param>\r
+            <param name="x4">The x-coordinate of the 4th control point.</param>\r
+            <param name="y4">The y-coordinate of the 4th control point.</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color.</param>\r
+            <param name="pixels">The pixels array.</param>\r
+            <param name="w">The width of the bitmap.</param>\r
+            <param name="h">The height of the bitmap.</param> \r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillCurve(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a filled Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillCurve(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Int32)">\r
+            <summary>\r
+            Draws a filled Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillCurveClosed(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a filled, closed Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillCurveClosed(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Int32)">\r
+            <summary>\r
+            Draws a filled, closed Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBezier(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a cubic Beziér spline defined by start, end and two control points.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="cx1">The x-coordinate of the 1st control point.</param>\r
+            <param name="cy1">The y-coordinate of the 1st control point.</param>\r
+            <param name="cx2">The x-coordinate of the 2nd control point.</param>\r
+            <param name="cy2">The y-coordinate of the 2nd control point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBezier(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a cubic Beziér spline defined by start, end and two control points.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="cx1">The x-coordinate of the 1st control point.</param>\r
+            <param name="cy1">The y-coordinate of the 1st control point.</param>\r
+            <param name="cx2">The x-coordinate of the 2nd control point.</param>\r
+            <param name="cy2">The y-coordinate of the 2nd control point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBeziers(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a series of cubic Beziér splines each defined by start, end and two control points. \r
+            The ending point of the previous curve is used as starting point for the next. \r
+            Therfore the inital curve needs four points and the subsequent 3 (2 control and 1 end point).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, cx1, cy1, cx2, cy2, x2, y2, cx3, cx4 ..., xn, yn).</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBeziers(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Int32)">\r
+            <summary>\r
+            Draws a series of cubic Beziér splines each defined by start, end and two control points. \r
+            The ending point of the previous curve is used as starting point for the next. \r
+            Therfore the inital curve needs four points and the subsequent 3 (2 control and 1 end point).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, cx1, cy1, cx2, cy2, x2, y2, cx3, cx4 ..., xn, yn).</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurveSegment(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Single,System.Int32,System.Int32[],System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a segment of a Cardinal spline (cubic) defined by four control points.\r
+            </summary>\r
+            <param name="x1">The x-coordinate of the 1st control point.</param>\r
+            <param name="y1">The y-coordinate of the 1st control point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd control point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd control point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd control point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd control point.</param>\r
+            <param name="x4">The x-coordinate of the 4th control point.</param>\r
+            <param name="y4">The y-coordinate of the 4th control point.</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color.</param>\r
+            <param name="pixels">The pixels array.</param>\r
+            <param name="w">The width of the bitmap.</param>\r
+            <param name="h">The height of the bitmap.</param> \r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurve(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurve(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Int32)">\r
+            <summary>\r
+            Draws a Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurveClosed(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a closed Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurveClosed(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Int32)">\r
+            <summary>\r
+            Draws a closed Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Crop(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Creates a new cropped WriteableBitmap.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate of the rectangle that defines the crop region.</param>\r
+            <param name="y">The y coordinate of the rectangle that defines the crop region.</param>\r
+            <param name="width">The width of the rectangle that defines the crop region.</param>\r
+            <param name="height">The height of the rectangle that defines the crop region.</param>\r
+            <returns>A new WriteableBitmap that is a cropped version of the input.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Crop(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect)">\r
+            <summary>\r
+            Creates a new cropped WriteableBitmap.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="region">The rectangle that defines the crop region.</param>\r
+            <returns>A new WriteableBitmap that is a cropped version of the input.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Resize(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation)">\r
+            <summary>\r
+            Creates a new resized WriteableBitmap.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="width">The new desired width.</param>\r
+            <param name="height">The new desired height.</param>\r
+            <param name="interpolation">The interpolation method that should be used.</param>\r
+            <returns>A new WriteableBitmap that is a resized version of the input.</returns>\r
+        </member>\r
+        <member name="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode">\r
+            <summary>\r
+            The blending mode.\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.Alpha">\r
+            <summary>\r
+            Alpha blendiing uses the alpha channel to combine the source and destination. \r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.Additive">\r
+            <summary>\r
+            Additive blending adds the colors of the source and the destination.\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.Subtractive">\r
+            <summary>\r
+            Subtractive blending subtracts the source color from the destination.\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.Mask">\r
+            <summary>\r
+            Uses the source color as a mask.\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.Multiply">\r
+            <summary>\r
+            Multiplies the source color with the destination color.\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.None">\r
+            <summary>\r
+            No blending just copies the pixels from the source.\r
+            </summary>\r
+        </member>\r
+        <member name="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation">\r
+            <summary>\r
+            The interpolation method.\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.NearestNeighbor">\r
+            <summary>\r
+            The nearest neighbor algorithm simply selects the color of the nearest pixel.\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear">\r
+            <summary>\r
+            Linear interpolation in 2D using the average of 3 neighboring pixels.\r
+            </summary>\r
+        </member>\r
+    </members>\r
+</doc>\r
diff --git a/dev4/WriteableBitmapEx/WriteableBitmapEx.dll b/dev4/WriteableBitmapEx/WriteableBitmapEx.dll
new file mode 100644 (file)
index 0000000..72956f0
Binary files /dev/null and b/dev4/WriteableBitmapEx/WriteableBitmapEx.dll differ
diff --git a/dev4/WriteableBitmapEx/WriteableBitmapEx.pdb b/dev4/WriteableBitmapEx/WriteableBitmapEx.pdb
new file mode 100644 (file)
index 0000000..cc55600
Binary files /dev/null and b/dev4/WriteableBitmapEx/WriteableBitmapEx.pdb differ
diff --git a/dev4/psychlops/core/app/app.cs b/dev4/psychlops/core/app/app.cs
new file mode 100644 (file)
index 0000000..827da65
--- /dev/null
@@ -0,0 +1,28 @@
+namespace Psychlops\r
+{\r
+\r
+       public static class AppState\r
+       {\r
+\r
+               public static string statusBar\r
+               {\r
+                       set { setStatusBar(value); }\r
+               }\r
+               internal static void setStatusBar(string str)\r
+               {\r
+                       Internal.Main.statusBar.Dispatcher.BeginInvoke(setStatusBar_, str);\r
+               }\r
+               internal static void setStatusBar__(string str)\r
+               {\r
+                       Internal.Main.statusBar.Text = str;\r
+               }\r
+               internal delegate void StringDelegate(string str);\r
+               internal static StringDelegate setStatusBar_;\r
+\r
+               static AppState()\r
+               {\r
+                       setStatusBar_ = new StringDelegate(setStatusBar__);\r
+               }\r
+       }\r
+\r
+}\r
diff --git a/dev4/psychlops/core/app/misc.cs b/dev4/psychlops/core/app/misc.cs
new file mode 100644 (file)
index 0000000..d0d44c0
--- /dev/null
@@ -0,0 +1,27 @@
+namespace Psychlops\r
+{\r
+\r
+       public static class Main\r
+       {\r
+               public static Drawable drawable;\r
+               public static Canvas canvas;\r
+\r
+       }\r
+\r
+       namespace Internal\r
+       {\r
+               public static class Main\r
+               {\r
+                       public static System.Threading.Thread routine;\r
+                       public static System.Threading.AutoResetEvent canvas_flag;\r
+                       public static System.Windows.Controls.Canvas layoutRoot;\r
+                       public static System.Windows.Controls.TextBlock statusBar;\r
+                       public static System.Windows.Controls.StackPanel widgetStack;\r
+\r
+                       static Main()\r
+                       {\r
+                               canvas_flag = new System.Threading.AutoResetEvent(false);\r
+                       }\r
+               }\r
+       }\r
+}\r
diff --git a/dev4/psychlops/core/graphic/canvas.cs b/dev4/psychlops/core/graphic/canvas.cs
new file mode 100644 (file)
index 0000000..e67c6ae
--- /dev/null
@@ -0,0 +1,1410 @@
+using System;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Animation;\r
+using System.Windows.Media.Imaging;\r
+using System.Windows.Shapes;\r
+using System.Windows.Browser;\r
+\r
+using System.Collections.Generic;\r
\r
+\r
+\r
+namespace Psychlops\r
+{\r
+\r
+       internal static partial class CONST\r
+       {\r
+               internal static readonly Int32 MAX_OBJ_N = 1500;\r
+               internal static readonly Int32 MOBJ_N = 1000;\r
+               internal static readonly Int32 COBJ_N = 300;\r
+               internal static readonly Int32 HOBJ_N = 100;\r
+       }\r
+\r
+       namespace Templates\r
+       {\r
+\r
+               public class StackableDrawable : Drawable\r
+               {\r
+//                     protected System.Collections.Generic.Queue<Internal.PrimitiveFigure> stack;\r
+                       internal Internal.PrimitiveFigure[] stack;\r
+                       internal int stackN = 0;\r
+                       internal Line[] lineStack;\r
+                       internal int lineStackN = 0;\r
+                       internal Rectangle[] rectStack;\r
+                       internal int rectStackN = 0;\r
+                       internal ShaderField[] shaderStack;\r
+                       internal int shaderStackN = 0;\r
+                       internal Ellipse[] ellipseStack;\r
+                       internal int ellipseStackN = 0;\r
+                       internal Polygon[] polygonStack;\r
+                       internal int polygonStackN = 0;\r
+                       internal Letters[] lettersStack;\r
+                       internal int lettersStackN = 0;\r
+                       internal Image[] imageStack;\r
+                       internal int imageStackN = 0;\r
+                       internal Group[] groupStack;\r
+                       internal int groupStackN = 0;\r
+\r
+                       public StackableDrawable()\r
+                       {\r
+                               stack = new Internal.PrimitiveFigure[CONST.MAX_OBJ_N];\r
+                               lineStack = new Line[CONST.MOBJ_N];\r
+                               rectStack = new Rectangle[CONST.MOBJ_N];\r
+                               ellipseStack = new Ellipse[CONST.MOBJ_N];\r
+                               shaderStack = new ShaderField[CONST.COBJ_N];\r
+                               polygonStack = new Polygon[CONST.COBJ_N];\r
+                               lettersStack = new Letters[CONST.COBJ_N];\r
+                               imageStack = new Image[CONST.HOBJ_N];\r
+                               groupStack = new Group[CONST.HOBJ_N];\r
+                               for (int i = 0; i < CONST.MOBJ_N; i++)\r
+                               {\r
+                                       lineStack[i] = new Line(0,0,0,0);\r
+                                       rectStack[i] = new Rectangle();\r
+                                       ellipseStack[i] = new Ellipse();\r
+                               }\r
+                               for (int i = 0; i < CONST.COBJ_N; i++)\r
+                               {\r
+                                       shaderStack[i] = new ShaderField();\r
+                                       polygonStack[i] = new Polygon();\r
+                                       lettersStack[i] = new Letters();\r
+                               }\r
+                               for (int i = 0; i < CONST.HOBJ_N; i++)\r
+                               {\r
+                                       imageStack[i] = new Image();\r
+//                                     groupStack[i] = new Group();\r
+                               }\r
+\r
+\r
+                       }\r
+\r
+                       public void clear() { clear(Color.black); }\r
+                       public virtual void clear(Color col) { } //rect(back_panel, col); }\r
+                       public virtual void pix(int x, int y, Color col) { }\r
+                       public virtual void line(Line drawee) { drawee.copyToStack(this); }\r
+                       public virtual void rect(Rectangle drawee) { drawee.copyToStack(this); }\r
+                       public virtual void ellipse(Ellipse drawee) { drawee.copyToStack(this); }\r
+                       public virtual void oval(Ellipse drawee) { drawee.copyToStack(this); }\r
+                       public virtual void polygon(Polygon drawee) { drawee.copyToStack(this); }\r
+                       public virtual void letters(Letters drawee) { drawee.copyToStack(this); }\r
+                       public virtual void image(Image drawee) { drawee.copyToStack(this); }\r
+                       public virtual void group(Group drawee) { drawee.copyToStack(this); }\r
+                       public virtual void shader(ShaderField drawee) { drawee.copyToStack(this); }\r
+\r
+                       public void msg(string str, double x, double y) { msg(str, x, y, Color.white); }\r
+                       public virtual void msg(string dstr, double x, double y, Color col)\r
+                       {\r
+                               var let = new Letters(dstr);\r
+                               let.locate(x, y);\r
+                               let.fill = col;\r
+                               this.letters(let);\r
+                       }\r
+                       public void var<Type>(Type val, double x, double y) { msg(val.ToString(), x, y, Color.white); }\r
+                       public void var<Type>(Type val, double x, double y, Color col) { msg(val.ToString(), x, y, col); }\r
+\r
+                       public virtual Point getCenter() { return new Point(0, 0, 0); }\r
+               }\r
+\r
+       }\r
+\r
+       public class Canvas : Templates.StackableDrawable\r
+       {\r
+               internal System.Windows.Controls.Canvas masterPool, prevPool;\r
+               internal System.Windows.Point[] pointPool;\r
+               internal int pointPoolN;\r
+               internal SolidColorBrush[] brushPool;\r
+               internal int brushPoolN;\r
+\r
+               internal System.Windows.Controls.Canvas[] UIElementPool;\r
+               internal int UIElementPoolN;\r
+               internal int lastVisibleN;\r
+\r
+               internal System.Windows.Shapes.Line[] linePool;\r
+               internal int linePoolN;\r
+               internal System.Windows.Shapes.Rectangle[] dummyRectPool;\r
+               internal System.Windows.Shapes.Rectangle[] rectPool;\r
+               internal int rectPoolN;\r
+               internal System.Windows.Shapes.Rectangle[] shaderPool;\r
+               internal int shaderPoolN;\r
+               internal System.Windows.Shapes.Ellipse[] ellipsePool;\r
+               internal int ellipsePoolN;\r
+               internal System.Windows.Shapes.Polygon[] polygonPool;\r
+               internal int polygonPoolN;\r
+               internal System.Windows.Controls.TextBlock[] lettersPool;\r
+               internal int lettersPoolN;\r
+               internal System.Windows.Controls.Image[] imagePool;\r
+               internal int imagePoolN;\r
+               internal Dictionary<int, bool> imagePoolT;\r
+               internal System.Windows.Controls.Canvas[] groupPool;\r
+               internal int groupPoolN;\r
+\r
+               #region initializer\r
+\r
+               Action flipexec;\r
+               public static IList<Action> initialize_at_canvas_initialize__ = new List<Action>();\r
+\r
+               public static System.Windows.Controls.UserControl default_panel;\r
+               public static System.Windows.Controls.Canvas default_api_canvas;\r
+               public static WriteableBitmap default_buffer;\r
+               internal System.Windows.Controls.Canvas api_canvas;\r
+               internal System.Windows.Controls.UserControl panel;\r
+               Rectangle back_panel;\r
+               double width_, height_;\r
+               Clock before;\r
+\r
+               public Canvas(int wid, int hei)\r
+               {\r
+                       panel = default_panel;\r
+                       api_canvas = default_api_canvas;\r
+                       initialize(wid, hei);\r
+               }\r
+               public Canvas(int wid, int hei, System.Windows.Controls.Canvas apicnvs, System.Windows.Controls.UserControl system)\r
+               {\r
+                       panel = system;\r
+                       api_canvas = apicnvs;\r
+                       initialize(wid, hei);\r
+               }\r
+\r
+               protected bool AsyncInitBool;\r
+               internal void beginInvoke(Action a) { api_canvas.Dispatcher.BeginInvoke(a); }\r
+               protected void initialize(int wid, int hei)\r
+               {\r
+                       before = new Clock();\r
+                       before.update();\r
+                       var after = new Clock();\r
+                       AsyncInitBool = false;\r
+                       width_ = wid;\r
+                       height_ = hei;\r
+                       api_canvas.Dispatcher.BeginInvoke(new Action<int,int>(initialize__), wid, hei);\r
+                       while (!AsyncInitBool)\r
+                       {\r
+                               after.update();\r
+                               if ((after - before).at_msec() > 1000) break;\r
+                       }\r
+                       Mouse._prime = api_canvas;\r
+                       Main.drawable = this;\r
+                       Main.canvas = this;\r
+\r
+                       back_panel = new Rectangle(wid, hei);\r
+\r
+                       flipexec = new Action(executeFlip);\r
+               }\r
+               protected void initialize__(int wid, int hei)\r
+               {\r
+                       api_canvas.Width = wid;\r
+                       api_canvas.Height = hei+20;\r
+                       api_canvas.MouseMove += Mouse.Canvas_MousePos;\r
+                       api_canvas.MouseLeftButtonDown += Mouse.Canvas_LDown;\r
+                       api_canvas.MouseLeftButtonUp += Mouse.Canvas_LUp;\r
+                       api_canvas.MouseWheel += Mouse.Canvas_MouseWheel;\r
+                       panel.KeyDown += Keyboard.Canvas_KeyDown;\r
+                       panel.KeyUp += Keyboard.Canvas_KeyUp;\r
+\r
+                       HtmlElement htmlHost = HtmlPage.Document.GetElementById("silverlightControlHost");\r
+                       //if (htmlHost != null) HtmlPage.Window.Alert("silverlightControlHost is null");\r
+                       htmlHost.SetStyleAttribute("width", (wid).ToString()+"px");\r
+                       htmlHost.SetStyleAttribute("height", (hei).ToString() + "px");\r
+                       htmlHost.SetStyleAttribute("margin", "2em auto auto auto");\r
+\r
+                       pointPool = new System.Windows.Point[CONST.MOBJ_N];\r
+                       brushPool = new SolidColorBrush[CONST.MOBJ_N];\r
+                       linePool = new System.Windows.Shapes.Line[CONST.MOBJ_N];\r
+                       rectPool = new System.Windows.Shapes.Rectangle[CONST.MOBJ_N];\r
+                       ellipsePool = new System.Windows.Shapes.Ellipse[CONST.MOBJ_N];\r
+                       for (int i = 0; i < CONST.MOBJ_N; i++)\r
+                       {\r
+                               pointPool[i] = new System.Windows.Point();\r
+                               brushPool[i] = new SolidColorBrush();\r
+                               linePool[i] = new System.Windows.Shapes.Line();\r
+                               rectPool[i] = new System.Windows.Shapes.Rectangle();\r
+                               ellipsePool[i] = new System.Windows.Shapes.Ellipse();\r
+                       }\r
+                       shaderPool = new System.Windows.Shapes.Rectangle[CONST.COBJ_N];\r
+                       polygonPool = new System.Windows.Shapes.Polygon[CONST.COBJ_N];\r
+                       lettersPool = new System.Windows.Controls.TextBlock[CONST.COBJ_N];\r
+                       for (int i = 0; i < CONST.COBJ_N; i++)\r
+                       {\r
+                               shaderPool[i] = new System.Windows.Shapes.Rectangle();\r
+                               polygonPool[i] = new System.Windows.Shapes.Polygon();\r
+                               lettersPool[i] = new System.Windows.Controls.TextBlock();\r
+                       }\r
+                       imagePool = new System.Windows.Controls.Image[CONST.HOBJ_N];\r
+                       imagePoolT = new Dictionary<int, bool>(CONST.HOBJ_N);\r
+                       groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N];\r
+                       for (int i = 0; i < CONST.HOBJ_N; i++)\r
+                       {\r
+                               imagePool[i] = new System.Windows.Controls.Image();\r
+                               imagePoolT.Add(imagePool[i].GetHashCode(), false);\r
+                               groupPool[i] = new System.Windows.Controls.Canvas();\r
+                       }\r
+\r
+                       masterPool = new System.Windows.Controls.Canvas();\r
+                       prevPool = new System.Windows.Controls.Canvas();\r
+                       api_canvas.Children.Add(masterPool);\r
+\r
+                       //api_canvas.Children.Remove(Internal.Main.widgetStack);\r
+                       Psychlops.Internal.Main.widgetStack = new StackPanel();\r
+                       Psychlops.Internal.Main.widgetStack.Orientation = Orientation.Vertical;\r
+                       Psychlops.Internal.Main.widgetStack.Height = hei;\r
+                       api_canvas.Children.Add(Psychlops.Internal.Main.widgetStack);\r
+                       Internal.Main.statusBar.Visibility = Visibility.Collapsed;\r
+\r
+\r
+                       UIElementPool = new System.Windows.Controls.Canvas[CONST.MAX_OBJ_N];\r
+                       dummyRectPool = new System.Windows.Shapes.Rectangle[CONST.MAX_OBJ_N];\r
+                       for (int i = 0; i < CONST.MAX_OBJ_N; i++)\r
+                       {\r
+                               UIElementPool[i] = new System.Windows.Controls.Canvas();\r
+                               masterPool.Children.Add(UIElementPool[i]);\r
+                               dummyRectPool[i] = new System.Windows.Shapes.Rectangle();\r
+                               UIElementPool[i].Children.Add(dummyRectPool[i]);\r
+                               dummyRectPool[i].Visibility = Visibility.Collapsed;\r
+                       }\r
+\r
+                       AsyncInitBool = true;\r
+\r
+                       // initialize at Canvas initializing\r
+                       //Figures.ShaderGabor.initialize__();\r
+               }\r
+\r
+               internal int findEmptyInPool(Dictionary<int, bool> pool)\r
+               {\r
+                       /*\r
+                       foreach( KeyValuePair<int, bool> elem in pool)\r
+                       {\r
+                               if(elem) \r
+                       }*/\r
+                       return 0;\r
+               }\r
+\r
+               #endregion\r
+\r
+               #region static initializer\r
+               /*\r
+               static Canvas()\r
+               {\r
+               }\r
+               */\r
+               #endregion\r
+\r
+\r
+               public override void clear(Color col)\r
+               {\r
+                       back_panel.fill = col;\r
+                       stackN = 0;\r
+                       rect(back_panel);\r
+               }\r
+\r
+               int nextIntervalFrame = 1, chacked = 0;\r
+               public void flip(int n)\r
+               {\r
+                       lock (this)\r
+                       {\r
+                               nextIntervalFrame = n;\r
+                               chacked = 1;\r
+                       }\r
+                       //pointStackN = 0;\r
+                       lineStackN = 0;\r
+                       rectStackN = 0;\r
+                       shaderStackN = 0;\r
+                       polygonStackN = 0;\r
+                       ellipseStackN = 0;\r
+                       lettersStackN = 0;\r
+                       imageStackN = 0;\r
+                       groupStackN = 0;\r
+\r
+                       UIElementPoolN = 0;\r
+                       brushPoolN = 0;\r
+                       /*\r
+                       pointPoolN = 0;\r
+                       brushPoolN = 0;\r
+                       linePoolN = 0;\r
+                       rectPoolN = 0;\r
+                       ellipsePoolN = 0;\r
+                       polygonPoolN = 0;\r
+                       lettersPoolN = 0;\r
+                       imagePoolN = 0;\r
+                       groupPoolN = 0;\r
+                        * */\r
+\r
+                       //executeFlip();\r
+                       Internal.Main.canvas_flag.WaitOne();\r
+               }\r
+               public void flip()\r
+               {\r
+                       flip(1);\r
+               }\r
+\r
+\r
+               #region version modifyNative2\r
+               public void executeFlip()\r
+               {\r
+//                     Clock after = new Clock();\r
+//                     after.update();\r
+//                     AppState.statusBar = ((after - before).at_msec().ToString()) + " msec";\r
+\r
+                       Line lineS;\r
+                       ShaderField shaderS;\r
+                       Rectangle rectS;\r
+                       Ellipse ellipseS;\r
+                       Polygon polygonS;\r
+                       Letters lettersS;\r
+                       Image imageS;\r
+                       Group groupS;\r
+                       System.Windows.Shapes.Line lineP;\r
+                       System.Windows.Shapes.Rectangle rectP;\r
+                       System.Windows.Shapes.Rectangle shaderP;\r
+                       System.Windows.Shapes.Ellipse ellipseP;\r
+                       System.Windows.Shapes.Polygon polygonP;\r
+                       System.Windows.Controls.TextBlock lettersP;\r
+                       System.Windows.Controls.Image imageP;\r
+                       System.Windows.Controls.Canvas groupP;\r
+\r
+                       lock (this)\r
+                       {\r
+                               nextIntervalFrame--;\r
+                       }\r
+\r
+                       var cnv = UIElementPool[0];\r
+                       if (nextIntervalFrame <= 0)\r
+                       {\r
+                               if (chacked > 0)\r
+                               {\r
+                                       if (stackN > 0)\r
+                                       {\r
+                                               for (int i = 0; i < stackN; i++)\r
+                                               {\r
+                                                       if (null != (shaderS = stack[i] as ShaderField))\r
+                                                       {\r
+                                                               if (null != (shaderP = cnv.Children[0] as System.Windows.Shapes.Rectangle))\r
+                                                               {\r
+                                                                       shaderS.modifyNative(shaderP, this);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
+                                                               }\r
+                                                       }\r
+                                                       else if( null != (rectS = stack[i] as Rectangle) )\r
+                                                       {\r
+                                                               if (null != (rectP = cnv.Children[0] as System.Windows.Shapes.Rectangle))\r
+                                                               {\r
+                                                                       rectS.modifyNative(rectP, this);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
+                                                               }\r
+                                                       }\r
+                                                       else if (null != (lineS = stack[i] as Line))\r
+                                                       {\r
+                                                               if (null != (lineP = cnv.Children[0] as System.Windows.Shapes.Line))\r
+                                                               {\r
+                                                                       lineS.modifyNative(lineP, this);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
+                                                               }\r
+                                                       }\r
+                                                       else if (null != (ellipseS = stack[i] as Ellipse))\r
+                                                       {\r
+                                                               if (null != (ellipseP = cnv.Children[0] as System.Windows.Shapes.Ellipse))\r
+                                                               {\r
+                                                                       ellipseS.modifyNative(ellipseP, this);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
+                                                               }\r
+                                                       }\r
+                                                       else if (null != (polygonS = stack[i] as Polygon))\r
+                                                       {\r
+                                                               if (null != (polygonP = cnv.Children[0] as System.Windows.Shapes.Polygon))\r
+                                                               {\r
+                                                                       polygonS.modifyNative(polygonP, this);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
+                                                               }\r
+                                                       }\r
+                                                       else if (null != (lettersS = stack[i] as Letters))\r
+                                                       {\r
+                                                               if (null != (lettersP = cnv.Children[0] as System.Windows.Controls.TextBlock))\r
+                                                               {\r
+                                                                       lettersS.modifyNative(lettersP, this);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
+                                                               }\r
+                                                       }\r
+                                                       else if (null != (imageS = stack[i] as Image))\r
+                                                       {\r
+                                                               if (null != (imageP = cnv.Children[0] as System.Windows.Controls.Image))\r
+                                                               {\r
+                                                                       imageS.modifyNative(imageP, this);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
+                                                               }\r
+                                                       }\r
+                                                       else if (null != (groupS = stack[i] as Group))\r
+                                                       {\r
+                                                               if (null != (groupP = cnv.Children[0] as System.Windows.Controls.Canvas))\r
+                                                               {\r
+                                                                       groupS.modifyNative(groupP, this);\r
+                                                               }\r
+                                                               else\r
+                                                               {\r
+                                                                       cnv.Children.Clear();\r
+                                                                       cnv.Children.Add(stack[i].poolNative(this));\r
+                                                               }\r
+                                                       }\r
+                                                       cnv.Visibility = Visibility.Visible;\r
+                                                       UIElementPoolN++;\r
+                                                       cnv = UIElementPool[UIElementPoolN];\r
+                                               }\r
+                                               for (int i = UIElementPoolN; i < lastVisibleN; i++)\r
+                                               {\r
+                                                       cnv = UIElementPool[i];\r
+                                                       cnv.Visibility = Visibility.Collapsed;\r
+                                               }\r
+                                               lastVisibleN = UIElementPoolN;\r
+                                               stackN = 0;\r
+                                       }\r
+                                       lock (this)\r
+                                       {\r
+                                               chacked = 0;\r
+                                       }\r
+                                       Psychlops.Internal.Main.canvas_flag.Set();\r
+                               }\r
+                       }\r
+                       System.Threading.Thread.Sleep(0);\r
+               }\r
+               #endregion\r
+\r
+\r
+\r
+               #region version modifyNative\r
+               /*\r
+               public void executeFlip()\r
+               {\r
+                       Line lineS;\r
+                       Rectangle rectS;\r
+                       Ellipse ellipseS;\r
+                       Polygon polygonS;\r
+                       Letters lettersS;\r
+                       Image imageS;\r
+                       Group groupS;\r
+                       System.Windows.Shapes.Line lineP;\r
+                       System.Windows.Shapes.Rectangle rectP;\r
+                       System.Windows.Shapes.Ellipse ellipseP;\r
+                       System.Windows.Shapes.Polygon polygonP;\r
+                       System.Windows.Controls.TextBlock lettersP;\r
+                       System.Windows.Controls.Image imageP;\r
+                       System.Windows.Controls.Canvas groupP;\r
+\r
+                       lock (this)\r
+                       {\r
+                               nextIntervalFrame--;\r
+                       }\r
+\r
+                       var en = masterPool.Children.GetEnumerator();\r
+                       bool full = en.MoveNext();\r
+                       if (nextIntervalFrame <= 0)\r
+                       {\r
+                               if (chacked > 0)\r
+                               {\r
+                                       //masterPool.Children.Clear();\r
+                                       if (stackN > 0)\r
+                                       {\r
+                                               for (int i = 0; i < stackN - 2; i++)\r
+                                               {\r
+                                                       if (full == false)\r
+                                                       {\r
+                                                               masterPool.Children.Add(stack[i].poolNative(this));\r
+                                                       }\r
+                                                       else\r
+                                                       {\r
+                                                               if( null != (rectS = stack[i] as Rectangle) )\r
+                                                               {\r
+                                                                       if (null != (rectP = en.Current as System.Windows.Shapes.Rectangle))\r
+                                                                       {\r
+                                                                               rectS.modifyNative(rectP, this);\r
+                                                                       }\r
+                                                               }\r
+                                                               else if (null != (lineS = stack[i] as Line))\r
+                                                               {\r
+                                                                       if (null != (lineP = en.Current as System.Windows.Shapes.Line))\r
+                                                                       {\r
+                                                                               lineS.modifyNative(lineP, this);\r
+                                                                       }\r
+                                                               }\r
+                                                               else if (null != (ellipseS = stack[i] as Ellipse))\r
+                                                               {\r
+                                                                       if (null != (ellipseP = en.Current as System.Windows.Shapes.Ellipse))\r
+                                                                       {\r
+                                                                               ellipseS.modifyNative(ellipseP, this);\r
+                                                                       }\r
+                                                                       else\r
+                                                                       {\r
+                                                                               masterPool.Children.Add(stack[i].poolNative(this));\r
+                                                                       }\r
+                                                               }\r
+                                                               else if (null != (polygonS = stack[i] as Polygon))\r
+                                                               {\r
+                                                                       if (null != (polygonP = en.Current as System.Windows.Shapes.Polygon))\r
+                                                                       {\r
+                                                                               polygonS.modifyNative(polygonP, this);\r
+                                                                       }\r
+                                                               }\r
+                                                               else if (null != (lettersS = stack[i] as Letters))\r
+                                                               {\r
+                                                                       if (null != (lettersP = en.Current as System.Windows.Controls.TextBlock))\r
+                                                                       {\r
+                                                                               lettersS.modifyNative(lettersP, this);\r
+                                                                       }\r
+                                                               }\r
+                                                               else if (null != (imageS = stack[i] as Image))\r
+                                                               {\r
+                                                                       if (null != (imageP = en.Current as System.Windows.Controls.Image))\r
+                                                                       {\r
+                                                                               imageS.modifyNative(imageP, this);\r
+                                                                       }\r
+                                                               }\r
+                                                               else if (null != (groupS = stack[i] as Group))\r
+                                                               {\r
+                                                                       if (null != (groupP = en.Current as System.Windows.Controls.Canvas))\r
+                                                                       {\r
+                                                                               groupS.modifyNative(groupP, this);\r
+                                                                       }\r
+                                                               }\r
+                                                               full = en.MoveNext();\r
+                                                       }\r
+                                               }\r
+                                               stackN = 0;\r
+                                       }\r
+                                       lock (this)\r
+                                       {\r
+                                               chacked = 0;\r
+                                       }\r
+                                       Psychlops.Internal.Main.canvas_flag.Set();\r
+                               }\r
+                       }\r
+                       System.Threading.Thread.Sleep(0);\r
+               }\r
+                * */\r
+               #endregion\r
+\r
+               #region version poolNative 2\r
+               /*\r
+               public void executeFlip()\r
+               {\r
+\r
+                       lock (this)\r
+                       {\r
+                               nextIntervalFrame--;\r
+                       }\r
+                       UIElementPoolN = 0;\r
+                       if (nextIntervalFrame <= 0)\r
+                       {\r
+                               if (chacked > 0)\r
+                               {\r
+                                       //masterPool.Children.Clear();\r
+                                       if (stackN > 0)\r
+                                       {\r
+                                               for (int i = 0; i < stackN - 2; i++)\r
+                                               {\r
+                                                       UIElementPool[UIElementPoolN] = stack[i].poolNative(this);\r
+                                                       UIElementPool[UIElementPoolN].Visibility = Visibility.Visible;\r
+                                                       UIElementPoolN++;\r
+\r
+                                               }\r
+                                               for (int i = stackN - 2; i < 10000; i++)\r
+                                               {\r
+                                                       UIElementPool[UIElementPoolN] = rectPool[i];\r
+                                                       UIElementPool[UIElementPoolN].Visibility = Visibility.Collapsed;\r
+                                                       UIElementPoolN++;\r
+                                               }\r
+                                               stackN = 0;\r
+                                       }\r
+                                       lock (this)\r
+                                       {\r
+                                               chacked = 0;\r
+                                       }\r
+                                       Psychlops.Internal.Main.canvas_flag.Set();\r
+                               }\r
+                       }\r
+                       System.Threading.Thread.Sleep(0);\r
+               }\r
+               */\r
+               #endregion\r
+\r
+\r
+               #region Properties\r
+\r
+               public double width { get { return width_; } }\r
+               public double height { get { return height_; } }\r
+               public Point center { get { return new Point(width / 2.0, height / 2.0, 0); } }\r
+               public double getWidth() { return width; }\r
+               public double getHeight() { return height; }\r
+               public override Point getCenter() { return center; }\r
+               public double getHCenter() { return width / 2; }\r
+               public double getVCenter() { return height / 2; }\r
+               public double getRefreshRate() { return 60; }\r
+\r
+               #endregion\r
+\r
+\r
+               #region compatibitily trick\r
+\r
+               public enum Mode { window, fullscreen }\r
+               public static readonly Mode window = Mode.window, fullscreen = Mode.fullscreen;\r
+\r
+               public Canvas(int wid, int hei, Mode mod)\r
+               {\r
+                       panel = default_panel;\r
+                       api_canvas = default_api_canvas;\r
+                       initialize(500, 500);\r
+               }\r
+               public Canvas(Mode mod)\r
+                       : base()\r
+               {\r
+                       panel = default_panel;\r
+                       api_canvas = default_api_canvas;\r
+                       initialize(500, 500);\r
+               }\r
+\r
+               public Canvas(int wid, int hei, Mode mod, Display.DisplayName name)\r
+               {\r
+                       panel = default_panel;\r
+                       api_canvas = default_api_canvas;\r
+                       initialize(500, 500);\r
+               }\r
+               public Canvas(Mode mod, Display.DisplayName name)\r
+                       : base()\r
+               {\r
+                       panel = default_panel;\r
+                       api_canvas = default_api_canvas;\r
+                       initialize(500, 500);\r
+               }\r
+\r
+\r
+               public void showFPS(bool sw = true) { }\r
+               public void watchFPS(bool sw = true) { }\r
+\r
+\r
+               public void clear(double lum)\r
+               {\r
+                       clear(new Color(lum));\r
+               }\r
+\r
+               #endregion\r
+\r
+\r
+       }\r
+\r
+\r
+\r
+       #region primitive tokenizer\r
+\r
+\r
+       #region primitive\r
+\r
+       partial struct Point\r
+       {\r
+               public static implicit operator System.Windows.Point(Point d)\r
+               {\r
+                       return new System.Windows.Point(d.x, d.y);\r
+               }\r
+\r
+\r
+               public Point datum { get { return this; } set { this = value; } }\r
+               public Point shift(Point p) { this = this + p; return this; }\r
+               public Point centering(Point p) { this = p; return this; }\r
+               public Point getDatum() { return this; }\r
+               public Point setDatum(Point p) { this = p; return p; }\r
+               public Point shift(double x, double y, double z = 0.0) { return shift(new Point(x, y, z)); }\r
+               public Point centering() { return centering(Main.drawable.getCenter()); }\r
+               public Point centering(double x, double y, double z = 0.0) { return centering(new Point(x, y, z)); }\r
+       }\r
+\r
+       partial struct Color\r
+       {\r
+               public static implicit operator System.Windows.Media.Color(Color d)\r
+               {\r
+                       return System.Windows.Media.Color.FromArgb((byte)(d.a * 255), (byte)(d.r * 255), (byte)(d.g * 255), (byte)(d.b * 255));\r
+               }\r
+               public static implicit operator System.Windows.Media.SolidColorBrush(Color d)\r
+               {\r
+                       return new SolidColorBrush { Color = d };\r
+               }\r
+               public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)\r
+               {\r
+                       var tmp = d.brushPool[d.brushPoolN];\r
+                       tmp.Color = this;\r
+                       d.brushPoolN++;\r
+                       return tmp;\r
+               }\r
+\r
+       }\r
+\r
+       partial struct Stroke\r
+       {\r
+               public void apply(System.Windows.Shapes.Shape target)\r
+               {\r
+                       target.Stroke = this;\r
+                       //target.StrokeDashArray\r
+                       target.StrokeThickness = thick;\r
+               }\r
+               public static implicit operator SolidColorBrush(Stroke d)\r
+               {\r
+                       return new SolidColorBrush { Color = d.color };\r
+               }\r
+               public System.Windows.Media.SolidColorBrush getNativeFromStack(Canvas d)\r
+               {\r
+                       var tmp = d.brushPool[d.brushPoolN];\r
+                       tmp.Color = this.color;\r
+                       d.brushPoolN++;\r
+                       return tmp;\r
+               }\r
+       }\r
+       \r
+       #endregion\r
+       \r
+       #region Line\r
+\r
+       partial class Line\r
+       {\r
+               public Line dup()\r
+               {\r
+                       return (Line)MemberwiseClone();\r
+               }\r
+               public Line clone()\r
+               {\r
+                       return (Line)MemberwiseClone();\r
+               }\r
+               public static implicit operator System.Windows.Shapes.Line(Line d)\r
+               {\r
+                       var tmp =  new System.Windows.Shapes.Line() { X1 = d.begin.x, Y1 = d.begin.y, X2 = d.end.x, Y2 = d.end.y };\r
+                       if (d.stroke.thick == 0.0) tmp.Stroke = d.fill;\r
+                       else d.stroke.apply(tmp);\r
+                       return tmp;\r
+               }\r
+               public UIElement toNative() { return this; }\r
+\r
+               public void copyToStack(Templates.StackableDrawable d)\r
+               {\r
+                       var tmp = d.lineStack[d.lineStackN];\r
+                       tmp.begin.x = begin.x;\r
+                       tmp.begin.y = begin.y;\r
+                       tmp.end.x = end.x;\r
+                       tmp.end.y = end.y;\r
+                       tmp.fill = fill;\r
+                       tmp.stroke = stroke;\r
+                       d.stack[d.stackN] = tmp;\r
+                       d.lineStackN++;\r
+                       d.stackN++;\r
+               }\r
+               public UIElement poolNative(Canvas d)\r
+               {\r
+                       var tmp = d.linePool[d.linePoolN];\r
+                       tmp.X1 = begin.x;\r
+                       tmp.Y1 = begin.y;\r
+                       tmp.X2 = end.x;\r
+                       tmp.Y2 = end.y;\r
+                       if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);\r
+                       else stroke.apply(tmp);\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+                       tmp.Visibility = Visibility.Visible;\r
+                       d.linePoolN++;\r
+                       return tmp;\r
+               }\r
+               public void modifyNative(System.Windows.Shapes.Line tmp, Canvas d)\r
+               {\r
+                       tmp.X1 = begin.x;\r
+                       tmp.Y1 = begin.y;\r
+                       tmp.X2 = end.x;\r
+                       tmp.Y2 = end.y;\r
+                       if (stroke.thick == 0.0) tmp.Stroke = fill.getNativeFromStack(d);\r
+                       else stroke.apply(tmp);\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
+       }\r
+       \r
+       #endregion\r
+               \r
+       #region Rectangle\r
+\r
+       partial class Rectangle\r
+       {\r
+               public Rectangle dup()\r
+               {\r
+                       return (Rectangle)MemberwiseClone();\r
+               }\r
+               public Rectangle clone()\r
+               {\r
+                       return (Rectangle)MemberwiseClone();\r
+               }\r
+               public static implicit operator System.Windows.Rect(Rectangle d)\r
+               {\r
+                       return new System.Windows.Rect(d.v1.x, d.v1.y, d.v2.x, d.v2.y);\r
+               }\r
+               public static implicit operator System.Windows.Shapes.Rectangle(Rectangle d)\r
+               {\r
+                       var tmp = new System.Windows.Shapes.Rectangle { Width = d.width, Height = d.height, Fill = d.fill };\r
+                       d.stroke.apply(tmp);\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, d.left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
+                       return tmp;\r
+               }\r
+\r
+               public UIElement toNative() { return this; }\r
+               public void copyToStack(Templates.StackableDrawable d)\r
+               {\r
+                       var tmp = d.rectStack[d.rectStackN];\r
+                       tmp.v1 = v1;\r
+                       tmp.v2 = v2;\r
+                       tmp.fill = fill;\r
+                       d.stack[d.stackN] = tmp;\r
+                       d.rectStackN++;\r
+                       d.stackN++;\r
+               }\r
+               public UIElement poolNative(Canvas d)\r
+               {\r
+                       var tmp = d.rectPool[d.rectPoolN];\r
+                       tmp.Width = width;\r
+                       tmp.Height = height;\r
+                       tmp.Fill = fill.getNativeFromStack(d);\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+                       tmp.Visibility = Visibility.Visible;\r
+                       d.rectPoolN++;\r
+                       return tmp;\r
+               }\r
+               public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)\r
+               {\r
+                       tmp.Width = width;\r
+                       tmp.Height = height;\r
+                       tmp.Fill = fill.getNativeFromStack(d);\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
+       }\r
+       \r
+       #endregion\r
+       \r
+       #region ShaderField\r
+\r
+       partial class ShaderField\r
+       {\r
+               public System.Windows.Media.Effects.Effect shader;\r
+               protected static System.Windows.Media.SolidColorBrush dummyfill = null;\r
+\r
+               protected static void initializeShader()\r
+               {\r
+                       dummyfill = new SolidColorBrush(System.Windows.Media.Colors.Blue);\r
+               }\r
+\r
+               public UIElement toNative() { return null; }\r
+               public void copyToStack(Templates.StackableDrawable d)\r
+               {\r
+                       var tmp = d.shaderStack[d.shaderStackN];\r
+                       tmp.initialize__ = initialize__;\r
+                       tmp.setParameters = setParameters;\r
+                       tmp.v1 = v1;\r
+                       tmp.v2 = v2;\r
+                       tmp.shader = shader;\r
+                       d.stack[d.stackN] = tmp;\r
+                       d.shaderStackN++;\r
+                       d.stackN++;\r
+               }\r
+               public UIElement poolNative(Canvas d)\r
+               {\r
+                       var tmp = d.shaderPool[d.shaderPoolN];\r
+                       tmp.Width = width;\r
+                       tmp.Height = height;\r
+                       if (!initialized) { initialize__(); }\r
+                       setParameters();\r
+                       tmp.Effect = shader;\r
+                       tmp.Fill = dummyfill;\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+                       tmp.Visibility = Visibility.Visible;\r
+                       d.shaderPoolN++;\r
+                       return tmp;\r
+               }\r
+               public void modifyNative(System.Windows.Shapes.Rectangle tmp, Canvas d)\r
+               {\r
+                       tmp.Width = width;\r
+                       tmp.Height = height;\r
+                       if (!initialized) { initialize__(); }\r
+                       setParameters();\r
+                       tmp.Effect = shader;\r
+                       tmp.Fill = dummyfill;\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
+       }\r
+\r
+       #endregion\r
+\r
+       #region Ellipse\r
+\r
+       partial class Ellipse\r
+       {\r
+               public Ellipse dup()\r
+               {\r
+                       return (Ellipse)MemberwiseClone();\r
+               }\r
+               public Ellipse clone()\r
+               {\r
+                       return (Ellipse)MemberwiseClone();\r
+               }\r
+               public static implicit operator System.Windows.Shapes.Ellipse(Ellipse d)\r
+               {\r
+                       var tmp = new System.Windows.Shapes.Ellipse { Width = d.width, Height = d.height, Fill = d.fill };\r
+                       d.stroke.apply(tmp);\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, d.left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, d.top);\r
+                       return tmp;\r
+               }\r
+\r
+               public UIElement toNative() { return this; }\r
+\r
+               public void copyToStack(Templates.StackableDrawable d)\r
+               {\r
+                       var tmp = d.ellipseStack[d.ellipseStackN];\r
+                       tmp.datum = datum;\r
+                       tmp.xdiameter = xdiameter;\r
+                       tmp.ydiameter = ydiameter;\r
+                       tmp.fill = fill;\r
+                       d.stack[d.stackN] = tmp;\r
+                       d.ellipseStackN++;\r
+                       d.stackN++;\r
+               }\r
+               public UIElement poolNative(Canvas d)\r
+               {\r
+                       var tmp = d.ellipsePool[d.ellipsePoolN];\r
+                       tmp.Width = width;\r
+                       tmp.Height = height;\r
+                       tmp.Fill = fill.getNativeFromStack(d);\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+                       tmp.Visibility = Visibility.Visible;\r
+                       d.ellipsePoolN++;\r
+                       return tmp;\r
+               }\r
+               public void modifyNative(System.Windows.Shapes.Ellipse tmp, Canvas d)\r
+               {\r
+                       tmp.Width = width;\r
+                       tmp.Height = height;\r
+                       tmp.Fill = fill.getNativeFromStack(d);\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, top);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
+       }\r
+\r
+       #endregion\r
+\r
+       #region Polygon\r
+\r
+       partial class Polygon\r
+       {\r
+               public Polygon dup()\r
+               {\r
+                       return (Polygon)MemberwiseClone();\r
+               }\r
+               public Polygon clone()\r
+               {\r
+                       return (Polygon)MemberwiseClone();\r
+               }\r
+               public static implicit operator System.Windows.Shapes.Polygon(Polygon d)\r
+               {\r
+                       var tmp = new System.Windows.Shapes.Polygon { Fill = d.fill };\r
+                       d.stroke.apply(tmp);\r
+                       foreach (Point p in d.vertices)\r
+                       {\r
+                               tmp.Points.Add(p);\r
+                       }\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);\r
+                       return tmp;\r
+               }\r
+               public UIElement toNative() { return this; }\r
+\r
+               public void copyToStack(Templates.StackableDrawable d)\r
+               {\r
+                       var tmp = d.polygonStack[d.polygonStackN];\r
+                       tmp.datum = datum;\r
+                       tmp.vertices.Clear();\r
+                       foreach (var v in vertices)\r
+                       {\r
+                               tmp.vertices.Add(v);\r
+                       }\r
+                       tmp.fill = fill;\r
+                       d.stack[d.stackN] = tmp;\r
+                       d.polygonStackN++;\r
+                       d.stackN++;\r
+               }\r
+               public UIElement poolNative(Canvas d)\r
+               {\r
+                       var tmp = d.polygonPool[d.polygonPoolN];\r
+                       tmp.Fill = fill.getNativeFromStack(d);\r
+                       tmp.Points.Clear();\r
+                       foreach (var v in vertices)\r
+                       {\r
+                               tmp.Points.Add(v);\r
+                       }\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+                       d.polygonPoolN++;\r
+                       return tmp;\r
+               }\r
+               public void modifyNative(System.Windows.Shapes.Polygon tmp, Canvas d)\r
+               {\r
+                       tmp.Fill = fill.getNativeFromStack(d);\r
+                       tmp.Points.Clear();\r
+                       foreach (var v in vertices)\r
+                       {\r
+                               tmp.Points.Add(v);\r
+                       }\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
+\r
+       }\r
+               \r
+       #endregion\r
+\r
+       #region Letters\r
+\r
+       partial class Letters\r
+       {\r
+               #region static initializer\r
+               internal static System.Collections.Generic.Dictionary<int, System.Windows.FontWeight> FONT_WEIGHT_BRIDGE;\r
+               internal static System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle> FONT_STYLE_BRIDGE;\r
+               internal static System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment> LETTERS_H_ALIGN_BRIDGE;\r
+               static Letters()\r
+               {\r
+                       FONT_WEIGHT_BRIDGE = new System.Collections.Generic.Dictionary<int, System.Windows.FontWeight>();\r
+                       FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.normal, System.Windows.FontWeights.Normal);\r
+                       FONT_WEIGHT_BRIDGE.Add((int)Font.Weight.bold, System.Windows.FontWeights.Bold);\r
+                       FONT_STYLE_BRIDGE = new System.Collections.Generic.Dictionary<Font.Style, System.Windows.FontStyle>();\r
+                       FONT_STYLE_BRIDGE.Add(Font.Style.normal, System.Windows.FontStyles.Normal);\r
+                       FONT_STYLE_BRIDGE.Add(Font.Style.italic, System.Windows.FontStyles.Italic);\r
+                       FONT_STYLE_BRIDGE.Add(Font.Style.oblique, System.Windows.FontStyles.Italic);\r
+                       LETTERS_H_ALIGN_BRIDGE = new System.Collections.Generic.Dictionary<Letters.HorizontalAlign, TextAlignment>();\r
+                       LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.left, TextAlignment.Left);\r
+                       LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.center, TextAlignment.Center);\r
+                       LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.right, TextAlignment.Right);\r
+                       LETTERS_H_ALIGN_BRIDGE.Add(Letters.HorizontalAlign.not_specified, TextAlignment.Left);\r
+               }\r
+               #endregion\r
+               public Letters dup()\r
+               {\r
+                       return (Letters)MemberwiseClone();\r
+               }\r
+               public Letters clone()\r
+               {\r
+                       return (Letters)MemberwiseClone();\r
+               }\r
+               public static implicit operator System.Windows.Controls.TextBlock(Letters d)\r
+               {\r
+                       //var zapi_shape = new System.Windows.Documents.Glyphs();\r
+                       var tmp = new System.Windows.Controls.TextBlock {\r
+                               Text = d.str, Width = 500, Height = 500,\r
+                               FontSize = d.font.size,\r
+                               //tmp.FontFamily = ,\r
+                               FontStyle = FONT_STYLE_BRIDGE[d.font.style],\r
+                               FontWeight = FONT_WEIGHT_BRIDGE[d.font.weight],\r
+                               TextAlignment = LETTERS_H_ALIGN_BRIDGE[d.align],\r
+                               Foreground = d.fill\r
+                       };\r
+                       double left = 0;\r
+                       switch (d.align)\r
+                       {\r
+                               case Letters.HorizontalAlign.left: break;\r
+                               case Letters.HorizontalAlign.center: left = tmp.Width / 2; break;\r
+                               case Letters.HorizontalAlign.right: left = tmp.Width; break;\r
+                       }\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x - left);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y - d.font.size);\r
+                       return tmp;\r
+               }\r
+               public UIElement toNative() { return this; }\r
+\r
+               public void copyToStack(Templates.StackableDrawable d)\r
+               {\r
+                       var tmp = d.lettersStack[d.lettersStackN];\r
+                       tmp.str = str;\r
+                       tmp.datum = datum;\r
+                       tmp.fill = fill;\r
+                       d.stack[d.stackN] = tmp;\r
+                       d.lettersStackN++;\r
+                       d.stackN++;\r
+               }\r
+               public UIElement poolNative(Canvas d)\r
+               {\r
+                       var tmp = d.lettersPool[d.lettersPoolN];\r
+                       tmp.Text = str;\r
+                       tmp.Width = 500;\r
+                       tmp.Height = 500;\r
+                       tmp.FontSize = font.size;\r
+                       //tmp.FontFamily = ,\r
+                       tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];\r
+                       tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];\r
+                       tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];\r
+                       tmp.Foreground = fill.getNativeFromStack(d);\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+                       d.lettersPoolN++;\r
+                       return tmp;\r
+               }\r
+               public void modifyNative(System.Windows.Controls.TextBlock tmp, Canvas d)\r
+               {\r
+                       tmp.Text = str;\r
+                       tmp.Width = 500;\r
+                       tmp.Height = 500;\r
+                       tmp.FontSize = font.size;\r
+                       //tmp.FontFamily = ,\r
+                       tmp.FontStyle = FONT_STYLE_BRIDGE[font.style];\r
+                       tmp.FontWeight = FONT_WEIGHT_BRIDGE[font.weight];\r
+                       tmp.TextAlignment = LETTERS_H_ALIGN_BRIDGE[align];\r
+                       tmp.Foreground = fill.getNativeFromStack(d);\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
+       }\r
+       \r
+       #endregion\r
+       \r
+       #region Image\r
+\r
+       partial class Image\r
+       {\r
+               internal void initialize__(int wid, int hei)\r
+               {\r
+                       AsyncBool = false;\r
+                       Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action<int,int>(create__), wid, hei);\r
+                       while (!AsyncBool) { System.Threading.Thread.Sleep(10); }\r
+               }\r
+               internal void create__(int wid, int hei)\r
+               {\r
+                       buffer = new WriteableBitmap(wid, hei);\r
+                       AsyncBool = true;\r
+               }\r
+               internal void load__(string uri)\r
+               {\r
+                       AsyncBool = false;\r
+                       var ur = new System.Uri(uri,  System.UriKind.RelativeOrAbsolute);\r
+                       Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action<Uri>(load_), ur);\r
+                       while (!AsyncBool) { System.Threading.Thread.Sleep(10); }\r
+               }\r
+               internal void load_(Uri uri)\r
+               {\r
+                       var bitmap = new BitmapImage();\r
+                       bitmap.CreateOptions = BitmapCreateOptions.None;\r
+                       bitmap.UriSource = uri;\r
+                       //try\r
+                       //{\r
+                               var wbm = new System.Windows.Media.Imaging.WriteableBitmap(bitmap);\r
+                               buffer = wbm;\r
+                       //}\r
+                       //catch (Exception e)\r
+                       //{\r
+                       //      buffer = new WriteableBitmap(64, 64);\r
+                       //      buffer.ForEach(bitmap_drawChecker);\r
+                       //}\r
+                       self_rect.set(buffer.PixelWidth, buffer.PixelHeight);\r
+                       AsyncBool = true;\r
+               }\r
+               static System.Windows.Media.Color[] CHECKER_C;\r
+               static Image()\r
+               {\r
+                       CHECKER_C = new System.Windows.Media.Color[2];\r
+                       CHECKER_C[0] = System.Windows.Media.Color.FromArgb(0, 0, 0, 0);\r
+                       CHECKER_C[1] = System.Windows.Media.Color.FromArgb(128,128,128,128);\r
+               }\r
+               static System.Windows.Media.Color bitmap_drawChecker(int x, int y)\r
+               {\r
+                       return ((x / 4) + (y / 4)) % 2 == 0 ? CHECKER_C[0] : CHECKER_C[1];\r
+               }\r
+               delegate void FieldFunc1(System.Func<int, int, System.Windows.Media.Color> func);\r
+               delegate void FieldFunc2(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func);\r
+               public void field__(System.Func<int, int, System.Windows.Media.Color> func)\r
+               {\r
+                       Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc1(field___), func);\r
+                       //buffer.ForEach(func);\r
+               }\r
+               public void field__(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
+               {\r
+                       Canvas.default_api_canvas.Dispatcher.BeginInvoke(new FieldFunc2(field___), func);\r
+                       //buffer.ForEach(func);\r
+               }\r
+               public void field___(System.Func<int, int, System.Windows.Media.Color> func)\r
+               {\r
+                       buffer.ForEach(func);\r
+               }\r
+               public void field___(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
+               {\r
+                       buffer.ForEach(func);\r
+               }\r
+\r
+               public Image clone()\r
+               {\r
+                       return (Image)MemberwiseClone();\r
+               }\r
+               public static implicit operator System.Windows.Controls.Image(Image d)\r
+               {\r
+                       var tmp = new System.Windows.Controls.Image();\r
+                       tmp.Source = d.buffer;\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, d.datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, d.datum.y);\r
+                       return tmp;\r
+               }\r
+               public UIElement toNative() { return this; }\r
+\r
+               public void copyToStack(Templates.StackableDrawable d)\r
+               {\r
+                       var tmp = d.imageStack[d.imageStackN];\r
+                       tmp.datum = datum;\r
+                       tmp.buffer = buffer;\r
+                       tmp.self_rect = self_rect;\r
+                       d.stack[d.stackN] = tmp;\r
+                       d.imageStackN++;\r
+                       d.stackN++;\r
+               }\r
+               public UIElement poolNative(Canvas d)\r
+               {\r
+                       var tmp = d.imagePool[d.imagePoolN];\r
+                       tmp.Source = buffer;\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+                       d.imagePoolN++;\r
+                       return tmp;\r
+               }\r
+               public void modifyNative(System.Windows.Controls.Image tmp, Canvas d)\r
+               {\r
+                       tmp.Source = buffer;\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
+\r
+       }\r
+\r
+       #endregion\r
+\r
+       #region Group\r
+\r
+       partial class Group\r
+       {\r
+               internal void initialize__()\r
+               {\r
+                       Canvas.default_api_canvas.Dispatcher.BeginInvoke(new Action(create__));\r
+               }\r
+               internal void create__()\r
+               {\r
+                       cnvs = new System.Windows.Controls.Canvas();\r
+                       trans = new System.Windows.Media.TransformGroup();\r
+                       transF = new System.Windows.Media.TransformCollection();\r
+                       rotateF = new System.Windows.Media.RotateTransform();\r
+                       scaleF = new System.Windows.Media.ScaleTransform();\r
+                       translateF = new System.Windows.Media.TranslateTransform();\r
+                       transF.Add(rotateF);\r
+                       transF.Add(scaleF);\r
+                       transF.Add(translateF);\r
+                       trans.Children = transF;\r
+                       cnvs.RenderTransform = trans;\r
+                       AsyncBool = true;\r
+               }\r
+               public Group clone()\r
+               {\r
+                       return (Group)MemberwiseClone();\r
+               }\r
+\r
+               delegate void AppendFunc1(Internal.PrimitiveFigure func);\r
+               void append__(Internal.PrimitiveFigure fig)\r
+               {\r
+                       fig.centering(0, 0);\r
+                       UIElement e = fig.toNative();\r
+                       cnvs.Children.Add(e);\r
+                       System.Windows.Controls.Canvas.SetLeft(e, fig.datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(e, fig.datum.y);\r
+               }\r
+               delegate void SimpleProcedure();\r
+               void getRotation__() { rotation_ = rotateF.Angle; }\r
+               void setRotation__() { rotateF.Angle = rotation_; }\r
+               //void getTranslation__() { rotation_ = rotateF.Angle; }\r
+               void setTranslation__() { translateF.X = datum.x; translateF.Y = datum.y; }\r
+               void setScaling__() { scaleF.ScaleX = scaling_.x; scaleF.ScaleY = scaling_.y; }\r
+\r
+               public static implicit operator System.Windows.Controls.Canvas(Group d)\r
+               {\r
+                       var tmp = d.cnvs;//new System.Windows.Controls.Canvas();\r
+                       System.Windows.Controls.Canvas.SetLeft(d.cnvs, d.datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(d.cnvs, d.datum.y);\r
+                       return tmp;\r
+               }\r
+               public UIElement toNative() { return this; }\r
+\r
+               public void copyToStack(Templates.StackableDrawable d)\r
+               {\r
+                       var tmp = d.groupStack[d.groupStackN];\r
+                       tmp.datum = datum;\r
+                       tmp.cnvs = cnvs;\r
+                       d.stack[d.stackN] = tmp;\r
+                       d.groupStackN++;\r
+                       d.stackN++;\r
+               }\r
+               public UIElement poolNative(Canvas d)\r
+               {\r
+                       //d.groupPool[d.groupPoolN] = cnvs;\r
+                       //var tmp = d.groupPool[d.groupPoolN];\r
+                       var tmp = cnvs;\r
+                       System.Windows.Controls.Canvas.SetLeft(tmp, datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(tmp, datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+                       //d.groupPoolN++;\r
+                       return tmp;\r
+               }\r
+               public void modifyNative(System.Windows.Controls.Canvas tmp, Canvas d)\r
+               {\r
+                       d.groupPool[d.groupPoolN] = cnvs;\r
+                       System.Windows.Controls.Canvas.SetLeft(cnvs, datum.x);\r
+                       System.Windows.Controls.Canvas.SetTop(cnvs, datum.y);\r
+                       tmp.Visibility = Visibility.Visible;\r
+               }\r
+\r
+       }\r
+       #endregion\r
+       \r
+       #endregion\r
+\r
+\r
+}
\ No newline at end of file
diff --git a/dev4/psychlops/core/graphic/font.cs b/dev4/psychlops/core/graphic/font.cs
new file mode 100644 (file)
index 0000000..8ef3a14
--- /dev/null
@@ -0,0 +1,139 @@
+using System;\r
+using System.Net;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Documents;\r
+using System.Windows.Ink;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Animation;\r
+using System.Windows.Shapes;\r
+\r
+namespace Psychlops\r
+{\r
+       public class Font\r
+       {\r
+               public static Font default_font;\r
+\r
+               public enum Style { normal, italic, oblique };\r
+               public enum Weight { normal=400, bold=700 };\r
+               public double size;\r
+               public int weight;\r
+               public Style style;\r
+               public string family;\r
+\r
+               static Font()\r
+               {\r
+                       default_font = new Font();\r
+               }\r
+               public Font()\r
+               {\r
+                       size = 18;\r
+                       weight = (int)Weight.normal;\r
+                       style = Style.normal;\r
+                       //family = new string[1];\r
+               }\r
+               public Font(double size_, int weight_, Style style_, string family_)\r
+               {\r
+                       size = size_;\r
+                       weight = weight_;\r
+                       style = style_;\r
+                       //family = new string[1];\r
+                       family = family_;\r
+               }\r
+               public Font(string family_, double size_, int weight_, Style style_)\r
+               {\r
+                       size = size_;\r
+                       weight = weight_;\r
+                       style = style_;\r
+                       //family = new string[1];\r
+                       family = family_;\r
+               }\r
+               ~Font()\r
+               {\r
+               }\r
+       }\r
+\r
+       public partial class Letters : Shape\r
+       {\r
+               protected string str_;\r
+               protected Font font_;\r
+               protected double width_, height_;\r
+               public Point datum { get; set; }\r
+\r
+               public enum HorizontalAlign { not_specified=-1, left=0, center, right };\r
+               //public const HorizontalAlign NOT_SPECIFIED=HorizontalAlign.not_specified, TEXT_ALIGN_LEFT=HorizontalAlign.left, TEXT_ALIGN_CENTER = HorizontalAlign.center, TEXT_ALIGN_RIGHT=HorizontalAlign.right;\r
+               public HorizontalAlign align;\r
+\r
+               public Letters()\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       str_ = "";\r
+                       font = Font.default_font;\r
+                       align = HorizontalAlign.left;\r
+               }\r
+               public Letters(String init_str)\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       str_ = init_str;\r
+                       font_ = Font.default_font;\r
+                       align = HorizontalAlign.center;\r
+               }\r
+               public Letters(String init_str, Font init_font)\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       str_ = init_str;\r
+                       font_ = init_font;\r
+                       align = HorizontalAlign.right;\r
+               }\r
+               ~Letters()\r
+               {\r
+               }\r
+               public Font font\r
+               {\r
+                       get { return font_; }\r
+                       set { font_ = value; }\r
+               }\r
+               public Font getFont() { return font; }\r
+               public string str\r
+               {\r
+                       get { return str_; }\r
+                       set { str_ = value; }\r
+               }\r
+               public String getString() { return str; }\r
+               public Figure centering(Point p)\r
+               {\r
+                       datum = p;\r
+                       align = HorizontalAlign.center;\r
+                       return this;\r
+               }\r
+               public Figure shift(Point p)\r
+               {\r
+                       datum = datum + p;\r
+                       return this;\r
+               }\r
+               public Letters locate(Point p)\r
+               {\r
+                       datum = p;\r
+                       return this;\r
+               }\r
+               public Letters locate(double x, double y)\r
+               {\r
+                       datum = new Point(x,y);\r
+                       return this;\r
+               }\r
+\r
+               public void draw()\r
+               {\r
+                       Main.drawable.letters(this);\r
+               }\r
+\r
+               public Color fill { get; set; }\r
+               public Stroke stroke { get; set; }\r
+\r
+       }\r
+\r
+}\r
diff --git a/dev4/psychlops/core/graphic/image.cs b/dev4/psychlops/core/graphic/image.cs
new file mode 100644 (file)
index 0000000..64f3c1e
--- /dev/null
@@ -0,0 +1,154 @@
+using System;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Animation;\r
+using System.Windows.Media.Imaging;\r
+using System.Windows.Shapes;\r
+\r
+\r
+namespace Psychlops{\r
+\r
+\r
+       public partial class Image : Internal.PrimitiveFigure\r
+       {\r
+               public WriteableBitmap buffer;\r
+               public Point datum { get; set; }\r
+               public Point getDatum() { return datum; }\r
+               public Point setDatum(Point p) { datum = p; return datum; }\r
+               public Rectangle self_rect;\r
+               protected bool AsyncBool;\r
+\r
+               public Image() \r
+               {\r
+                       self_rect = new Rectangle(1, 1);\r
+                       initialize__(1, 1);\r
+               }\r
+\r
+               public Image(string uri)\r
+               {\r
+                       self_rect = new Rectangle();\r
+                       load__(uri);\r
+               }\r
+\r
+               public Image(int wid, int hei)\r
+               {\r
+                       self_rect = new Rectangle(wid, hei);\r
+                       initialize__(wid, hei);\r
+               }\r
+               public Image(double wid, double hei)\r
+               {\r
+                       self_rect = new Rectangle(Math.round(wid), Math.round(hei));\r
+                       initialize__((int)Math.round(wid), (int)Math.round(hei));\r
+               }\r
+\r
+               public Image set(int wid, int hei)\r
+               {\r
+                       self_rect = new Rectangle(wid, hei);\r
+                       initialize__(wid, hei);\r
+                       return this;\r
+               }\r
+               public Image set(double wid, double hei)\r
+               {\r
+                       self_rect = new Rectangle(Math.round(wid), Math.round(hei));\r
+                       initialize__((int)Math.round(wid), (int)Math.round(hei));\r
+                       return this;\r
+               }\r
+\r
+               public Figure shift(Point p)\r
+               {\r
+                       datum = datum + p;\r
+                       return this;\r
+               }\r
+               public Figure centering(Point p)\r
+               {\r
+                       datum = new Point( p.x - width / 2.0, p.y - height / 2.0);\r
+                       return this;\r
+               }\r
+               public Image move_to(Point p) { datum = p; return this; }\r
+               public Image move_to(double x, double y, double z) { datum = new Point(x, y, z); return this; }\r
+               public Image locate(Point p) { datum = p; return this; }\r
+               public Image locate(double x, double y, double z) { datum = new Point(x, y, z); return this; }\r
+\r
+               public void pix(int x, int y, Color col)\r
+               {\r
+                       buffer.SetPixel(x, y, col);\r
+               }\r
+\r
+               public void release()\r
+               {\r
+               }\r
+\r
+               public void cache(bool on_off = true)\r
+               {\r
+               }\r
+\r
+               public void alpha(int x, int y, double a)\r
+               {\r
+                       buffer.SetPixel(x, y, (byte)(a*255), buffer.GetPixel(x, y));\r
+               }\r
+\r
+               public void clear(Color col)\r
+               {\r
+                       for (int y = 0; y < height; y++)\r
+                       {\r
+                               for (int x = 0; x < width; x++)\r
+                               {\r
+                                       pix(x, y, col);\r
+                               }\r
+                       }\r
+               }\r
+\r
+\r
+               public void field(System.Func<int, int, System.Windows.Media.Color> func)\r
+               {\r
+                       field__(func);\r
+               }\r
+               public void field(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
+               {\r
+                       field__(func);\r
+               }\r
+               public void each(System.Func<int, int, System.Windows.Media.Color> func)\r
+               {\r
+                       field__(func);\r
+               }\r
+               public void each(System.Func<int, int, System.Windows.Media.Color, System.Windows.Media.Color> func)\r
+               {\r
+                       field__(func);\r
+               }\r
+\r
+               public void load(string uri)\r
+               {\r
+                       load__(uri);\r
+               }\r
+\r
+               public void draw()\r
+               {\r
+                       Main.drawable.image(this);\r
+               }\r
+\r
+\r
+               public double width { get { return self_rect.width; } }\r
+               public double height { get { return self_rect.height; } }\r
+               public Point center { get { return new Point(width/2.0, height/2.0); } }\r
+               public double getWidth() { return width; }\r
+               public double getHeight() { return height; }\r
+               public Point getCenter() { return center; }\r
+               public double getHcenter() { return width / 2.0; }\r
+               public double getVcenter() { return height / 2.0; }\r
+\r
+               public double left { get { return datum.x; } }\r
+               public double right { get { return datum.x + width; } }\r
+               public double top { get { return datum.y; } }\r
+               public double bottom { get { return datum.y + height; } }\r
+               public double getLeft() { return left; }\r
+               public double getRight() { return right; }\r
+               public double getTop() { return top; }\r
+               public double getBottom() { return bottom; }\r
+\r
+       }\r
+\r
+\r
+}
\ No newline at end of file
diff --git a/dev4/psychlops/core/graphic/module.cs b/dev4/psychlops/core/graphic/module.cs
new file mode 100644 (file)
index 0000000..8a5be98
--- /dev/null
@@ -0,0 +1,368 @@
+using System;\r
+using System.Windows;\r
+\r
+\r
+namespace Psychlops\r
+{\r
+       public static class StaticFunctions\r
+       {\r
+               public static T[] NewArray<T>(int x)\r
+                       where T : new()\r
+               {\r
+                       T[] t = new T[x];\r
+                       for (int i = 0; i < x; i++)\r
+                       {\r
+                               t[i] = new T();\r
+                       }\r
+                       return t;\r
+               }\r
+               public static T[,] NewArray<T>(int x, int y)\r
+                       where T : new()\r
+               {\r
+                       T[,] t = new T[x,y];\r
+                       for (int i = 0; i < x; i++)\r
+                       {\r
+                               for (int j = 0; j < x; j++)\r
+                               {\r
+                                       t[i,j] = new T();\r
+                               }\r
+                       }\r
+                       return t;\r
+               }\r
+               public static T[,,] NewArray<T>(int x, int y, int z)\r
+                       where T : new()\r
+               {\r
+                       T[,,] t = new T[x, y, z];\r
+                       for (int i = 0; i < x; i++)\r
+                       {\r
+                               for (int j = 0; j < y; j++)\r
+                               {\r
+                                       for (int k = 0; k < z; k++)\r
+                                       {\r
+                                               t[i, j, k] = new T();\r
+                                       }\r
+                               }\r
+                       }\r
+                       return t;\r
+               }\r
+       }\r
+\r
+       public partial struct Point\r
+       {\r
+               public double x, y, z;\r
+               public Point(double dx, double dy, double dz = 0.0)\r
+               {\r
+                       x = dx;\r
+                       y = dy;\r
+                       z = dz;\r
+               }\r
+               public Point set(double dx, double dy, double dz = 0.0)\r
+               {\r
+                       x = dx;\r
+                       y = dy;\r
+                       z = dz;\r
+                       return this;\r
+               }\r
+\r
+               public static Point operator +(Point lhs, Point rhs)\r
+               {\r
+                       return new Point(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z);\r
+               }\r
+               public static Point operator -(Point lhs, Point rhs)\r
+               {\r
+                       return new Point(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z);\r
+               }\r
+               public override string ToString()\r
+               {\r
+                       return "X:"+ x.ToString() + " Y:"+ y.ToString() + " Z:"+ z.ToString();\r
+               }\r
+       }\r
+\r
+\r
+       public partial struct Color\r
+       {\r
+               public double r, g, b, a;\r
+               public Color(double lum)\r
+               {\r
+                       r = g = b = lum;\r
+                       a = 1.0;\r
+               }\r
+               public Color(double red, double green, double blue, double alpha = 1.0)\r
+               {\r
+                       r = red;\r
+                       g = green;\r
+                       b = blue;\r
+                       a = alpha;\r
+               }\r
+               public void set(double lum)\r
+               {\r
+                       r = g = b = lum;\r
+                       a = 1.0;\r
+               }\r
+               public void set(double red, double green, double blue, double alpha = 1.0)\r
+               {\r
+                       r = red;\r
+                       g = green;\r
+                       b = blue;\r
+                       a = alpha;\r
+               }\r
+\r
+               public override string ToString()\r
+               {\r
+                       return "R:" + r.ToString() + " G:" + g.ToString() + " B:" + b.ToString() + " A:" + a.ToString();\r
+               }\r
+\r
+               public static readonly Color\r
+                       black = new Color(0, 0, 0, 1),\r
+                       red = new Color(1, 0, 0, 1),\r
+                       green = new Color(0, 1, 0, 1),\r
+                       blue = new Color(0, 0, 1, 1),\r
+                       yellow = new Color(1, 1, 0, 1),\r
+                       magenta = new Color(1, 0, 1, 1),\r
+                       cyan = new Color(0, 1, 1, 1),\r
+                       gray = new Color(.5, .5, .5, 1),\r
+                       white = new Color(1, 1, 1, 1),\r
+                       null_color = new Color(0, 0, 0, 0),\r
+                       transparent = new Color(0, 0, 0, 0);\r
+\r
+       }\r
+\r
+\r
+       public interface Drawable\r
+       {\r
+               Point getCenter();\r
+               void clear(Color col);\r
+               void pix(int x, int y, Color col);\r
+               void line(Line drawee);\r
+               void rect(Rectangle drawee);\r
+               void ellipse(Ellipse drawee);\r
+               void polygon(Polygon drawee);\r
+               void letters(Letters drawee);\r
+               void image(Image drawee);\r
+               void group(Group drawee);\r
+               void shader(ShaderField drawee);\r
+               void msg(string s, double x, double y, Color c);\r
+       }\r
+\r
+\r
+\r
+       public interface Figure\r
+       {\r
+               Point datum { get; set; }\r
+               Figure shift(Point p);\r
+               Figure centering(Point p);\r
+               void draw();\r
+       }\r
+       public static class FigureExtention\r
+       {\r
+               public static Point getDatum(this Figure target)\r
+               {\r
+                       return target.datum;\r
+               }\r
+               public static Point setDatum(this Figure target, Point p)\r
+               {\r
+                       target.datum = p;\r
+                       return target.datum;\r
+               }\r
+               public static Figure shift(this Figure target, double x, double y, double z = 0.0)\r
+               {\r
+                       return target.shift(new Point(x, y, z));\r
+               }\r
+               public static Figure centering(this Figure target)\r
+               {\r
+                       return target.centering(Main.drawable.getCenter());\r
+               }\r
+               public static Figure centering(this Figure target, double x, double y, double z = 0.0)\r
+               {\r
+                       return target.centering(new Point(x, y, z));\r
+               }\r
+       }\r
+\r
+       namespace Internal\r
+       {\r
+               public interface PrimitiveFigure : Figure\r
+               {\r
+                       UIElement toNative();\r
+                       UIElement poolNative(Canvas c);\r
+               }\r
+       }\r
+\r
+       public partial class Group : Internal.PrimitiveFigure\r
+       {\r
+               System.Collections.Generic.List<Figure> list;\r
+               System.Windows.Controls.Canvas cnvs;\r
+               System.Windows.Media.TransformGroup trans;\r
+               System.Windows.Media.TransformCollection transF;\r
+               System.Windows.Media.RotateTransform rotateF;\r
+               SimpleProcedure setRotation_;\r
+               System.Windows.Media.ScaleTransform scaleF;\r
+               SimpleProcedure setScaling_;\r
+               System.Windows.Media.TranslateTransform translateF;\r
+\r
+               bool AsyncBool;\r
+               double rotation_;\r
+               public double rotation\r
+               {\r
+                       get { return rotation_; }\r
+                       set { rotation_ = value; rotateF.Dispatcher.BeginInvoke(setRotation_); }\r
+               }               \r
+               public Point axis\r
+               {\r
+                       get;\r
+                       set;\r
+               }\r
+               Point scaling_;\r
+               public Point scaling\r
+               {\r
+                       get { return scaling_; }\r
+                       set { scaling_ = value; scaleF.Dispatcher.BeginInvoke(setScaling_); }\r
+               }\r
+\r
+               AppendFunc1 append_;\r
+\r
+               public Group()\r
+               {\r
+                       setRotation_ = new SimpleProcedure(setRotation__);\r
+                       setScaling_ = new SimpleProcedure(setScaling__);\r
+                       append_ = new AppendFunc1(append__);\r
+                       list = new System.Collections.Generic.List<Figure>();\r
+                       AsyncBool = false;\r
+                       initialize__();\r
+                       while (!AsyncBool) { }\r
+               }\r
+\r
+               public Group append(Internal.PrimitiveFigure fig)\r
+               {\r
+                       list.Add(fig);\r
+                       cnvs.Dispatcher.BeginInvoke(append_, fig);\r
+                       return this;\r
+               }\r
+\r
+               public Point datum { get; set; }\r
+               public Figure shift(Point p)\r
+               {\r
+                       datum = datum + p;\r
+                       return this;\r
+               }\r
+               public Figure centering(Point p)\r
+               {\r
+                       datum = p;\r
+                       return this;\r
+               }\r
+               public void draw()\r
+               {\r
+                       Main.drawable.group(this);\r
+               }\r
+       }\r
+\r
+\r
+\r
+       public partial class ShaderField : Internal.PrimitiveFigure\r
+       {\r
+               public Point v1, v2;\r
+               \r
+               public ShaderField()\r
+               {\r
+                       set(0,0);\r
+               }\r
+               public ShaderField(double wid, double hei)\r
+               {\r
+                       initialized = false;\r
+                       set(wid, hei);\r
+               }\r
+               public ShaderField(Rectangle another)\r
+               {\r
+                       v1 = another.v1;\r
+                       v2 = another.v2;\r
+               }\r
+               public ShaderField set(double wid, double hei)\r
+               {\r
+                       v1.set(0, 0, 0);\r
+                       v2.set(wid, hei, 0);\r
+                       return this;\r
+               }\r
+               ShaderField set(Point po1, Point po2)\r
+               {\r
+                       v1 = po1;\r
+                       v2 = po2;\r
+                       return this;\r
+               }\r
+               public ShaderField set(double l, double t, double r, double b)\r
+               {\r
+                       v1.set(l, t, 0);\r
+                       v2.set(r, b, 0);\r
+                       return this;\r
+               }\r
+               public ShaderField set(ShaderField another)\r
+               {\r
+                       v1 = another.v1;\r
+                       v2 = another.v2;\r
+                       return this;\r
+               }\r
+\r
+               public ShaderField resize(double width, double height)\r
+               {\r
+                       Point po = center;\r
+                       set(width, height);\r
+                       centering(po);\r
+                       return this;\r
+               }\r
+\r
+\r
+               public Point datum\r
+               {\r
+                       get { return v1; }\r
+                       set { double w = width, h = height; v1 = value; v2 = v1 + new Point(w,h); }\r
+               }\r
+               public ShaderField move_to(Point p) { datum = p; return this; }\r
+               public ShaderField move_to(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }\r
+               public ShaderField locate(Point p) { datum = p; return this; }\r
+               public ShaderField locate(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }\r
+\r
+               public Figure shift(Point p)\r
+               {\r
+                       v1 += p;\r
+                       v2 += p;\r
+                       return this;\r
+               }\r
+               public Figure centering(Point p)\r
+               {\r
+                       double h = width, v = height;\r
+                       v1.x = p.x - h / 2.0;\r
+                       v1.y = p.y - v / 2.0;\r
+                       v2.x = v1.x + h;\r
+                       v2.y = v1.y + v;\r
+                       return this;\r
+               }\r
+\r
+               public virtual void draw()\r
+               {\r
+                       Main.drawable.shader(this);\r
+               }\r
+\r
+               internal Action setParameters = initialize___;\r
+               internal Action initialize__ = initialize___;\r
+               private static void initialize___() {}\r
+               internal bool initialized = false;\r
+\r
+               public double left { get { return v1.x; } }\r
+               public double top { get { return v1.y; } }\r
+               public double right { get { return v2.x; } }\r
+               public double bottom { get { return v2.y; } }\r
+               public double width { get { return Math.abs(v1.x - v2.x); } }\r
+               public double height { get { return Math.abs(v1.y - v2.y); } }\r
+               public Point center\r
+               {\r
+                       get { return new Point((left + right) / 2, (top + bottom) / 2); }\r
+                       set { centering(value); }\r
+               }\r
+               public double getLeft() { return left; }\r
+               public double getTop() { return top; }\r
+               public double getRight() { return right; }\r
+               public double getBottom() { return bottom; }\r
+               public double getWidth() { return width; }\r
+               public double getHeight() { return height; }\r
+               public Point getCenter() { return center; }\r
+       }\r
+\r
+}
\ No newline at end of file
diff --git a/dev4/psychlops/core/graphic/shape.cs b/dev4/psychlops/core/graphic/shape.cs
new file mode 100644 (file)
index 0000000..9c7ed2b
--- /dev/null
@@ -0,0 +1,515 @@
+using System;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Animation;\r
+using System.Windows.Media.Imaging;\r
+using System.Windows.Shapes;\r
+\r
+\r
+\r
+namespace Psychlops{\r
+\r
+       public interface Shape : Internal.PrimitiveFigure\r
+       {\r
+               Color fill { get; set; }\r
+               Stroke stroke { get; set; }\r
+       }\r
+       public static class ShapeExtention\r
+       {\r
+               public static void draw(this Shape drawee, double c)\r
+               {\r
+                       drawee.draw( new Color(c) );\r
+               }\r
+               public static void draw(this Shape drawee, Color c)\r
+               {\r
+                       Color tmp_col = drawee.fill;\r
+                       Stroke tmp_strk = drawee.stroke;\r
+                       drawee.fill = c;\r
+                       drawee.stroke = new Stroke();\r
+                       drawee.draw();\r
+                       drawee.fill = tmp_col;\r
+                       drawee.stroke = tmp_strk;\r
+               }\r
+               public static void draw(this Shape drawee, Stroke strk)\r
+               {\r
+                       Color tmp_col = drawee.fill;\r
+                       Stroke tmp_strk = drawee.stroke;\r
+                       drawee.fill = new Color(0,0,1,1);\r
+                       drawee.stroke = strk;\r
+                       drawee.draw();\r
+                       drawee.fill = tmp_col;\r
+                       drawee.stroke = tmp_strk;\r
+               }\r
+       }\r
+\r
+       public partial struct Stroke\r
+       {\r
+               public double thick;\r
+               public Color color;\r
+               public Stroke(Color c, double t)\r
+               {\r
+                       color = c;\r
+                       thick = t;\r
+               }\r
+               public void set(Color c, double t)\r
+               {\r
+                       color = c;\r
+                       thick = t;\r
+               }\r
+               public static readonly Stroke null_line = new Stroke(Color.null_color, 0);\r
+               public static readonly Stroke hair_line = new Stroke(Color.white, 1);\r
+       }\r
+\r
+       public partial class Line : Shape\r
+       {\r
+               public Point begin, end;\r
+               public Point datum\r
+               {\r
+                       get { return begin; }\r
+                       set { begin = value; }\r
+               }\r
+\r
+               //public static Line[] this[int x] { get { return Array(x); } }\r
+               //public static Line[,] this[int x, int y] { get { return Array(x, y); } }\r
+               public static Line[] Array(int ind)\r
+               {\r
+                       Line[] l = new Line[ind];\r
+                       for(int i=0; i<ind; i++) { l[i] = new Line(); }\r
+                       return l;\r
+               }\r
+               public static Line[,] Array(int indx, int indy)\r
+               {\r
+                       Line[,] l = new Line[indx, indy];\r
+                       for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Line(); } }\r
+                       return l;\r
+               }\r
+\r
+\r
+               public Line()\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.hair_line;\r
+                       set(0,0,0,0);\r
+               }\r
+               public Line(double x1, double y1, double x2, double y2)\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.hair_line;\r
+                       set(x1, y1, x2, y2);\r
+               }\r
+               public Line(Point v1, Point v2)\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.hair_line;\r
+                       set(v1, v2);\r
+               }\r
+               public Line set(double x1, double y1, double x2, double y2)\r
+               {\r
+                       begin.set(x1, y1);\r
+                       end.set(x2, y2);\r
+                       return this;\r
+               }\r
+               public Line set(Point v1, Point v2)\r
+               {\r
+                       begin = v1;\r
+                       end   = v2;\r
+                       return this;\r
+               }\r
+\r
+               public Figure shift(Point p)\r
+               {\r
+                       begin += p;\r
+                       end   += p;\r
+                       return this;\r
+               }\r
+               public Figure centering(Point p)\r
+               {\r
+                       double h = width, v = height;\r
+                       begin.x = p.x - h / 2.0;\r
+                       begin.y = p.y - v / 2.0;\r
+                       end.x = begin.x + h;\r
+                       end.y = begin.y + v;\r
+                       return this;\r
+               }\r
+\r
+               public virtual void draw()\r
+               {\r
+                       Main.drawable.line(this);\r
+               }\r
+\r
+               public double left { get { return begin.x < end.x ? begin.x : end.x; } }\r
+               public double top { get { return begin.y < end.y ? begin.y : end.y; ; } }\r
+               public double right { get { return begin.x > end.x ? begin.x : end.x; ; } }\r
+               public double bottom { get { return begin.y > end.y ? begin.y : end.y; ; } }\r
+               public double width { get { return Math.abs(begin.x - end.x); } }\r
+               public double height { get { return Math.abs(begin.y - end.y); } }\r
+               public double getLeft() { return left; }\r
+               public double getTop() { return top; }\r
+               public double getRight() { return right; }\r
+               public double getBottom() { return bottom; }\r
+               public double getWidth() { return width; }\r
+               public double getHeight() { return height; }\r
+\r
+               public Color fill { get; set; }\r
+               public Stroke stroke { get; set; }\r
+       }\r
+\r
+       public partial class Rectangle_\r
+       {\r
+               public Point v1, v2;\r
+\r
+               public double left { get { return v1.x; } }\r
+               public double top { get { return v1.y; } }\r
+               public double right { get { return v2.x; } }\r
+               public double bottom { get { return v2.y; } }\r
+               public double width { get { return Math.abs(v1.x - v2.x); } }\r
+               public double height { get { return Math.abs(v1.y - v2.y); } }\r
+               public double getLeft() { return left; }\r
+               public double getTop() { return top; }\r
+               public double getRight() { return right; }\r
+               public double getBottom() { return bottom; }\r
+               public double getWidth() { return width; }\r
+               public double getHeight() { return height; }\r
+\r
+\r
+\r
+               public Color fill { get; set; }\r
+               public Stroke stroke { get; set; }\r
+\r
+               public override string ToString()\r
+               {\r
+                       return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString();\r
+               }\r
+       }\r
+\r
+\r
+       public partial class Rectangle : Shape\r
+       {\r
+               public Point v1, v2;\r
+\r
+               //public static Rectangle[] this[int x] { get { return Array(x); } }\r
+               //public static Rectangle[,] this[int x, int y] { get { return Array(x, y); } }\r
+               public static Rectangle[] Array(int ind)\r
+               {\r
+                       Rectangle[] l = new Rectangle[ind];\r
+                       for (int i = 0; i < ind; i++) { l[i] = new Rectangle(); }\r
+                       return l;\r
+               }\r
+               public static Rectangle[,] Array(int indx, int indy)\r
+               {\r
+                       Rectangle[,] l = new Rectangle[indx, indy];\r
+                       for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Rectangle(); } }\r
+                       return l;\r
+               }\r
+\r
+\r
+               public Rectangle()\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       set(0,0);\r
+               }\r
+               public Rectangle(double wid, double hei)\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       set(wid, hei);\r
+               }\r
+               public Rectangle(Rectangle another)\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       v1 = another.v1;\r
+                       v2 = another.v2;\r
+               }\r
+               public Rectangle set(double wid, double hei)\r
+               {\r
+                       v1.set(0, 0, 0);\r
+                       v2.set(wid, hei, 0);\r
+                       return this;\r
+               }\r
+               Rectangle set(Point po1, Point po2) {\r
+                       v1 = po1;\r
+                       v2 = po2;\r
+                       return this;\r
+               }\r
+               public Rectangle set(double l, double t, double r, double b)\r
+               {\r
+                       v1.set(l, t, 0);\r
+                       v2.set(r, b, 0);\r
+                       return this;\r
+               }\r
+               public Rectangle set(Rectangle another)\r
+               {\r
+                       v1 = another.v1;\r
+                       v2 = another.v2;\r
+                       return this;\r
+               }\r
+\r
+               public Rectangle resize(double width, double height)\r
+               {\r
+                       Point po = center;\r
+                       set(width, height);\r
+                       centering(po);\r
+                       return this;\r
+               }\r
+\r
+\r
+               public Point datum\r
+               {\r
+                       get { return v1; }\r
+                       set { double w = width, h = height; v1 = value; v2 = v1 + new Point(w,h); }\r
+               }\r
+               public Rectangle move_to(Point p) { datum = p; return this; }\r
+               public Rectangle move_to(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }\r
+               public Rectangle locate(Point p) { datum = p; return this; }\r
+               public Rectangle locate(double x, double y, double z = 0.0) { datum = new Point(x, y, z); return this; }\r
+\r
+               public Figure shift(Point p)\r
+               {\r
+                       v1 += p;\r
+                       v2 += p;\r
+                       return this;\r
+               }\r
+               public Figure centering(Point p)\r
+               {\r
+                       double h = width, v = height;\r
+                       v1.x = p.x - h / 2.0;\r
+                       v1.y = p.y - v / 2.0;\r
+                       v2.x = v1.x + h;\r
+                       v2.y = v1.y + v;\r
+                       return this;\r
+               }\r
+\r
+               public virtual void draw()\r
+               {\r
+                       Main.drawable.rect(this);\r
+               }\r
+               public bool include(double x, double y)\r
+               {\r
+                       return (top <= y) && (left <= x) && (bottom >= y) && (right >= x);\r
+               }\r
+               public bool include(Point p)\r
+               {\r
+                       return (top <= p.y) && (left <= p.x) && (bottom >= p.y) && (right >= p.x);\r
+               }\r
+               public bool include(Rectangle rect)\r
+               {\r
+                       return (top <= rect.top) && (left <= rect.left) && (bottom >= rect.bottom) && (right >= rect.right);\r
+               }\r
+\r
+               public Rectangle alignLeft(double lef)\r
+               {\r
+                       return move_to(lef, getTop(), datum.z);\r
+               }\r
+               public Rectangle alignTop(double to_)\r
+               {\r
+                       return move_to(getLeft(), to_, datum.z);\r
+               }\r
+               public Rectangle alignRight(double rig)\r
+               {\r
+                       return move_to(rig - getWidth(), getTop(), datum.z);\r
+               }\r
+               public Rectangle alignBottom(double bot)\r
+               {\r
+                       return move_to(getLeft(), bot - getHeight(), datum.z);\r
+               }\r
+\r
+               public void clipped_by(Rectangle source)\r
+               {\r
+                       double t = top, l = left, b = bottom, r = right;\r
+                       if (top < source.top) { t = source.top; }\r
+                       if (left < source.left) { l = source.left; }\r
+                       if (bottom > source.bottom) { b = source.bottom; }\r
+                       if (right > source.right) { r = source.right; }\r
+                       set(l, t, r, b);\r
+               }\r
+               public void clip(Rectangle target)\r
+               {\r
+                       double t = top, l = left, b = bottom, r = right;\r
+                       if (top < target.top) { t = target.top; }\r
+                       if (left < target.left) { l = target.left; }\r
+                       if (bottom > target.bottom) { b = target.bottom; }\r
+                       if (right > target.right) { r = target.right; }\r
+                       set(l, t, r, b);\r
+               }\r
+\r
+\r
+               public double left   { get { return v1.x; } }\r
+               public double top    { get { return v1.y; } }\r
+               public double right  { get { return v2.x; } }\r
+               public double bottom { get { return v2.y; } }\r
+               public double width { get { return Math.abs(v1.x - v2.x); } }\r
+               public double height { get { return Math.abs(v1.y - v2.y); } }\r
+               public Point center {\r
+                       get { return new Point((left + right) / 2, (top + bottom) / 2); }\r
+                       set { centering(value); }\r
+               }\r
+               public double getLeft() { return left; }\r
+               public double getTop() { return top; }\r
+               public double getRight() { return right; }\r
+               public double getBottom() { return bottom; }\r
+               public double getWidth() { return width; }\r
+               public double getHeight() { return height; }\r
+               public Point getCenter() { return center; }\r
+\r
+\r
+\r
+               public Color fill { get; set; }\r
+               public Stroke stroke { get; set; }\r
+\r
+               public override string ToString()\r
+               {\r
+                       return "Left:" + left.ToString() + " Top:" + top.ToString() + " Right:" + right.ToString() + " Bottom:" + bottom.ToString();\r
+               }\r
+       }\r
+\r
+\r
+       public partial class Ellipse : Shape\r
+       {\r
+               public Point datum { get; set; }\r
+               public double xdiameter, ydiameter;\r
+\r
+               //public static Ellipse[] this[int x] { get { return Array(x); } }\r
+               //public static Ellipse[,] this[int x, int y] { get { return Array(x, y); } }\r
+               public static Ellipse[] Array(int ind)\r
+               {\r
+                       Ellipse[] l = new Ellipse[ind];\r
+                       for (int i = 0; i < ind; i++) { l[i] = new Ellipse(); }\r
+                       return l;\r
+               }\r
+               public static Ellipse[,] Array(int indx, int indy)\r
+               {\r
+                       Ellipse[,] l = new Ellipse[indx, indy];\r
+                       for (int i = 0; i < indx; i++) { for (int j = 0; j < indy; j++) { l[i, j] = new Ellipse(); } }\r
+                       return l;\r
+               }\r
+\r
+               public Ellipse()\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       set(0,0);\r
+               }\r
+               public Ellipse(double wid, double hei)\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       set(wid, hei);\r
+               }\r
+\r
+               public Ellipse set(double wid, double hei)\r
+               {\r
+                       xdiameter = wid;\r
+                       ydiameter = hei;\r
+                       return this;\r
+               }\r
+               public Ellipse resize(double width, double height)\r
+               {\r
+                       Point po = center;\r
+                       set(width, height);\r
+                       centering(po);\r
+                       return this;\r
+               }\r
+               public Figure shift(Point p)\r
+               {\r
+                       datum += p;\r
+                       return this;\r
+               }\r
+               public Figure centering(Point p)\r
+               {\r
+                       datum = p;\r
+                       return this;\r
+               }\r
+\r
+               public virtual void draw()\r
+               {\r
+                       Main.drawable.ellipse(this);\r
+               }\r
+\r
+               public double left { get { return datum.x - xdiameter/2.0; } }\r
+               public double top { get { return datum.y - ydiameter / 2.0; } }\r
+               public double right { get { return datum.x + xdiameter / 2.0; } }\r
+               public double bottom { get { return datum.y + ydiameter / 2.0; } }\r
+               public double width { get { return Math.abs(xdiameter); } }\r
+               public double height { get { return Math.abs(ydiameter); } }\r
+               public Point center\r
+               {\r
+                       get { return new Point((left + right) / 2, (top + bottom) / 2); }\r
+                       set { centering(value); }\r
+               }\r
+               public double getLeft() { return left; }\r
+               public double getTop() { return top; }\r
+               public double getRight() { return right; }\r
+               public double getBottom() { return bottom; }\r
+               public double getWidth() { return width; }\r
+               public double getHeight() { return height; }\r
+               public Point getCenter() { return center; }\r
+\r
+               public Color fill { get; set; }\r
+               public Stroke stroke { get; set; }\r
+       }\r
+\r
+\r
+       public partial class Polygon : Shape\r
+       {\r
+               public Point datum { get; set; }\r
+               public System.Collections.Generic.List<Point> vertices;\r
+\r
+               public Polygon()\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       vertices = new System.Collections.Generic.List<Point>();\r
+               }\r
+               public Polygon(double[] verts)\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       vertices = new System.Collections.Generic.List<Point>();\r
+                       for (int i=0; i < verts.Length; i+=2)\r
+                       {\r
+                               vertices.Add(new Point(verts[i], verts[i+1]));\r
+                       }\r
+\r
+               }\r
+               public Polygon(Point[] verts)\r
+               {\r
+                       fill = Color.white;\r
+                       stroke = Stroke.null_line;\r
+                       vertices = new System.Collections.Generic.List<Point>();\r
+                       foreach (Point p in verts)\r
+                       {\r
+                               vertices.Add(p);\r
+                       }\r
+\r
+               }\r
+               public Polygon append(Point p) { vertices.Add(p); return this; }\r
+               public Polygon append(double x, double y) { return append(new Point(x, y, 0.0)); }\r
+               public Polygon append(double x, double y, double z) { return append(new Point(x, y, z)); }\r
+\r
+\r
+               public Figure shift(Point p)\r
+               {\r
+                       datum = datum + p;\r
+                       return this;\r
+               }\r
+               public Figure centering(Point p)\r
+               {\r
+                       datum = p;\r
+                       return this;\r
+               }\r
+\r
+               public virtual void draw()\r
+               {\r
+                       Main.drawable.polygon(this);\r
+               }\r
+\r
+               public Color fill { get; set; }\r
+               public Stroke stroke { get; set; }\r
+       }\r
+\r
+}
\ No newline at end of file
diff --git a/dev4/psychlops/core/math/interval.cs b/dev4/psychlops/core/math/interval.cs
new file mode 100644 (file)
index 0000000..843338f
--- /dev/null
@@ -0,0 +1,214 @@
+using System;\r
+using Psychlops.Internal;\r
+\r
+\r
+namespace Psychlops\r
+{\r
+\r
+       public struct Interval {\r
+               public enum OPERATOR { CLOSE, OPEN };\r
+               public const OPERATOR CLOSE = OPERATOR.CLOSE, OPEN = OPERATOR.OPEN;\r
+               public struct VAL {\r
+                       public double value;\r
+                       public OPERATOR op;\r
+                       /*public VAL()\r
+                       {\r
+                               val = Double.NaN;\r
+                               op = OPERATOR.CLOSE;\r
+                       }*/\r
+                       public VAL(double v, OPERATOR o)\r
+                       {\r
+                               value = v;\r
+                               op = o;\r
+                       }\r
+                       public bool bounded()\r
+                       {\r
+                               return !Double.IsNaN(value) && (!Double.IsInfinity(value) || op == OPERATOR.OPEN);\r
+                       }\r
+               }\r
+               public VAL begin, end;\r
+\r
+               \r
+               /*public Interval()\r
+               {\r
+                       begin = new VAL { val = Double.PositiveInfinity, op = OPERATOR.CLOSE };\r
+                       end = new VAL { val = Double.NegativeInfinity, op = OPERATOR.CLOSE };\r
+               }*/\r
+               public Interval(double floor_val, double ceil_val)\r
+               {\r
+                       begin.value = floor_val;\r
+                       begin.op =  OPERATOR.CLOSE;\r
+                       end.value = ceil_val;\r
+                       end.op = OPERATOR.CLOSE;\r
+               }\r
+               public Interval(double floor_val, OPERATOR floor_op, double ceil_val, OPERATOR ceil_op)\r
+               {\r
+                       begin.value = floor_val;\r
+                       begin.op = floor_op;\r
+                       end.value = ceil_val;\r
+                       end.op = ceil_op;\r
+               }\r
+\r
+\r
+               public int int_floor()\r
+               {\r
+                       double v = Math.ceil(begin.value);\r
+                       if (begin.op == OPEN && v == begin.value) { return (int)v + 1; }\r
+                       else return (int)v;\r
+               }\r
+               public int int_floor(int minval)\r
+               {\r
+                       if(begin.value<minval) return minval;\r
+                       double v = Math.ceil(begin.value);\r
+                       if (begin.op == OPEN && v == begin.value) { return (int)v + 1; }\r
+                       else return (int)v;\r
+               }\r
+               public int int_ceil()\r
+               {\r
+                       double v = Math.floor(end.value);\r
+                       if (end.op == OPEN && v == end.value) { return (int)v - 1; }\r
+                       else return (int)v;\r
+               }\r
+               public int int_ceil(int maxval)\r
+               {\r
+                       if(end.value>maxval) return maxval;\r
+                       double v = Math.floor(end.value);\r
+                       if (end.op == OPEN && v == end.value) { return (int)v - 1; }\r
+                       else return (int)v;\r
+               }\r
+               \r
+               bool includes(double val)\r
+               {\r
+                       bool result = false;\r
+                       switch(begin.op) {\r
+                               case OPERATOR.CLOSE:\r
+                                       result = begin.value <= val ? true : false;\r
+                                       break;\r
+                               case OPERATOR.OPEN:\r
+                                       result = begin.value < val ? true : false;\r
+                                       break;\r
+                       }\r
+                       switch(end.op) {\r
+                               case OPERATOR.CLOSE:\r
+                                       result = result && (end.value >= val ? true : false);\r
+                                       break;\r
+                               case OPERATOR.OPEN:\r
+                                       result = result && (end.value > val ? true : false);\r
+                                       break;\r
+                       }\r
+                       return result;\r
+               }\r
+\r
+               public bool bounded()\r
+               {\r
+                       return begin.bounded() && end.bounded();\r
+               }\r
+\r
+               System.Collections.Generic.IEnumerable<double> step(double steps)\r
+               {\r
+                       if (steps > 0) throw new Exception("Interval: step must be a positive");\r
+                       //                      return new IntervalIEnumerable(this, steps);\r
+                       Interval it = this;\r
+                       long front_step = (it.begin.op == Interval.OPERATOR.CLOSE ? -1 : 0);\r
+                       long back_step = (long)System.Math.Floor((it.end.value - it.begin.value) / steps);\r
+                       if (it.end.op == Interval.OPERATOR.OPEN && 0 == System.Math.IEEERemainder(it.end.value - it.begin.value, steps))\r
+                       {\r
+                               back_step -= 1;\r
+                       }\r
+                       while (front_step <= back_step)\r
+                               yield return steps * front_step + it.begin.value;\r
+               }\r
+\r
+\r
+               #region accessor generation\r
+\r
+               public static IntervalAcc operator <(double val, Interval rng)\r
+               {\r
+                       return new IntervalAcc { instance = new Interval(val, OPERATOR.OPEN, Double.PositiveInfinity, OPERATOR.CLOSE) };\r
+               }\r
+               public static IntervalAcc operator <=(double val, Interval rng)\r
+               {\r
+                       return new IntervalAcc { instance = new Interval(val, OPERATOR.CLOSE, Double.PositiveInfinity, OPERATOR.CLOSE) };\r
+               }\r
+               public static IntervalAcc operator >(double val, Interval rng)\r
+               {\r
+                       return new IntervalAcc { instance = new Interval(Double.NegativeInfinity, OPERATOR.CLOSE, val, OPERATOR.OPEN) };\r
+               }\r
+               public static IntervalAcc operator >=(double val, Interval rng)\r
+               {\r
+                       return new IntervalAcc { instance = new Interval(Double.NegativeInfinity, OPERATOR.CLOSE, val, OPERATOR.CLOSE) };\r
+               }\r
+               public static IntervalAcc operator <(Interval rng, double val)\r
+               {\r
+                       return new IntervalAcc { instance = new Interval(Double.NegativeInfinity, OPERATOR.CLOSE, val, OPERATOR.OPEN) };\r
+               }\r
+               public static IntervalAcc operator <=(Interval rng, double val)\r
+               {\r
+                       return new IntervalAcc { instance = new Interval(Double.NegativeInfinity, OPERATOR.CLOSE, val, OPERATOR.CLOSE) };\r
+               }\r
+               public static IntervalAcc operator >(Interval rng, double val)\r
+               {\r
+                       return new IntervalAcc { instance = new Interval(val, OPERATOR.OPEN, Double.PositiveInfinity, OPERATOR.CLOSE) };\r
+               }\r
+               public static IntervalAcc operator >=(Interval rng, double val)\r
+               {\r
+                       return new IntervalAcc { instance = new Interval(val, OPERATOR.CLOSE, Double.PositiveInfinity, OPERATOR.CLOSE) };\r
+               }\r
+\r
+               #endregion\r
+\r
+       }\r
+\r
+       namespace Internal\r
+       {\r
+               #region accessor definition\r
+\r
+               public struct IntervalAcc\r
+               {\r
+                       public Interval instance;\r
+\r
+                       public static IntervalAcc operator <(double val, IntervalAcc rng)\r
+                       {\r
+                               return new IntervalAcc { instance = new Interval(val, Interval.OPERATOR.OPEN, rng.instance.end.value, rng.instance.end.op) };\r
+                       }\r
+                       public static IntervalAcc operator <=(double val, IntervalAcc rng)\r
+                       {\r
+                               return new IntervalAcc { instance = new Interval(val, Interval.OPERATOR.CLOSE, rng.instance.end.value, rng.instance.end.op) };\r
+                       }\r
+                       public static IntervalAcc operator >(double val, IntervalAcc rng)\r
+                       {\r
+                               return new IntervalAcc { instance = new Interval(rng.instance.begin.value, rng.instance.begin.op, val, Interval.OPERATOR.OPEN) };\r
+                       }\r
+                       public static IntervalAcc operator >=(double val, IntervalAcc rng)\r
+                       {\r
+                               return new IntervalAcc { instance = new Interval(rng.instance.begin.value, rng.instance.begin.op, val, Interval.OPERATOR.CLOSE) };\r
+                       }\r
+                       public static IntervalAcc operator <(IntervalAcc rng, double val)\r
+                       {\r
+                               return new IntervalAcc { instance = new Interval(rng.instance.begin.value, rng.instance.begin.op, val, Interval.OPERATOR.OPEN) };\r
+                       }\r
+                       public static IntervalAcc operator <=(IntervalAcc rng, double val)\r
+                       {\r
+                               return new IntervalAcc { instance = new Interval(rng.instance.begin.value, rng.instance.begin.op, val, Interval.OPERATOR.CLOSE) };\r
+                       }\r
+                       public static IntervalAcc operator >(IntervalAcc rng, double val)\r
+                       {\r
+                               return new IntervalAcc { instance = new Interval(val, Interval.OPERATOR.OPEN, rng.instance.end.value, rng.instance.end.op) };\r
+                       }\r
+                       public static IntervalAcc operator >=(IntervalAcc rng, double val)\r
+                       {\r
+                               return new IntervalAcc { instance = new Interval(val, Interval.OPERATOR.CLOSE, rng.instance.end.value, rng.instance.end.op) };\r
+                       }\r
+\r
+                       public static implicit operator Interval(IntervalAcc rhs)\r
+                       {\r
+                               return rhs.instance;\r
+                       }\r
+               }\r
+\r
+               #endregion\r
+\r
+       }\r
+\r
+\r
+}
\ No newline at end of file
diff --git a/dev4/psychlops/core/math/matrix.cs b/dev4/psychlops/core/math/matrix.cs
new file mode 100644 (file)
index 0000000..de4a836
--- /dev/null
@@ -0,0 +1,113 @@
+using System;\r
+\r
+namespace Psychlops\r
+{\r
+\r
+\r
+       public abstract class Matrix\r
+       {\r
+               public abstract double this[int row, int col]\r
+               {\r
+                       get;\r
+                       set;\r
+               }\r
+\r
+               /*\r
+               public abstract Internal.MatrixExpression this[Interval row, Interval col]\r
+               {\r
+                       get;\r
+                       set;\r
+               }\r
+\r
+\r
+               /*\r
+               public static Matrix operator +(Matrix m, double d)\r
+               {\r
+                       return new Internal.MatrixExpression();\r
+               }\r
+               */\r
+\r
+               public abstract int rows { get; }\r
+               public abstract int cols { get; }\r
+               public int getRows() { return rows; }\r
+               public int getCols() { return cols; }\r
+\r
+       }\r
+\r
+\r
+       namespace Internal\r
+       {\r
+\r
+               public class MatrixImplementation : Matrix\r
+               {\r
+                       internal double[,] elements;\r
+\r
+                       public MatrixImplementation(int dnrow, int dncol)\r
+                       {\r
+                               elements = new double[dnrow, dncol];\r
+                       }\r
+\r
+                       public override double this[int row, int col]\r
+                       {\r
+                               get\r
+                               {\r
+                                       return elements[row - 1, col - 1];\r
+                               }\r
+                               set\r
+                               {\r
+                                       elements[row - 1, col - 1] = value;\r
+                               }\r
+                       }\r
+                       /*\r
+                       public override MatrixExpression this[Interval row, Interval col]\r
+                       {\r
+                               get\r
+                               {\r
+                                       return new MatrixExpression(this, row.int_floor(), col.int_floor(), row.int_ceil(), col.int_ceil());\r
+                               }\r
+                               set\r
+                               {\r
+                                       for(int r = 0, r<)\r
+                                       elements[row - 1, col - 1] = value;\r
+                               }\r
+                       }\r
+                        * */\r
+\r
+                       public override int rows { get { return elements.GetLength(0); } }\r
+                       public override int cols { get { return elements.GetLength(1); } }\r
+\r
+               }\r
+\r
+               public class MatrixExpression : Matrix\r
+               {\r
+                       MatrixImplementation imp;\r
+                       readonly int brow, bcol;\r
+                       readonly int erow, ecol;\r
+\r
+                       internal MatrixExpression(MatrixImplementation target, int dbrow, int dbcol, int derow, int decol)\r
+                       {\r
+                               brow = dbrow;\r
+                               bcol = dbcol;\r
+                               erow = derow;\r
+                               ecol = decol;\r
+                               imp = target;\r
+                       }\r
+\r
+                       public override double this[int row, int col]\r
+                       {\r
+                               get\r
+                               {\r
+                                       return imp.elements[(row - 1 - brow), (col - 1 - bcol)];\r
+                               }\r
+                               set\r
+                               {\r
+                                       imp.elements[(row - 1 - brow), (col - 1 - bcol)] = value;\r
+                               }\r
+                       }\r
+\r
+                       public override int rows { get { return erow - brow + 1; } }\r
+                       public override int cols { get { return ecol - bcol + 1; } }\r
+               }\r
+       }\r
+\r
+}
\ No newline at end of file
diff --git a/dev4/psychlops/core/math/util.cs b/dev4/psychlops/core/math/util.cs
new file mode 100644 (file)
index 0000000..f1aa817
--- /dev/null
@@ -0,0 +1,263 @@
+using System;\r
+\r
+namespace Psychlops\r
+{\r
+\r
+       public static class Math\r
+       {\r
+               public const double PI = 3.14159265, E = 2.718281828459045, LOG2E = 1.44269504088896340736;\r
+               public static Random random_generator;\r
+               static Math()\r
+               {\r
+                       random_generator = new Random();\r
+               }\r
+\r
+               public static T max<T>(T val1, T val2) where T : IComparable\r
+               {\r
+                       return val1.CompareTo(val2) > 0 ? val1 : val2;\r
+               }\r
+               public static T min<T>(T val1, T val2) where T : IComparable\r
+               {\r
+                       return val1.CompareTo(val2) < 0 ? val1 : val2;\r
+               }\r
+               public static void shuffle<X>(X[] array, int n)\r
+               {\r
+                       int a;\r
+                       X tmp;\r
+                       for(int i = 1; i < n; i++){\r
+                               a = random(i + 1);\r
+                               tmp = array[i];\r
+                               array[i] = array[a];\r
+                               array[a] = tmp;\r
+                       }\r
+               }\r
+\r
+\r
+               public static double mod(double lhs, double rhs)\r
+               {\r
+                       return lhs - System.Math.Floor(lhs/rhs)*rhs;\r
+               }\r
+               public static double abs(double x)\r
+               {\r
+                       return System.Math.Abs(x);\r
+               }\r
+               public static double floor(double x)\r
+               {\r
+                       return System.Math.Floor(x);\r
+               }\r
+               public static double ceil(double x)\r
+               {\r
+                       return System.Math.Ceiling(x);\r
+               }\r
+               public static double sin(double x)\r
+               {\r
+                       return System.Math.Sin(x);\r
+               }\r
+               public static double cos(double x)\r
+               {\r
+                       return System.Math.Cos(x);\r
+               }\r
+               public static double tan(double x)\r
+               {\r
+                       return System.Math.Tan(x);\r
+               }\r
+               public static double asin(double x)\r
+               {\r
+                       return System.Math.Asin(x);\r
+               }\r
+               public static double acos(double x)\r
+               {\r
+                       return System.Math.Acos(x);\r
+               }\r
+               public static double atan(double x)\r
+               {\r
+                       return System.Math.Atan(x);\r
+               }\r
+               public static double atan(double y, double x)\r
+               {\r
+                       return System.Math.Atan2(y, x);\r
+               }\r
+               public static double atan2(double y, double x)\r
+               {\r
+                       return System.Math.Atan2(y, x);\r
+               }\r
+               public static double sqrt(double x)\r
+               {\r
+                       return System.Math.Sqrt(x);\r
+               }\r
+               public static double pow(double x, double y)\r
+               {\r
+                       return System.Math.Pow(x,y);\r
+               }\r
+               public static double exp(double x)\r
+               {\r
+                       return System.Math.Exp(x);\r
+               }\r
+               public static double log(double x)\r
+               {\r
+                       return System.Math.Log(x);\r
+               }\r
+               public static double log2(double val)\r
+               {\r
+                       return log(val) * LOG2E;\r
+               }\r
+               public static double round(double val)\r
+               {\r
+                       return System.Math.Round(val);\r
+               }\r
+\r
+               public static double radius(double x, double y)\r
+               {\r
+                       return System.Math.Sqrt(x * x + y * y);\r
+               }\r
+\r
+               public static double random()\r
+               {\r
+                       return (random_generator.NextDouble());\r
+               }\r
+               public static int random(int x)\r
+               {\r
+                       return (int)((random_generator.NextDouble()) * x);\r
+               }\r
+               public static double random(double x)\r
+               {\r
+                       return (random_generator.NextDouble()) * x;\r
+               }\r
+               public static double random(double x, double y)\r
+               {\r
+                       return (random_generator.NextDouble()) * (y-x) + x;\r
+               }\r
+\r
+\r
+               public static double gaussian(double x, double sigma)\r
+               {\r
+                       return exp(- (x*x) / (2*sigma*sigma));\r
+               }\r
+\r
+               public static double normalDistibution(double x, double mu, double sigma)\r
+               {\r
+                       return exp( -( (x-mu)*(x-mu) / (2*sigma*sigma) ) ) / sqrt(2*PI*sigma*sigma);\r
+               }\r
+\r
+               public static double cumulativeNormalDistibution(double x, double mu, double sigma)\r
+               {\r
+                       return .5 + .5*Internal.GammaFunction.erf( (x-mu)/(sigma*sqrt(2.0) ) );\r
+               }\r
+\r
+       }\r
+\r
+       namespace Internal\r
+       {\r
+               public static class GammaFunction\r
+               {\r
+                       /************ loggamma(x) -- gamma.c より再掲 *************/\r
+\r
+                       static readonly double PI      = 3.14159265358979324;  /* $\pi$ */\r
+                       static readonly double LOG_2PI = 1.83787706640934548;  /* $\log 2\pi$ */\r
+                       static readonly double N       = 8;\r
+\r
+                       static readonly double B0  = 1            ;     /* 以下はBernoulli数 */\r
+                       static readonly double B1  = (-1.0 / 2.0);\r
+                       static readonly double B2  = ( 1.0 / 6.0);\r
+                       static readonly double B4  = (-1.0 / 30.0);\r
+                       static readonly double B6  = ( 1.0 / 42.0);\r
+                       static readonly double B8  = (-1.0 / 30.0);\r
+                       static readonly double B10 = ( 5.0 / 66.0);\r
+                       static readonly double B12 = (-691.0 / 2730.0);\r
+                       static readonly double B14 = ( 7.0 / 6.0);\r
+                       static readonly double B16 = (-3617.0 / 510.0);\r
+\r
+                       public static double loggamma(double x)  /* ガンマ関数の対数 */\r
+                       {\r
+                               double v, w;\r
+\r
+                               v = 1;\r
+                               while (x < N) {  v *= x;  x++;  }\r
+                               w = 1 / (x * x);\r
+                               return ((((((((B16 / (16 * 15))  * w + (B14 / (14 * 13))) * w\r
+                                                       + (B12 / (12 * 11))) * w + (B10 / (10 *  9))) * w\r
+                                                       + (B8  / ( 8 *  7))) * w + (B6  / ( 6 *  5))) * w\r
+                                                       + (B4  / ( 4 *  3))) * w + (B2  / ( 2 *  1))) / x\r
+                                                       + 0.5 * LOG_2PI - Math.log(v) - x + (x - 0.5) * Math.log(x);\r
+                       }\r
+\r
+                       public static double p_gamma(double a, double x, double loggamma_a)  /* 本文参照 */\r
+                       {\r
+                               int k;\r
+                               double result, term, previous;\r
+\r
+                               if (x >= 1 + a) return 1 - q_gamma(a, x, loggamma_a);\r
+                               if (x == 0)     return 0;\r
+                               result = term = Math.exp(a * Math.log(x) - x - loggamma_a) / a;\r
+                               for (k = 1; k < 1000; k++) {\r
+                                       term *= x / (a + k);\r
+                                       previous = result;  result += term;\r
+                                       if (result == previous) return result;\r
+                               }\r
+                               //throw new Exception("p_gamma(): the sequence is not convergent.");\r
+                               return result;\r
+                       }\r
+\r
+                       public static double q_gamma(double a, double x, double loggamma_a)  /* 本文参照 */\r
+                       {\r
+                               int k;\r
+                               double result, w, temp, previous;\r
+                               double la = 1, lb = 1 + x - a;  /* Laguerreの多項式 */\r
+\r
+                               if (x < 1 + a) return 1 - p_gamma(a, x, loggamma_a);\r
+                               w = Math.exp(a * Math.log(x) - x - loggamma_a);\r
+                               result = w / lb;\r
+                               for (k = 2; k < 1000; k++) {\r
+                                       temp = ((k - 1 - a) * (lb - la) + (k + x) * lb) / k;\r
+                                       la = lb;  lb = temp;\r
+                                       w *= (k - 1 - a) / k;\r
+                                       temp = w / (la * lb);\r
+                                       previous = result;  result += temp;\r
+                                       if (result == previous) return result;\r
+                               }\r
+                               //throw new Exception("q_gamma(): the sequence is not convergent.");\r
+                               return result;\r
+                       }\r
+\r
+                       public static double p_chisq(double chisq, int df)  /* カイ2乗分布の下側確率 */\r
+                       {\r
+                               return p_gamma(0.5 * df, 0.5 * chisq, loggamma(0.5 * df));\r
+                       }\r
+\r
+                       public static double q_chisq(double chisq, int df)  /* カイ2乗分布の上側確率 */\r
+                       {\r
+                               return q_gamma(0.5 * df, 0.5 * chisq, loggamma(0.5 * df));\r
+                       }\r
+\r
+                       static readonly double LOG_PI = 1.14472988584940017;  /* $\log_e \pi$ */\r
+\r
+                       public static double erf(double x)  /* Gaussの誤差関数 ${\rm erf}(x)$ */\r
+                       {\r
+                               if (x >= 0) return   p_gamma(0.5, x * x, LOG_PI / 2);\r
+                               else        return - p_gamma(0.5, x * x, LOG_PI / 2);\r
+                       }\r
+\r
+                       public static double erfc(double x)  /* $1 - {\rm erf}(x)$ */\r
+                       {\r
+                               if (x >= 0) return  q_gamma(0.5, x * x, LOG_PI / 2);\r
+                               else        return  1 + p_gamma(0.5, x * x, LOG_PI / 2);\r
+                       }\r
+\r
+                       public static double p_normal(double x)  /* 標準正規分布の下側確率 */\r
+                       {\r
+                               if (x >= 0) return\r
+                                       0.5 * (1 + p_gamma(0.5, 0.5 * x * x, LOG_PI / 2));\r
+                               else return\r
+                                       0.5 * q_gamma(0.5, 0.5 * x * x, LOG_PI / 2);\r
+                       }\r
+\r
+                       public static double q_normal(double x)  /* 標準正規分布の上側確率 */\r
+                       {\r
+                               if (x >= 0) return\r
+                                       0.5 * q_gamma(0.5, 0.5 * x * x, LOG_PI / 2);\r
+                               else return\r
+                                       0.5 * (1 + p_gamma(0.5, 0.5 * x * x, LOG_PI / 2));\r
+                       }\r
+               }\r
+       }\r
+}
\ No newline at end of file
diff --git a/dev4/psychlops/psychlops.cs b/dev4/psychlops/psychlops.cs
new file mode 100644 (file)
index 0000000..5f28270
--- /dev/null
@@ -0,0 +1 @@
+
\ No newline at end of file
index 100e216..e982c4e 100644 (file)
@@ -2,34 +2,34 @@
 using System.Runtime.CompilerServices;\r
 using System.Runtime.InteropServices;\r
 \r
-// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。\r
-// アセンブリに関連付けられている情報を変更するには、\r
-// これらの属性値を変更してください。\r
-[assembly: AssemblyTitle("PsychlopsSilverlight4")]\r
+// General Information about an assembly is controlled through the following \r
+// set of attributes. Change these attribute values to modify the information\r
+// associated with an assembly.\r
+[assembly: AssemblyTitle("PsychlopsSilverlight5")]\r
 [assembly: AssemblyDescription("")]\r
 [assembly: AssemblyConfiguration("")]\r
 [assembly: AssemblyCompany("")]\r
-[assembly: AssemblyProduct("PsychlopsSilverlight4")]\r
-[assembly: AssemblyCopyright("Copyright ©  2010")]\r
+[assembly: AssemblyProduct("PsychlopsSilverlight5")]\r
+[assembly: AssemblyCopyright("Copyright ©  2012")]\r
 [assembly: AssemblyTrademark("")]\r
 [assembly: AssemblyCulture("")]\r
 \r
-// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから\r
-// 見えなくなります。このアセンブリ内で COM から型にアクセスする必要がある場合は、\r
-// その型の ComVisible 属性を true に設定してください。\r
+// Setting ComVisible to false makes the types in this assembly not visible \r
+// to COM components.  If you need to access a type in this assembly from \r
+// COM, set the ComVisible attribute to true on that type.\r
 [assembly: ComVisible(false)]\r
 \r
-// このプロジェクトが COM に公開される場合、次の GUID がタイプ ライブラリの ID になります。\r
-[assembly: Guid("a37cfddf-f475-42fb-804c-66fa131de7fb")]\r
+// The following GUID is for the ID of the typelib if this project is exposed to COM\r
+[assembly: Guid("ce3deb79-1a00-456c-931d-157d2d01bdcb")]\r
 \r
-// アセンブリのバージョン情報は、以下の 4 つの値で構成されています。\r
+// Version information for an assembly consists of the following four values:\r
 //\r
 //      Major Version\r
 //      Minor Version \r
 //      Build Number\r
 //      Revision\r
 //\r
-// すべての値を指定するか、下のように '*' を使ってリビジョンおよびビルド番号を\r
-// 既定値にすることができます。\r
+// You can specify all the values or you can default the Revision and Build Numbers \r
+// by using the '*' as shown below:\r
 [assembly: AssemblyVersion("1.0.0.0")]\r
 [assembly: AssemblyFileVersion("1.0.0.0")]\r
diff --git a/dev5/PsychlopsSilverlight5.csproj b/dev5/PsychlopsSilverlight5.csproj
new file mode 100644 (file)
index 0000000..2352231
--- /dev/null
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
+    <ProductVersion>8.0.50727</ProductVersion>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectGuid>{1A6795E6-DD87-4D31-86F0-59C991EA6A7F}</ProjectGuid>\r
+    <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>\r
+    <OutputType>Library</OutputType>\r
+    <AppDesignerFolder>Properties</AppDesignerFolder>\r
+    <RootNamespace>PsychlopsSilverlight5</RootNamespace>\r
+    <AssemblyName>PsychlopsSilverlight5</AssemblyName>\r
+    <TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>\r
+    <TargetFrameworkVersion>v5.0</TargetFrameworkVersion>\r
+    <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>\r
+    <SilverlightApplication>false</SilverlightApplication>\r
+    <ValidateXaml>true</ValidateXaml>\r
+    <ThrowErrorsInValidation>true</ThrowErrorsInValidation>\r
+  </PropertyGroup>\r
+  <!-- This property group is only here to support building this project using the \r
+       MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs \r
+       to set the TargetFrameworkVersion to v3.5 -->\r
+  <PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">\r
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
+    <DebugSymbols>true</DebugSymbols>\r
+    <DebugType>full</DebugType>\r
+    <Optimize>false</Optimize>\r
+    <OutputPath>Bin\Debug</OutputPath>\r
+    <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>\r
+    <NoStdLib>true</NoStdLib>\r
+    <NoConfig>true</NoConfig>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
+    <DebugType>pdbonly</DebugType>\r
+    <Optimize>true</Optimize>\r
+    <OutputPath>Bin\Release</OutputPath>\r
+    <DefineConstants>TRACE;SILVERLIGHT</DefineConstants>\r
+    <NoStdLib>true</NoStdLib>\r
+    <NoConfig>true</NoConfig>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Reference Include="mscorlib" />\r
+    <Reference Include="System.Windows" />\r
+    <Reference Include="system" />\r
+    <Reference Include="System.Core" />\r
+    <Reference Include="System.Xml" />\r
+    <Reference Include="System.Net" />\r
+    <Reference Include="System.Windows.Browser" />\r
+    <Reference Include="WriteableBitmapEx">\r
+      <HintPath>WriteableBitmapEx\WriteableBitmapEx.dll</HintPath>\r
+    </Reference>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <Compile Include="Properties\AssemblyInfo.cs" />\r
+    <Compile Include="psychlops\core\app\app.cs" />\r
+    <Compile Include="psychlops\core\app\misc.cs" />\r
+    <Compile Include="psychlops\core\devices\clock.cs" />\r
+    <Compile Include="psychlops\core\devices\hid.cs" />\r
+    <Compile Include="psychlops\core\graphic\canvas.cs" />\r
+    <Compile Include="psychlops\core\graphic\font.cs" />\r
+    <Compile Include="psychlops\core\graphic\image.cs" />\r
+    <Compile Include="psychlops\core\graphic\module.cs" />\r
+    <Compile Include="psychlops\core\graphic\shape.cs" />\r
+    <Compile Include="psychlops\core\math\interval.cs" />\r
+    <Compile Include="psychlops\core\math\matrix.cs" />\r
+    <Compile Include="psychlops\core\math\util.cs" />\r
+    <Compile Include="psychlops\extension\compatibility\compatibility.cs" />\r
+    <Compile Include="psychlops\extension\experiments\experiments.cs" />\r
+    <Compile Include="psychlops\extension\math\BigFloat.cs" />\r
+    <Compile Include="psychlops\extension\math\BigInt.cs" />\r
+    <Compile Include="psychlops\extension\math\solver.cs" />\r
+    <Compile Include="psychlops\extension\media\dom.cs" />\r
+    <Compile Include="psychlops\extension\media\svg.cs" />\r
+    <Compile Include="psychlops\extension\standard\CIEColor.cs" />\r
+    <Compile Include="psychlops\extension\standard\figures.cs" />\r
+    <Compile Include="psychlops\extension\standard\shader.cs" />\r
+    <Compile Include="psychlops\extension\standard\widget.cs" />\r
+    <Compile Include="psychlops\psychlops.cs" />\r
+  </ItemGroup>\r
+  <ItemGroup />\r
+  <ItemGroup>\r
+    <Resource Include="Shader\Gabor.ps" />\r
+    <Resource Include="Shader\GaborAlpha.ps" />\r
+    <Resource Include="Shader\Grating.ps" />\r
+    <Resource Include="Shader\Plaid.ps" />\r
+  </ItemGroup>\r
+  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />\r
+  <ProjectExtensions>\r
+    <VisualStudio>\r
+      <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">\r
+        <SilverlightProjectProperties />\r
+      </FlavorProperties>\r
+    </VisualStudio>\r
+  </ProjectExtensions>\r
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
+       Other similar extension points exist, see Microsoft.Common.targets.\r
+  <Target Name="BeforeBuild">\r
+  </Target>\r
+  <Target Name="AfterBuild">\r
+  </Target>\r
+  -->\r
+</Project>
\ No newline at end of file
index a307dd7..4763699 100644 (file)
@@ -6,13 +6,13 @@
     <members>\r
         <member name="T:System.Windows.Media.Imaging.WriteableBitmapExtensions">\r
             <summary>\r
-            Collection of interchange extension methods for the Silverlight WriteableBitmap class.\r
+            Collection of draw extension methods for the Silverlight WriteableBitmap class.\r
             </summary>\r
             <summary>\r
-            Collection of draw extension methods for the Silverlight WriteableBitmap class.\r
+            Collection of draw spline extension methods for the Silverlight WriteableBitmap class.\r
             </summary>\r
             <summary>\r
-            Collection of draw extension methods for the Silverlight WriteableBitmap class.\r
+            Collection of filter / convolution extension methods for the Silverlight WriteableBitmap class.\r
             </summary>\r
             <summary>\r
             Collection of blit (copy) extension methods for the Silverlight WriteableBitmap class.\r
             Collection of draw extension methods for the Silverlight WriteableBitmap class.\r
             </summary>\r
             <summary>\r
-            Collection of draw spline extension methods for the Silverlight WriteableBitmap class.\r
+            Collection of transformation extension methods for the Silverlight WriteableBitmap class.\r
             </summary>\r
             <summary>\r
-            Collection of transformation extension methods for the Silverlight WriteableBitmap class.\r
+            Collection of draw extension methods for the Silverlight WriteableBitmap class.\r
+            </summary>\r
+            <summary>\r
+            Collection of interchange extension methods for the Silverlight WriteableBitmap class.\r
             </summary>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ToByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Clear(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Media.Color)">\r
             <summary>\r
-            Copies the Pixels from the WriteableBitmap into a ARGB byte array starting at a specific Pixels index.\r
+            Fills the whole WriteableBitmap with a color.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="offset">The starting Pixels index.</param>\r
-            <param name="count">The number of Pixels to copy.</param>\r
-            <returns>The color buffer as byte ARGB values.</returns>\r
+            <param name="color">The color used for filling.</param>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ToByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Int32)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Clear(System.Windows.Media.Imaging.WriteableBitmap)">\r
             <summary>\r
-            Copies the Pixels from the WriteableBitmap into a ARGB byte array.\r
+            Fills the whole WriteableBitmap with an empty color (0).\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="count">The number of pixels to copy.</param>\r
-            <returns>The color buffer as byte ARGB values.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ToByteArray(System.Windows.Media.Imaging.WriteableBitmap)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Clone(System.Windows.Media.Imaging.WriteableBitmap)">\r
             <summary>\r
-            Copies all the Pixels from the WriteableBitmap into a ARGB byte array.\r
+            Clones the specified WriteableBitmap.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <returns>The color buffer as byte ARGB values.</returns>\r
+            <returns>A copy of the WriteableBitmap.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Byte[],System.Int32,System.Int32)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ForEach(System.Windows.Media.Imaging.WriteableBitmap,System.Func{System.Int32,System.Int32,System.Windows.Media.Color})">\r
             <summary>\r
-            Copies color information from an ARGB byte array into this WriteableBitmap starting at a specific buffer index.\r
+            Applies the given function to all the pixels of the bitmap in \r
+            order to set their color.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="offset">The starting index in the buffer.</param>\r
-            <param name="count">The number of bytes to copy from the buffer.</param>\r
-            <param name="buffer">The color buffer as byte ARGB values.</param>\r
-            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
+            <param name="func">The function to apply. With parameters x, y and a color as a result</param>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Byte[],System.Int32)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ForEach(System.Windows.Media.Imaging.WriteableBitmap,System.Func{System.Int32,System.Int32,System.Windows.Media.Color,System.Windows.Media.Color})">\r
             <summary>\r
-            Copies color information from an ARGB byte array into this WriteableBitmap.\r
+            Applies the given function to all the pixels of the bitmap in \r
+            order to set their color.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="count">The number of bytes to copy from the buffer.</param>\r
-            <param name="buffer">The color buffer as byte ARGB values.</param>\r
-            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
+            <param name="func">The function to apply. With parameters x, y, source color and a color as a result</param>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Byte[])">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.GetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
             <summary>\r
-            Copies all the color information from an ARGB byte array into this WriteableBitmap.\r
+            Gets the color of the pixel at the x, y coordinate as integer.  \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="buffer">The color buffer as byte ARGB values.</param>\r
-            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
+            <param name="x">The x coordinate of the pixel.</param>\r
+            <param name="y">The y coordinate of the pixel.</param>\r
+            <returns>The color of the pixel at x, y.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.WriteTga(System.Windows.Media.Imaging.WriteableBitmap,System.IO.Stream)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.GetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
             <summary>\r
-            Writes the WriteableBitmap as a TGA image to a stream. \r
-            Used with permission from Nokola: http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx\r
+            Gets the color of the pixel at the x, y coordinate as a Color struct.  \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="destination">The destination stream.</param>\r
+            <param name="x">The x coordinate of the pixel.</param>\r
+            <param name="y">The y coordinate of the pixel.</param>\r
+            <returns>The color of the pixel at x, y as a Color struct.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromResource(System.Windows.Media.Imaging.WriteableBitmap,System.String)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.GetBrightness(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
             <summary>\r
-            Loads an image from the applications resource file and fills this WriteableBitmap with it.\r
+            Gets the brightness / luminance of the pixel at the x, y coordinate as byte.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="relativePath">Only the relative path to the resource file. The assembly name is retrieved automatically.</param>\r
-            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
+            <param name="x">The x coordinate of the pixel.</param>\r
+            <param name="y">The y coordinate of the pixel.</param>\r
+            <returns>The brightness of the pixel at x, y.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Byte,System.Byte,System.Byte)">\r
+            <summary>\r
+            Sets the color of the pixel using a precalculated index (faster). \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="index">The coordinate index.</param>\r
+            <param name="r">The red value of the color.</param>\r
+            <param name="g">The green value of the color.</param>\r
+            <param name="b">The blue value of the color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Byte,System.Byte,System.Byte)">\r
+            <summary>\r
+            Sets the color of the pixel. \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate (row).</param>\r
+            <param name="y">The y coordinate (column).</param>\r
+            <param name="r">The red value of the color.</param>\r
+            <param name="g">The green value of the color.</param>\r
+            <param name="b">The blue value of the color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Byte,System.Byte,System.Byte,System.Byte)">\r
+            <summary>\r
+            Sets the color of the pixel including the alpha value and using a precalculated index (faster). \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="index">The coordinate index.</param>\r
+            <param name="a">The alpha value of the color.</param>\r
+            <param name="r">The red value of the color.</param>\r
+            <param name="g">The green value of the color.</param>\r
+            <param name="b">The blue value of the color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Byte,System.Byte,System.Byte,System.Byte)">\r
+            <summary>\r
+            Sets the color of the pixel including the alpha value. \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate (row).</param>\r
+            <param name="y">The y coordinate (column).</param>\r
+            <param name="a">The alpha value of the color.</param>\r
+            <param name="r">The red value of the color.</param>\r
+            <param name="g">The green value of the color.</param>\r
+            <param name="b">The blue value of the color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Sets the color of the pixel using a precalculated index (faster). \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="index">The coordinate index.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Sets the color of the pixel. \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate (row).</param>\r
+            <param name="y">The y coordinate (column).</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Byte,System.Windows.Media.Color)">\r
+            <summary>\r
+            Sets the color of the pixel using an extra alpha value and a precalculated index (faster). \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="index">The coordinate index.</param>\r
+            <param name="a">The alpha value of the color.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Byte,System.Windows.Media.Color)">\r
+            <summary>\r
+            Sets the color of the pixel using an extra alpha value. \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate (row).</param>\r
+            <param name="y">The y coordinate (column).</param>\r
+            <param name="a">The alpha value of the color.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
+            <summary>\r
+            Sets the color of the pixel using a precalculated index (faster).  \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="index">The coordinate index.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Sets the color of the pixel. \r
+            For best performance this method should not be used in iterative real-time scenarios. Implement the code directly inside a loop.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x">The x coordinate (row).</param>\r
+            <param name="y">The y coordinate (column).</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBezier(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a cubic Beziér spline defined by start, end and two control points.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="cx1">The x-coordinate of the 1st control point.</param>\r
+            <param name="cy1">The y-coordinate of the 1st control point.</param>\r
+            <param name="cx2">The x-coordinate of the 2nd control point.</param>\r
+            <param name="cy2">The y-coordinate of the 2nd control point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBezier(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a cubic Beziér spline defined by start, end and two control points.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="cx1">The x-coordinate of the 1st control point.</param>\r
+            <param name="cy1">The y-coordinate of the 1st control point.</param>\r
+            <param name="cx2">The x-coordinate of the 2nd control point.</param>\r
+            <param name="cy2">The y-coordinate of the 2nd control point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBeziers(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a series of cubic Beziér splines each defined by start, end and two control points. \r
+            The ending point of the previous curve is used as starting point for the next. \r
+            Therfore the inital curve needs four points and the subsequent 3 (2 control and 1 end point).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, cx1, cy1, cx2, cy2, x2, y2, cx3, cx4 ..., xn, yn).</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBeziers(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Int32)">\r
+            <summary>\r
+            Draws a series of cubic Beziér splines each defined by start, end and two control points. \r
+            The ending point of the previous curve is used as starting point for the next. \r
+            Therfore the inital curve needs four points and the subsequent 3 (2 control and 1 end point).\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, cx1, cy1, cx2, cy2, x2, y2, cx3, cx4 ..., xn, yn).</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurveSegment(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Single,System.Int32,System.Int32[],System.Int32,System.Int32)">\r
+            <summary>\r
+            Draws a segment of a Cardinal spline (cubic) defined by four control points.\r
+            </summary>\r
+            <param name="x1">The x-coordinate of the 1st control point.</param>\r
+            <param name="y1">The y-coordinate of the 1st control point.</param>\r
+            <param name="x2">The x-coordinate of the 2nd control point.</param>\r
+            <param name="y2">The y-coordinate of the 2nd control point.</param>\r
+            <param name="x3">The x-coordinate of the 3rd control point.</param>\r
+            <param name="y3">The y-coordinate of the 3rd control point.</param>\r
+            <param name="x4">The x-coordinate of the 4th control point.</param>\r
+            <param name="y4">The y-coordinate of the 4th control point.</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color.</param>\r
+            <param name="pixels">The pixels array.</param>\r
+            <param name="w">The width of the bitmap.</param>\r
+            <param name="h">The height of the bitmap.</param> \r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurve(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurve(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Int32)">\r
+            <summary>\r
+            Draws a Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurveClosed(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Windows.Media.Color)">\r
+            <summary>\r
+            Draws a closed Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurveClosed(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Int32)">\r
+            <summary>\r
+            Draws a closed Cardinal spline (cubic) defined by a point collection. \r
+            The cardinal spline passes through each point in the collection.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
+            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
+            <param name="color">The color for the spline.</param>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.KernelGaussianBlur5x5">\r
+            <summary>\r
+             Gaussian blur kernel with the size 5x5\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.KernelGaussianBlur3x3">\r
+            <summary>\r
+             Gaussian blur kernel with the size 3x3\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.KernelSharpen3x3">\r
+            <summary>\r
+             Sharpen kernel with the size 3x3\r
+            </summary>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Convolute(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[0:,0:])">\r
+            <summary>\r
+            Creates a new filtered WriteableBitmap.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="kernel">The kernel used for convolution.</param>\r
+            <returns>A new WriteableBitmap that is a filtered version of the input.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Convolute(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[0:,0:],System.Int32,System.Int32)">\r
+            <summary>\r
+            Creates a new filtered WriteableBitmap.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="kernel">The kernel used for convolution.</param>\r
+            <param name="kernelFactorSum">The factor used for the kernel summing.</param>\r
+            <param name="kernelOffsetSum">The offset used for the kernel summing.</param>\r
+            <returns>A new WriteableBitmap that is a filtered version of the input.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Invert(System.Windows.Media.Imaging.WriteableBitmap)">\r
+            <summary>\r
+            Creates a new inverted WriteableBitmap and returns it.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <returns>The new inverted WriteableBitmap.</returns>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode)">\r
+            <summary>\r
+            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            </summary>\r
+            <param name="bmp">The destination WriteableBitmap.</param>\r
+            <param name="destRect">The rectangle that defines the destination region.</param>\r
+            <param name="source">The source WriteableBitmap.</param>\r
+            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
+            <param name="BlendMode">The blending mode <see cref="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode"/>.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect)">\r
+            <summary>\r
+            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            </summary>\r
+            <param name="bmp">The destination WriteableBitmap.</param>\r
+            <param name="destRect">The rectangle that defines the destination region.</param>\r
+            <param name="source">The source WriteableBitmap.</param>\r
+            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Point,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Color,System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode)">\r
+            <summary>\r
+            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            </summary>\r
+            <param name="bmp">The destination WriteableBitmap.</param>\r
+            <param name="destPosition">The destination position in the destination bitmap.</param>\r
+            <param name="source">The source WriteableBitmap.</param>\r
+            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
+            <param name="color">If not Colors.White, will tint the source image. A partially transparent color and the image will be drawn partially transparent.</param>\r
+            <param name="BlendMode">The blending mode <see cref="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode"/>.</param>\r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Color,System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode)">\r
+            <summary>\r
+            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            </summary>\r
+            <param name="bmp">The destination WriteableBitmap.</param>\r
+            <param name="destRect">The rectangle that defines the destination region.</param>\r
+            <param name="source">The source WriteableBitmap.</param>\r
+            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
+            <param name="color">If not Colors.White, will tint the source image. A partially transparent color and the image will be drawn partially transparent. If the BlendMode is ColorKeying, this color will be used as color key to mask all pixels with this value out.</param>\r
+            <param name="BlendMode">The blending mode <see cref="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode"/>.</param>\r
         </member>\r
         <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLineBresenham(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
             <summary>\r
             <param name="y2">The y-coordinate of the end point.</param>\r
             <param name="color">The color for the line.</param>\r
         </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLineAa(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+            <summary> \r
+            Draws an anti-aliased line, using an optimized version of Gupta-Sproull algorithm \r
+            From http://nokola.com/blog/post/2010/10/14/Anti-aliased-Lines-And-Optimizing-Code-for-Windows-Phone-7e28093First-Look.aspx\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color for the line.</param>\r
+            </summary> \r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLineAa(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary> \r
+            Draws an anti-aliased line, using an optimized version of Gupta-Sproull algorithm \r
+            From http://nokola.com/blog/post/2010/10/14/Anti-aliased-Lines-And-Optimizing-Code-for-Windows-Phone-7e28093First-Look.aspx\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color for the line.</param>\r
+            </summary> \r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawLineAa(System.Int32[],System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+            <summary> \r
+            Draws an anti-aliased line, using an optimized version of Gupta-Sproull algorithm \r
+            From http://nokola.com/blog/post/2010/10/14/Anti-aliased-Lines-And-Optimizing-Code-for-Windows-Phone-7e28093First-Look.aspx\r
+            <param name="pixels">An array containing the pixels as int RGBA value.</param>\r
+            <param name="pixelWidth">The width of one scanline in the pixels array.</param>\r
+            <param name="pixelHeight">The height of the bitmap.</param>\r
+            <param name="x1">The x-coordinate of the start point.</param>\r
+            <param name="y1">The y-coordinate of the start point.</param>\r
+            <param name="x2">The x-coordinate of the end point.</param>\r
+            <param name="y2">The y-coordinate of the end point.</param>\r
+            <param name="color">The color for the line.</param>\r
+            </summary> \r
+        </member>\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.AlphaBlendNormalOnPremultiplied(System.Int32[],System.Int32,System.Int32,System.UInt32,System.UInt32)">\r
+            <summary> \r
+            Blends a specific source color on top of a destination premultiplied color \r
+            </summary> \r
+            <param name="pixels">Array containing destination color</param> \r
+            <param name="index">Index of destination pixel</param> \r
+            <param name="sa">Source alpha (0..255)</param> \r
+            <param name="srb">Source non-premultiplied red and blue component in the format 0x00rr00bb</param> \r
+            <param name="sg">Source green component (0..255)</param> \r
+        </member>\r
         <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawPolyline(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Windows.Media.Color)">\r
             <summary>\r
             Draws a polyline. Add the first point also at the end of the array if the line should be closed.\r
         <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipse(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
             <summary>\r
             A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
-            x2 has to be greater than x1 and y2 has to be greater than y1.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
-            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
-            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
-            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
-            <param name="color">The color for the line.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipse(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
-            <summary>\r
-            A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
-            x2 has to be greater than x1 and y2 has to be greater than y1.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
-            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
-            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
-            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
-            <param name="color">The color for the line.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipseCentered(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
-            <summary>\r
-            A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf\r
-            Uses a different parameter representation than DrawEllipse().\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="xc">The x-coordinate of the ellipses center.</param>\r
-            <param name="yc">The y-coordinate of the ellipses center.</param>\r
-            <param name="xr">The radius of the ellipse in x-direction.</param>\r
-            <param name="yr">The radius of the ellipse in y-direction.</param>\r
-            <param name="color">The color for the line.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipseCentered(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
-            <summary>\r
-            A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
-            Uses a different parameter representation than DrawEllipse().\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="xc">The x-coordinate of the ellipses center.</param>\r
-            <param name="yc">The y-coordinate of the ellipses center.</param>\r
-            <param name="xr">The radius of the ellipse in x-direction.</param>\r
-            <param name="yr">The radius of the ellipse in y-direction.</param>\r
-            <param name="color">The color for the line.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Clear(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Media.Color)">\r
-            <summary>\r
-            Fills the whole WriteableBitmap with a color.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="color">The color used for filling.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Clear(System.Windows.Media.Imaging.WriteableBitmap)">\r
-            <summary>\r
-            Fills the whole WriteableBitmap with an empty color (0).\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Clone(System.Windows.Media.Imaging.WriteableBitmap)">\r
-            <summary>\r
-            Clones the specified WriteableBitmap.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <returns>A copy of the WriteableBitmap.</returns>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ForEach(System.Windows.Media.Imaging.WriteableBitmap,System.Func{System.Int32,System.Int32,System.Windows.Media.Color})">\r
-            <summary>\r
-            Applies the given function to all the pixels of the bitmap in \r
-            order to set their color.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="func">The function to apply. With parameters x, y and a color as a result</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ForEach(System.Windows.Media.Imaging.WriteableBitmap,System.Func{System.Int32,System.Int32,System.Windows.Media.Color,System.Windows.Media.Color})">\r
-            <summary>\r
-            Applies the given function to all the pixels of the bitmap in \r
-            order to set their color.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="func">The function to apply. With parameters x, y, source color and a color as a result</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.GetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
-            <summary>\r
-            Gets the color of the pixel at the x, y coordinate as integer.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x">The x coordinate of the pixel.</param>\r
-            <param name="y">The y coordinate of the pixel.</param>\r
-            <returns>The color of the pixel at x, y.</returns>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.GetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
-            <summary>\r
-            Gets the color of the pixel at the x, y coordinate as a Color struct.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x">The x coordinate of the pixel.</param>\r
-            <param name="y">The y coordinate of the pixel.</param>\r
-            <returns>The color of the pixel at x, y as a Color struct.</returns>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Byte,System.Byte,System.Byte)">\r
-            <summary>\r
-            Sets the color of the pixel using a precalculated index (faster).\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="index">The coordinate index.</param>\r
-            <param name="r">The red value of the color.</param>\r
-            <param name="g">The green value of the color.</param>\r
-            <param name="b">The blue value of the color.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Byte,System.Byte,System.Byte)">\r
-            <summary>\r
-            Sets the color of the pixel.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x">The x coordinate (row).</param>\r
-            <param name="y">The y coordinate (column).</param>\r
-            <param name="r">The red value of the color.</param>\r
-            <param name="g">The green value of the color.</param>\r
-            <param name="b">The blue value of the color.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Byte,System.Byte,System.Byte,System.Byte)">\r
-            <summary>\r
-            Sets the color of the pixel including the alpha value and using a precalculated index (faster).\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="index">The coordinate index.</param>\r
-            <param name="a">The alpha value of the color.</param>\r
-            <param name="r">The red value of the color.</param>\r
-            <param name="g">The green value of the color.</param>\r
-            <param name="b">The blue value of the color.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Byte,System.Byte,System.Byte,System.Byte)">\r
-            <summary>\r
-            Sets the color of the pixel including the alpha value.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x">The x coordinate (row).</param>\r
-            <param name="y">The y coordinate (column).</param>\r
-            <param name="a">The alpha value of the color.</param>\r
-            <param name="r">The red value of the color.</param>\r
-            <param name="g">The green value of the color.</param>\r
-            <param name="b">The blue value of the color.</param>\r
+            x2 has to be greater than x1 and y2 has to be greater than y1.\r
+            </summary>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
+            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
+            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
+            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
+            <param name="color">The color for the line.</param>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Windows.Media.Color)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipse(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
             <summary>\r
-            Sets the color of the pixel using a precalculated index (faster).\r
+            A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
+            x2 has to be greater than x1 and y2 has to be greater than y1.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="index">The coordinate index.</param>\r
-            <param name="color">The color.</param>\r
+            <param name="x1">The x-coordinate of the bounding rectangle's left side.</param>\r
+            <param name="y1">The y-coordinate of the bounding rectangle's top side.</param>\r
+            <param name="x2">The x-coordinate of the bounding rectangle's right side.</param>\r
+            <param name="y2">The y-coordinate of the bounding rectangle's bottom side.</param>\r
+            <param name="color">The color for the line.</param>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Windows.Media.Color)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipseCentered(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
             <summary>\r
-            Sets the color of the pixel.\r
+            A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf\r
+            Uses a different parameter representation than DrawEllipse().\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x">The x coordinate (row).</param>\r
-            <param name="y">The y coordinate (column).</param>\r
-            <param name="color">The color.</param>\r
+            <param name="xc">The x-coordinate of the ellipses center.</param>\r
+            <param name="yc">The y-coordinate of the ellipses center.</param>\r
+            <param name="xr">The radius of the ellipse in x-direction.</param>\r
+            <param name="yr">The radius of the ellipse in y-direction.</param>\r
+            <param name="color">The color for the line.</param>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Byte,System.Windows.Media.Color)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawEllipseCentered(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
             <summary>\r
-            Sets the color of the pixel using an extra alpha value and a precalculated index (faster).\r
+            A Fast Bresenham Type Algorithm For Drawing Ellipses http://homepage.smc.edu/kennedy_john/belipse.pdf \r
+            Uses a different parameter representation than DrawEllipse().\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="index">The coordinate index.</param>\r
-            <param name="a">The alpha value of the color.</param>\r
-            <param name="color">The color.</param>\r
+            <param name="xc">The x-coordinate of the ellipses center.</param>\r
+            <param name="yc">The y-coordinate of the ellipses center.</param>\r
+            <param name="xr">The radius of the ellipse in x-direction.</param>\r
+            <param name="yr">The radius of the ellipse in y-direction.</param>\r
+            <param name="color">The color for the line.</param>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Byte,System.Windows.Media.Color)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Crop(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32)">\r
             <summary>\r
-            Sets the color of the pixel using an extra alpha value.\r
+            Creates a new cropped WriteableBitmap.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x">The x coordinate (row).</param>\r
-            <param name="y">The y coordinate (column).</param>\r
-            <param name="a">The alpha value of the color.</param>\r
-            <param name="color">The color.</param>\r
+            <param name="x">The x coordinate of the rectangle that defines the crop region.</param>\r
+            <param name="y">The y coordinate of the rectangle that defines the crop region.</param>\r
+            <param name="width">The width of the rectangle that defines the crop region.</param>\r
+            <param name="height">The height of the rectangle that defines the crop region.</param>\r
+            <returns>A new WriteableBitmap that is a cropped version of the input.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixeli(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Crop(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect)">\r
             <summary>\r
-            Sets the color of the pixel using a precalculated index (faster).\r
+            Creates a new cropped WriteableBitmap.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="index">The coordinate index.</param>\r
-            <param name="color">The color.</param>\r
+            <param name="region">The rectangle that defines the crop region.</param>\r
+            <returns>A new WriteableBitmap that is a cropped version of the input.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.SetPixel(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Resize(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation)">\r
             <summary>\r
-            Sets the color of the pixel.\r
+            Creates a new resized WriteableBitmap.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x">The x coordinate (row).</param>\r
-            <param name="y">The y coordinate (column).</param>\r
-            <param name="color">The color.</param>\r
+            <param name="width">The new desired width.</param>\r
+            <param name="height">The new desired height.</param>\r
+            <param name="interpolation">The interpolation method that should be used.</param>\r
+            <returns>A new WriteableBitmap that is a resized version of the input.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Resize(System.Int32[],System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation)">\r
             <summary>\r
-            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            Creates a new resized bitmap.\r
             </summary>\r
-            <param name="bmp">The destination WriteableBitmap.</param>\r
-            <param name="destRect">The rectangle that defines the destination region.</param>\r
-            <param name="source">The source WriteableBitmap.</param>\r
-            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
-            <param name="BlendMode">The blending mode <see cref="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode"/>.</param>\r
+            <param name="pixels">The source pixels.</param>\r
+            <param name="widthSource">The width of the source pixels.</param>\r
+            <param name="heightSource">The height of the source pixels.</param>\r
+            <param name="width">The new desired width.</param>\r
+            <param name="height">The new desired height.</param>\r
+            <param name="interpolation">The interpolation method that should be used.</param>\r
+            <returns>A new bitmap that is a resized version of the input.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Rotate(System.Windows.Media.Imaging.WriteableBitmap,System.Int32)">\r
             <summary>\r
-            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            Rotates the bitmap in 90° steps clockwise and returns a new rotated WriteableBitmap.\r
             </summary>\r
-            <param name="bmp">The destination WriteableBitmap.</param>\r
-            <param name="destRect">The rectangle that defines the destination region.</param>\r
-            <param name="source">The source WriteableBitmap.</param>\r
-            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="angle">The angle in degress the bitmap should be rotated in 90° steps clockwise.</param>\r
+            <returns>A new WriteableBitmap that is a rotated version of the input.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Point,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Color,System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.RotateFree(System.Windows.Media.Imaging.WriteableBitmap,System.Double,System.Boolean)">\r
             <summary>\r
-            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            Rotates the bitmap in any degree returns a new rotated WriteableBitmap.\r
             </summary>\r
-            <param name="bmp">The destination WriteableBitmap.</param>\r
-            <param name="destPosition">The destination position in the destination bitmap.</param>\r
-            <param name="source">The source WriteableBitmap.</param>\r
-            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
-            <param name="color">If not Colors.White, will tint the source image. A partially transparent color and the image will be drawn partially transparent.</param>\r
-            <param name="BlendMode">The blending mode <see cref="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode"/>.</param>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="angle">Arbitrary angle in 360 Degrees (positive = clockwise).</param>\r
+            <param name="crop">if true: keep the size, false: adjust canvas to new size</param>\r
+            <returns>A new WriteableBitmap that is a rotated version of the input.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Blit(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect,System.Windows.Media.Color,System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Flip(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Media.Imaging.WriteableBitmapExtensions.FlipMode)">\r
             <summary>\r
-            Copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this).\r
+            Flips (reflects the image) eiter vertical or horizontal.\r
             </summary>\r
-            <param name="bmp">The destination WriteableBitmap.</param>\r
-            <param name="destRect">The rectangle that defines the destination region.</param>\r
-            <param name="source">The source WriteableBitmap.</param>\r
-            <param name="sourceRect">The rectangle that will be copied from the source to the destination.</param>\r
-            <param name="color">If not Colors.White, will tint the source image. A partially transparent color and the image will be drawn partially transparent.</param>\r
-            <param name="BlendMode">The blending mode <see cref="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode"/>.</param>\r
+            <param name="bmp">The WriteableBitmap.</param>\r
+            <param name="flipMode">The flip mode.</param>\r
+            <returns>A new WriteableBitmap that is a flipped version of the input.</returns>\r
         </member>\r
         <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FillRectangle(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
             <summary>\r
             <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
             <param name="color">The color for the spline.</param>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBezier(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Windows.Media.Color)">\r
-            <summary>\r
-            Draws a cubic Beziér spline defined by start, end and two control points.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x1">The x-coordinate of the start point.</param>\r
-            <param name="y1">The y-coordinate of the start point.</param>\r
-            <param name="cx1">The x-coordinate of the 1st control point.</param>\r
-            <param name="cy1">The y-coordinate of the 1st control point.</param>\r
-            <param name="cx2">The x-coordinate of the 2nd control point.</param>\r
-            <param name="cy2">The y-coordinate of the 2nd control point.</param>\r
-            <param name="x2">The x-coordinate of the end point.</param>\r
-            <param name="y2">The y-coordinate of the end point.</param>\r
-            <param name="color">The color.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBezier(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32)">\r
-            <summary>\r
-            Draws a cubic Beziér spline defined by start, end and two control points.\r
-            </summary>\r
-            <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x1">The x-coordinate of the start point.</param>\r
-            <param name="y1">The y-coordinate of the start point.</param>\r
-            <param name="cx1">The x-coordinate of the 1st control point.</param>\r
-            <param name="cy1">The y-coordinate of the 1st control point.</param>\r
-            <param name="cx2">The x-coordinate of the 2nd control point.</param>\r
-            <param name="cy2">The y-coordinate of the 2nd control point.</param>\r
-            <param name="x2">The x-coordinate of the end point.</param>\r
-            <param name="y2">The y-coordinate of the end point.</param>\r
-            <param name="color">The color.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBeziers(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Windows.Media.Color)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ToByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32)">\r
             <summary>\r
-            Draws a series of cubic Beziér splines each defined by start, end and two control points. \r
-            The ending point of the previous curve is used as starting point for the next. \r
-            Therfore the inital curve needs four points and the subsequent 3 (2 control and 1 end point).\r
+            Copies the Pixels from the WriteableBitmap into a ARGB byte array starting at a specific Pixels index.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, cx1, cy1, cx2, cy2, x2, y2, cx3, cx4 ..., xn, yn).</param>\r
-            <param name="color">The color for the spline.</param>\r
+            <param name="offset">The starting Pixels index.</param>\r
+            <param name="count">The number of Pixels to copy.</param>\r
+            <returns>The color buffer as byte ARGB values.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawBeziers(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Int32)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ToByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Int32)">\r
             <summary>\r
-            Draws a series of cubic Beziér splines each defined by start, end and two control points. \r
-            The ending point of the previous curve is used as starting point for the next. \r
-            Therfore the inital curve needs four points and the subsequent 3 (2 control and 1 end point).\r
+            Copies the Pixels from the WriteableBitmap into a ARGB byte array.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, cx1, cy1, cx2, cy2, x2, y2, cx3, cx4 ..., xn, yn).</param>\r
-            <param name="color">The color for the spline.</param>\r
-        </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurveSegment(System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Int32,System.Single,System.Int32,System.Int32[],System.Int32,System.Int32)">\r
-            <summary>\r
-            Draws a segment of a Cardinal spline (cubic) defined by four control points.\r
-            </summary>\r
-            <param name="x1">The x-coordinate of the 1st control point.</param>\r
-            <param name="y1">The y-coordinate of the 1st control point.</param>\r
-            <param name="x2">The x-coordinate of the 2nd control point.</param>\r
-            <param name="y2">The y-coordinate of the 2nd control point.</param>\r
-            <param name="x3">The x-coordinate of the 3rd control point.</param>\r
-            <param name="y3">The y-coordinate of the 3rd control point.</param>\r
-            <param name="x4">The x-coordinate of the 4th control point.</param>\r
-            <param name="y4">The y-coordinate of the 4th control point.</param>\r
-            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
-            <param name="color">The color.</param>\r
-            <param name="pixels">The pixels array.</param>\r
-            <param name="w">The width of the bitmap.</param>\r
-            <param name="h">The height of the bitmap.</param> \r
+            <param name="count">The number of pixels to copy.</param>\r
+            <returns>The color buffer as byte ARGB values.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurve(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Windows.Media.Color)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.ToByteArray(System.Windows.Media.Imaging.WriteableBitmap)">\r
             <summary>\r
-            Draws a Cardinal spline (cubic) defined by a point collection. \r
-            The cardinal spline passes through each point in the collection.\r
+            Copies all the Pixels from the WriteableBitmap into a ARGB byte array.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
-            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
-            <param name="color">The color for the spline.</param>\r
+            <returns>The color buffer as byte ARGB values.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurve(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Int32)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Byte[],System.Int32,System.Int32)">\r
             <summary>\r
-            Draws a Cardinal spline (cubic) defined by a point collection. \r
-            The cardinal spline passes through each point in the collection.\r
+            Copies color information from an ARGB byte array into this WriteableBitmap starting at a specific buffer index.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
-            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
-            <param name="color">The color for the spline.</param>\r
+            <param name="offset">The starting index in the buffer.</param>\r
+            <param name="count">The number of bytes to copy from the buffer.</param>\r
+            <param name="buffer">The color buffer as byte ARGB values.</param>\r
+            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurveClosed(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Windows.Media.Color)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Byte[],System.Int32)">\r
             <summary>\r
-            Draws a closed Cardinal spline (cubic) defined by a point collection. \r
-            The cardinal spline passes through each point in the collection.\r
+            Copies color information from an ARGB byte array into this WriteableBitmap.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
-            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
-            <param name="color">The color for the spline.</param>\r
+            <param name="count">The number of bytes to copy from the buffer.</param>\r
+            <param name="buffer">The color buffer as byte ARGB values.</param>\r
+            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.DrawCurveClosed(System.Windows.Media.Imaging.WriteableBitmap,System.Int32[],System.Single,System.Int32)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromByteArray(System.Windows.Media.Imaging.WriteableBitmap,System.Byte[])">\r
             <summary>\r
-            Draws a closed Cardinal spline (cubic) defined by a point collection. \r
-            The cardinal spline passes through each point in the collection.\r
+            Copies all the color information from an ARGB byte array into this WriteableBitmap.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="points">The points for the curve in x and y pairs, therefore the array is interpreted as (x1, y1, x2, y2, x3, y3, x4, y4, x1, x2 ..., xn, yn).</param>\r
-            <param name="tension">The tension of the curve defines the shape. Usually between 0 and 1. 0 would be a straight line.</param>\r
-            <param name="color">The color for the spline.</param>\r
+            <param name="buffer">The color buffer as byte ARGB values.</param>\r
+            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Crop(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Int32,System.Int32)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.WriteTga(System.Windows.Media.Imaging.WriteableBitmap,System.IO.Stream)">\r
             <summary>\r
-            Creates a new cropped WriteableBitmap.\r
+            Writes the WriteableBitmap as a TGA image to a stream. \r
+            Used with permission from Nokola: http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="x">The x coordinate of the rectangle that defines the crop region.</param>\r
-            <param name="y">The y coordinate of the rectangle that defines the crop region.</param>\r
-            <param name="width">The width of the rectangle that defines the crop region.</param>\r
-            <param name="height">The height of the rectangle that defines the crop region.</param>\r
-            <returns>A new WriteableBitmap that is a cropped version of the input.</returns>\r
+            <param name="destination">The destination stream.</param>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Crop(System.Windows.Media.Imaging.WriteableBitmap,System.Windows.Rect)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromResource(System.Windows.Media.Imaging.WriteableBitmap,System.String)">\r
             <summary>\r
-            Creates a new cropped WriteableBitmap.\r
+            Loads an image from the applications resource file and fills this WriteableBitmap with it.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="region">The rectangle that defines the crop region.</param>\r
-            <returns>A new WriteableBitmap that is a cropped version of the input.</returns>\r
+            <param name="relativePath">Only the relative path to the resource file. The assembly name is retrieved automatically.</param>\r
+            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
         </member>\r
-        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.Resize(System.Windows.Media.Imaging.WriteableBitmap,System.Int32,System.Int32,System.Windows.Media.Imaging.WriteableBitmapExtensions.Interpolation)">\r
+        <member name="M:System.Windows.Media.Imaging.WriteableBitmapExtensions.FromContent(System.Windows.Media.Imaging.WriteableBitmap,System.String)">\r
             <summary>\r
-            Creates a new resized WriteableBitmap.\r
+            Loads an image from the applications content and fills this WriteableBitmap with it.\r
             </summary>\r
             <param name="bmp">The WriteableBitmap.</param>\r
-            <param name="width">The new desired width.</param>\r
-            <param name="height">The new desired height.</param>\r
-            <param name="interpolation">The interpolation method that should be used.</param>\r
-            <returns>A new WriteableBitmap that is a resized version of the input.</returns>\r
+            <param name="relativePath">Only the relative path to the content file.</param>\r
+            <returns>The WriteableBitmap that was passed as parameter.</returns>\r
         </member>\r
         <member name="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode">\r
             <summary>\r
             Multiplies the source color with the destination color.\r
             </summary>\r
         </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.ColorKeying">\r
+            <summary>\r
+            Ignores the specified Color\r
+            </summary>\r
+        </member>\r
         <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.BlendMode.None">\r
             <summary>\r
             No blending just copies the pixels from the source.\r
             Linear interpolation in 2D using the average of 3 neighboring pixels.\r
             </summary>\r
         </member>\r
+        <member name="T:System.Windows.Media.Imaging.WriteableBitmapExtensions.FlipMode">\r
+            <summary>\r
+            The mode for flipping.\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.FlipMode.Vertical">\r
+            <summary>\r
+            Flips the image vertical (around the center of the y-axis).\r
+            </summary>\r
+        </member>\r
+        <member name="F:System.Windows.Media.Imaging.WriteableBitmapExtensions.FlipMode.Horizontal">\r
+            <summary>\r
+            Flips the image horizontal (around the center of the x-axis).\r
+            </summary>\r
+        </member>\r
     </members>\r
 </doc>\r
index 72956f0..b08d73d 100644 (file)
Binary files a/dev5/WriteableBitmapEx/WriteableBitmapEx.dll and b/dev5/WriteableBitmapEx/WriteableBitmapEx.dll differ
index cc55600..b511413 100644 (file)
Binary files a/dev5/WriteableBitmapEx/WriteableBitmapEx.pdb and b/dev5/WriteableBitmapEx/WriteableBitmapEx.pdb differ
diff --git a/dev5/psychlops/core/devices/clock.cs b/dev5/psychlops/core/devices/clock.cs
new file mode 100644 (file)
index 0000000..f4a3ebf
--- /dev/null
@@ -0,0 +1,64 @@
+using System;\r
+\r
+namespace Psychlops\r
+{\r
+\r
+       public struct Clock\r
+       {\r
+               long ticks;\r
+               // where ticks unit is 100 nano seconds.\r
+\r
+               public void update()\r
+               {\r
+                       ticks = DateTime.Now.Ticks;\r
+               }\r
+               public long at_msec()\r
+               {\r
+                       return ticks/10000;\r
+               }\r
+\r
+               public static Clock operator +(Clock lhs, Clock rhs)\r
+               {\r
+                       return new Clock { ticks = lhs.ticks + rhs.ticks };\r
+               }\r
+               public static Clock operator -(Clock lhs, Clock rhs)\r
+               {\r
+                       return new Clock { ticks = lhs.ticks - rhs.ticks };\r
+               }\r
+\r
+               public static bool operator ==(Clock lhs, Clock rhs)\r
+               {\r
+                       return lhs.ticks == rhs.ticks;\r
+               }\r
+               public static bool operator !=(Clock lhs, Clock rhs)\r
+               {\r
+                       return lhs.ticks != rhs.ticks;\r
+               }\r
+               public override int GetHashCode()\r
+               {\r
+                       return ticks.GetHashCode();\r
+               }\r
+               public static bool operator >(Clock lhs, Clock rhs)\r
+               {\r
+                       return lhs.ticks > rhs.ticks;\r
+               }\r
+               public static bool operator <(Clock lhs, Clock rhs)\r
+               {\r
+                       return lhs.ticks < rhs.ticks;\r
+               }\r
+               public static bool operator >=(Clock lhs, Clock rhs)\r
+               {\r
+                       return lhs.ticks >= rhs.ticks;\r
+               }\r
+               public static bool operator <=(Clock lhs, Clock rhs)\r
+               {\r
+                       return lhs.ticks <= rhs.ticks;\r
+               }\r
+\r
+               public override string ToString()\r
+               {\r
+                       return ticks.ToString();\r
+               }\r
+       }\r
+\r
+}\r
diff --git a/dev5/psychlops/core/devices/hid.cs b/dev5/psychlops/core/devices/hid.cs
new file mode 100644 (file)
index 0000000..ff824ae
--- /dev/null
@@ -0,0 +1,155 @@
+using System;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+\r
+\r
+namespace Psychlops\r
+{\r
+       public class HID\r
+       {\r
+               public struct Button\r
+               {\r
+                       private static object locker;\r
+                       static Button()\r
+                       {\r
+                               locker = new object(); \r
+                       }\r
+                       private bool pushed_, released_, pressed_;\r
+                       public void down()\r
+                       {\r
+                               lock (locker)\r
+                               {\r
+                                       pushed_ = true;\r
+                                       pressed_ = true;\r
+                               }\r
+                       }\r
+                       public void up()\r
+                       {\r
+                               lock (locker)\r
+                               {\r
+                                       released_ = true;\r
+                                       pressed_ = false;\r
+                               }\r
+                       }\r
+                       public bool pushed() { lock (locker) { bool tmp = pushed_; pushed_ = false; return tmp; } }\r
+                       public bool released() { lock (locker) { bool tmp = released_; released_ = false; return tmp; } }\r
+                       public bool pressed() { return pressed_; }\r
+               }\r
+       }\r
+\r
+\r
+       public static class Mouse\r
+       {\r
+               static internal Point position_;\r
+               static internal System.Windows.UIElement _prime;\r
+               static public HID.Button left, right, middle;\r
+               static internal Point wheelDelta_;\r
+\r
+               static public Point position { get { return position_; } }\r
+               static public int x { get { return (int)position_.x; } }\r
+               static public int y { get { return (int)position_.y; } }\r
+               static public Point wheelDelta { get { return wheelDelta_; } }\r
+\r
+               static public void show() { }\r
+               static public void hide() { }\r
+\r
+               static public void Canvas_MousePos(object sender, MouseEventArgs e)\r
+               {\r
+                       System.Windows.Point p = e.GetPosition(_prime);\r
+                       position_.set(p.X, p.Y);\r
+               }\r
+               static public void Canvas_LDown(object sender, MouseEventArgs e)\r
+               {\r
+                       left.down();\r
+                       System.Windows.Point p = e.GetPosition(_prime);\r
+                       position_.set(p.X, p.Y);\r
+               }\r
+               static public void Canvas_LUp(object sender, MouseEventArgs e)\r
+               {\r
+                       left.up();\r
+                       System.Windows.Point p = e.GetPosition(_prime);\r
+                       position_.set(p.X, p.Y);\r
+               }\r
+               static public void Canvas_MouseWheel(object sender, MouseWheelEventArgs e)\r
+               {\r
+                       wheelDelta_.y += e.Delta;\r
+                       System.Windows.Point p = e.GetPosition(_prime);\r
+                       position_.set(p.X, p.Y);\r
+               }\r
+       }\r
+\r
+\r
+       public static class Keyboard\r
+       {\r
+               public class IKey\r
+               {\r
+                       //internal static HID.Button[] states;\r
+                       //int p;\r
+                       internal HID.Button state;\r
+                       public void down() { state.down(); }\r
+                       public void up() { state.up(); }\r
+                       public bool pushed() { return state.pushed(); }\r
+                       public bool released() { return state.released(); }\r
+                       public bool pressed() { return state.pressed(); }\r
+               }\r
+               static public IKey\r
+                       alt, shift, ctrl,\r
+                       esc, spc, rtn,\r
+                       left, right, up, down,\r
+                       tab,\r
+                       comma, period,\r
+                       q, w, e, r, t, y, u, i, o, p,\r
+                       a, s, d, f, g, h, j, k, l,\r
+                       z, x, c, v, b, n, m,\r
+                       one, two, three, four, five, six, seven, eight, nine, zero,\r
+                       pad0, pad1, pad2, pad3, pad4, pad5, pad6, pad7, pad8, pad9;\r
+               static private System.Collections.Generic.Dictionary<System.Windows.Input.Key, IKey> map;\r
+               static public void Canvas_KeyUp(object sender, KeyEventArgs e)\r
+               {\r
+                       if (map.ContainsKey(e.Key)) map[e.Key].up();\r
+               }\r
+               static public void Canvas_KeyDown(object sender, KeyEventArgs e)\r
+               {\r
+                       if (map.ContainsKey(e.Key)) map[e.Key].down();\r
+               }\r
+\r
+\r
+               static Keyboard()\r
+               {\r
+                       /*\r
+                       esc = new Key(0); spc = new Key(1); rtn = new Key(2);\r
+                       left = new Key(3); right = new Key(4); up = new Key(5); down = new Key(6);\r
+                       comma = new Key(7); period = new Key(8);\r
+                       q = new Key(32); w = new Key(33); e = new Key(34); r = new Key(35); t = new Key(36); y = new Key(37); u = new Key(38); i = new Key(39); o = new Key(40); p = new Key(41);\r
+                       a = new Key(42); s = new Key(43); d = new Key(44); f = new Key(45); g = new Key(46); h = new Key(47); j = new Key(48); k = new Key(49); l = new Key(50);\r
+                       z = new Key(51); x = new Key(52); c = new Key(53); v = new Key(54); b = new Key(55); n = new Key(56); m = new Key(57);\r
+                       one = new Key(80); two = new Key(81); three = new Key(82); four = new Key(83); five = new Key(84); six = new Key(85); seven = new Key(86); eight = new Key(87); nine = new Key(88); zero = new Key(96);\r
+                       pad0 = new Key(96); pad1 = new Key(97); pad2 = new Key(98); pad3 = new Key(99); pad4 = new Key(100); pad5 = new Key(101); pad6 = new Key(102); pad7 = new Key(103); pad8 = new Key(104); pad9 = new Key(105);\r
+                       */\r
+                       alt = new IKey(); shift = new IKey(); ctrl = new IKey();\r
+                       esc = new IKey(); spc = new IKey(); rtn = new IKey();\r
+                       left = new IKey(); right = new IKey(); up = new IKey(); down = new IKey();\r
+                       comma = new IKey(); period = new IKey();\r
+                       q = new IKey(); w = new IKey(); e = new IKey(); r = new IKey(); t = new IKey(); y = new IKey(); u = new IKey(); i = new IKey(); o = new IKey(); p = new IKey();\r
+                       a = new IKey(); s = new IKey(); d = new IKey(); f = new IKey(); g = new IKey(); h = new IKey(); j = new IKey(); k = new IKey(); l = new IKey();\r
+                       z = new IKey(); x = new IKey(); c = new IKey(); v = new IKey(); b = new IKey(); n = new IKey(); m = new IKey();\r
+                       one = new IKey(); two = new IKey(); three = new IKey(); four = new IKey(); five = new IKey(); six = new IKey(); seven = new IKey(); eight = new IKey(); nine = new IKey(); zero = new IKey();\r
+                       pad0 = new IKey(); pad1 = new IKey(); pad2 = new IKey(); pad3 = new IKey(); pad4 = new IKey(); pad5 = new IKey(); pad6 = new IKey(); pad7 = new IKey(); pad8 = new IKey(); pad9 = new IKey();\r
+\r
+                       map = new System.Collections.Generic.Dictionary<System.Windows.Input.Key, IKey>();\r
+                       map.Add(Key.Alt, alt); map.Add(Key.Shift, shift); map.Add(Key.Ctrl, ctrl);\r
+                       map.Add(Key.Escape, esc); map.Add(Key.Space, spc); map.Add(Key.Enter, rtn);\r
+                       map.Add(Key.Left, left); map.Add(Key.Right, right); map.Add(Key.Up, up); map.Add(Key.Down, down);\r
+                       map.Add(Key.Tab, tab);\r
+                       map.Add(Key.PageDown, comma); map.Add(Key.PageUp, period);\r
+                       map.Add(Key.Q, q); map.Add(Key.W, w); map.Add(Key.E, e); map.Add(Key.R, r); map.Add(Key.T, t); map.Add(Key.Y, y); map.Add(Key.U, u); map.Add(Key.I, i); map.Add(Key.O, o); map.Add(Key.P, p);\r
+                       map.Add(Key.A, a); map.Add(Key.S, s); map.Add(Key.D, d); map.Add(Key.F, f); map.Add(Key.G, g); map.Add(Key.H, h); map.Add(Key.J, j); map.Add(Key.K, k); map.Add(Key.L, l);\r
+                       map.Add(Key.Z, z); map.Add(Key.X, x); map.Add(Key.C, c); map.Add(Key.V, v); map.Add(Key.B, b); map.Add(Key.N, n); map.Add(Key.M, m);\r
+                       map.Add(Key.D1, one); map.Add(Key.D2, two); map.Add(Key.D3, three); map.Add(Key.D4, four); map.Add(Key.D5, five); map.Add(Key.D6, six); map.Add(Key.D7, seven); map.Add(Key.D8, eight); map.Add(Key.D9, nine); map.Add(Key.D0, zero);\r
+                       map.Add(Key.NumPad0, pad0); map.Add(Key.NumPad1, pad1); map.Add(Key.NumPad2, pad2); map.Add(Key.NumPad3, pad3); map.Add(Key.NumPad4, pad4); map.Add(Key.NumPad5, pad5); map.Add(Key.NumPad6, pad6); map.Add(Key.NumPad7, pad7); map.Add(Key.NumPad8, pad8); map.Add(Key.NumPad9, pad9);\r
+               }\r
+       }\r
+\r
+}
\ No newline at end of file
index e67c6ae..0560bea 100644 (file)
@@ -18,10 +18,13 @@ namespace Psychlops
 \r
        internal static partial class CONST\r
        {\r
-               internal static readonly Int32 MAX_OBJ_N = 1500;\r
-               internal static readonly Int32 MOBJ_N = 1000;\r
-               internal static readonly Int32 COBJ_N = 300;\r
-               internal static readonly Int32 HOBJ_N = 100;\r
+               internal static readonly Int32 MAX_OBJ_N = 4096;//65535;\r
+               internal static readonly Int32 MOBJ_N = 2048;//16384;\r
+               internal static readonly Int32 COBJ_N = 300;//4096;\r
+               internal static readonly Int32 HOBJ_N = 100;//1024;\r
+               internal static readonly Int32 MOBJ_I = 500;\r
+               internal static readonly Int32 COBJ_I = 300;\r
+               internal static readonly Int32 HOBJ_I = 100;\r
        }\r
 \r
        namespace Templates\r
@@ -33,21 +36,21 @@ namespace Psychlops
                        internal Internal.PrimitiveFigure[] stack;\r
                        internal int stackN = 0;\r
                        internal Line[] lineStack;\r
-                       internal int lineStackN = 0;\r
+                       internal int lineStackN = 0, lineStackMAX = 0;\r
                        internal Rectangle[] rectStack;\r
-                       internal int rectStackN = 0;\r
+                       internal int rectStackN = 0, rectStackMAX = 0;\r
                        internal ShaderField[] shaderStack;\r
-                       internal int shaderStackN = 0;\r
+                       internal int shaderStackN = 0, shaderStackMAX = 0;\r
                        internal Ellipse[] ellipseStack;\r
-                       internal int ellipseStackN = 0;\r
+                       internal int ellipseStackN = 0, ellipseStackMAX = 0;\r
                        internal Polygon[] polygonStack;\r
-                       internal int polygonStackN = 0;\r
+                       internal int polygonStackN = 0, polygonStackMAX = 0;\r
                        internal Letters[] lettersStack;\r
-                       internal int lettersStackN = 0;\r
+                       internal int lettersStackN = 0, lettersStackMAX = 0;\r
                        internal Image[] imageStack;\r
-                       internal int imageStackN = 0;\r
+                       internal int imageStackN = 0, imageStackMAX = 0;\r
                        internal Group[] groupStack;\r
-                       internal int groupStackN = 0;\r
+                       internal int groupStackN = 0, groupStackMAX = 0;\r
 \r
                        public StackableDrawable()\r
                        {\r
@@ -60,24 +63,30 @@ namespace Psychlops
                                lettersStack = new Letters[CONST.COBJ_N];\r
                                imageStack = new Image[CONST.HOBJ_N];\r
                                groupStack = new Group[CONST.HOBJ_N];\r
-                               for (int i = 0; i < CONST.MOBJ_N; i++)\r
+                               for (int i = 0; i < CONST.MOBJ_I; i++)\r
                                {\r
-                                       lineStack[i] = new Line(0,0,0,0);\r
                                        rectStack[i] = new Rectangle();\r
-                                       ellipseStack[i] = new Ellipse();\r
                                }\r
-                               for (int i = 0; i < CONST.COBJ_N; i++)\r
+                               rectStackMAX = CONST.MOBJ_I;\r
+                               for (int i = 0; i < CONST.COBJ_I; i++)\r
                                {\r
+                                       lineStack[i] = new Line(0, 0, 0, 0);\r
+                                       ellipseStack[i] = new Ellipse();\r
                                        shaderStack[i] = new ShaderField();\r
                                        polygonStack[i] = new Polygon();\r
-                                       lettersStack[i] = new Letters();\r
                                }\r
-                               for (int i = 0; i < CONST.HOBJ_N; i++)\r
+                               lineStackMAX = CONST.COBJ_I;\r
+                               shaderStackMAX = CONST.COBJ_I;\r
+                               ellipseStackMAX = CONST.COBJ_I;\r
+                               polygonStackMAX = CONST.COBJ_I;\r
+                               for (int i = 0; i < CONST.HOBJ_I; i++)\r
                                {\r
                                        imageStack[i] = new Image();\r
+                                       lettersStack[i] = new Letters();\r
 //                                     groupStack[i] = new Group();\r
                                }\r
-\r
+                               imageStackMAX = CONST.HOBJ_I;\r
+                               lettersStackMAX = CONST.HOBJ_I;\r
 \r
                        }\r
 \r
@@ -116,30 +125,30 @@ namespace Psychlops
                internal System.Windows.Point[] pointPool;\r
                internal int pointPoolN;\r
                internal SolidColorBrush[] brushPool;\r
-               internal int brushPoolN;\r
+               internal int brushPoolN, brushPoolMAX;\r
 \r
                internal System.Windows.Controls.Canvas[] UIElementPool;\r
                internal int UIElementPoolN;\r
                internal int lastVisibleN;\r
 \r
                internal System.Windows.Shapes.Line[] linePool;\r
-               internal int linePoolN;\r
+               internal int linePoolN, linePoolMAX;\r
                internal System.Windows.Shapes.Rectangle[] dummyRectPool;\r
                internal System.Windows.Shapes.Rectangle[] rectPool;\r
-               internal int rectPoolN;\r
+               internal int rectPoolN, rectPoolMAX;\r
                internal System.Windows.Shapes.Rectangle[] shaderPool;\r
-               internal int shaderPoolN;\r
+               internal int shaderPoolN, shaderPoolMAX;\r
                internal System.Windows.Shapes.Ellipse[] ellipsePool;\r
-               internal int ellipsePoolN;\r
+               internal int ellipsePoolN, ellipsePoolMAX;\r
                internal System.Windows.Shapes.Polygon[] polygonPool;\r
-               internal int polygonPoolN;\r
+               internal int polygonPoolN, polygonPoolMAX;\r
                internal System.Windows.Controls.TextBlock[] lettersPool;\r
-               internal int lettersPoolN;\r
+               internal int lettersPoolN, lettersPoolMAX;\r
                internal System.Windows.Controls.Image[] imagePool;\r
-               internal int imagePoolN;\r
+               internal int imagePoolN, imagePoolMAX;\r
                internal Dictionary<int, bool> imagePoolT;\r
                internal System.Windows.Controls.Canvas[] groupPool;\r
-               internal int groupPoolN;\r
+               internal int groupPoolN, groupPoolMAX;\r
 \r
                #region initializer\r
 \r
@@ -211,31 +220,31 @@ namespace Psychlops
 \r
                        pointPool = new System.Windows.Point[CONST.MOBJ_N];\r
                        brushPool = new SolidColorBrush[CONST.MOBJ_N];\r
-                       linePool = new System.Windows.Shapes.Line[CONST.MOBJ_N];\r
                        rectPool = new System.Windows.Shapes.Rectangle[CONST.MOBJ_N];\r
-                       ellipsePool = new System.Windows.Shapes.Ellipse[CONST.MOBJ_N];\r
                        for (int i = 0; i < CONST.MOBJ_N; i++)\r
                        {\r
-                               pointPool[i] = new System.Windows.Point();\r
+                               //pointPool[i] = new System.Windows.Point();\r
                                brushPool[i] = new SolidColorBrush();\r
-                               linePool[i] = new System.Windows.Shapes.Line();\r
                                rectPool[i] = new System.Windows.Shapes.Rectangle();\r
-                               ellipsePool[i] = new System.Windows.Shapes.Ellipse();\r
                        }\r
+                       ellipsePool = new System.Windows.Shapes.Ellipse[CONST.COBJ_N];\r
+                       linePool = new System.Windows.Shapes.Line[CONST.COBJ_N];\r
                        shaderPool = new System.Windows.Shapes.Rectangle[CONST.COBJ_N];\r
                        polygonPool = new System.Windows.Shapes.Polygon[CONST.COBJ_N];\r
-                       lettersPool = new System.Windows.Controls.TextBlock[CONST.COBJ_N];\r
                        for (int i = 0; i < CONST.COBJ_N; i++)\r
                        {\r
+                               linePool[i] = new System.Windows.Shapes.Line();\r
+                               ellipsePool[i] = new System.Windows.Shapes.Ellipse();\r
                                shaderPool[i] = new System.Windows.Shapes.Rectangle();\r
                                polygonPool[i] = new System.Windows.Shapes.Polygon();\r
-                               lettersPool[i] = new System.Windows.Controls.TextBlock();\r
                        }\r
+                       lettersPool = new System.Windows.Controls.TextBlock[CONST.HOBJ_N];\r
                        imagePool = new System.Windows.Controls.Image[CONST.HOBJ_N];\r
                        imagePoolT = new Dictionary<int, bool>(CONST.HOBJ_N);\r
                        groupPool = new System.Windows.Controls.Canvas[CONST.HOBJ_N];\r
                        for (int i = 0; i < CONST.HOBJ_N; i++)\r
                        {\r
+                               lettersPool[i] = new System.Windows.Controls.TextBlock();\r
                                imagePool[i] = new System.Windows.Controls.Image();\r
                                imagePoolT.Add(imagePool[i].GetHashCode(), false);\r
                                groupPool[i] = new System.Windows.Controls.Canvas();\r
@@ -878,6 +887,14 @@ namespace Psychlops
                public UIElement toNative() { return this; }\r
                public void copyToStack(Templates.StackableDrawable d)\r
                {\r
+                       if (d.rectStackMAX <= d.rectStackN)\r
+                       {\r
+                               d.rectStackMAX += CONST.HOBJ_I;\r
+                               for (int i = d.rectStackN; i < d.rectStackMAX; i++)\r
+                               {\r
+                                       d.rectStack[i] = new Rectangle();\r
+                               }\r
+                       }\r
                        var tmp = d.rectStack[d.rectStackN];\r
                        tmp.v1 = v1;\r
                        tmp.v2 = v2;\r
diff --git a/dev5/psychlops/extension/compatibility/compatibility.cs b/dev5/psychlops/extension/compatibility/compatibility.cs
new file mode 100644 (file)
index 0000000..fe1889f
--- /dev/null
@@ -0,0 +1,106 @@
+\r
+\r
+\r
+namespace Psychlops\r
+{\r
+\r
+       /*\r
+       namespace Internal\r
+       {\r
+               public class IndependentAccessor\r
+               {\r
+                       Widgets.Slider sld; \r
+                       public static IndependentAccessor operator <<( IndependentAccessor ind, Widgets.Slider sl )\r
+                       {\r
+                               ind.sld = sl;\r
+                               Psychlops.Main.canvas.independent_list.Add(sl);\r
+                               return ind;\r
+                       }\r
+                       public static IndependentAccessor operator | (IndependentAccessor ind, string str)\r
+                       {\r
+                               label = l;\r
+                               Psychlops.Main.canvas.independent_list.Add(sl);\r
+                               return ind;\r
+                       }\r
+               }\r
+       }\r
+        **/\r
+       public class Procedure\r
+       {\r
+               System.Action acc;\r
+               System.Action<Canvas> acc_c;\r
+               int func = 0;\r
+\r
+               public void setDesign()\r
+               {\r
+               }\r
+               public void setProcedure(System.Action ac)\r
+               {\r
+                       acc = ac;\r
+                       func = 1;\r
+               }\r
+               public void setProcedure(System.Action<Canvas> ac)\r
+               {\r
+                       acc_c = ac;\r
+                       func = 2;\r
+               }\r
+               public void run()\r
+               {\r
+                       if (func == 1)\r
+                       {\r
+                               acc();\r
+                       }\r
+               }\r
+               public void run(Canvas c)\r
+               {\r
+                       if (func == 2)\r
+                       {\r
+                               acc_c(c);\r
+                       }\r
+               }\r
+       }\r
+\r
+       public static class Display\r
+       {\r
+               public enum DisplayName { primary, secondary }\r
+               public static DisplayName primary = DisplayName.primary, secondary = DisplayName.secondary;\r
+\r
+               public static void pix(int x, int y, Color col) { Main.canvas.pix(x, y, col); }\r
+               public static void line(Line drawee) { Main.canvas.line(drawee); }\r
+               public static void rect(Rectangle drawee) { Main.canvas.rect(drawee); }\r
+               public static void ellipse(Ellipse drawee) { Main.canvas.ellipse(drawee); }\r
+               public static void oval(Ellipse drawee) { Main.canvas.ellipse(drawee); }\r
+               public static void polygon(Polygon drawee) { Main.canvas.polygon(drawee); }\r
+               public static void letters(Letters drawee) { Main.canvas.letters(drawee); }\r
+               public static void image(Image drawee) { Main.canvas.image(drawee); }\r
+               public static void group(Group drawee) { Main.canvas.group(drawee); }\r
+\r
+\r
+               public static void msg(string str, double x, double y) { Main.canvas.msg(str, x, y, Color.white); }\r
+               public static void msg(string dstr, double x, double y, Color col) { Main.canvas.msg(dstr, x, y, col); }\r
+               public static void var<Type>(Type val, double x, double y) { Main.canvas.var(val, x, y, Color.white); }\r
+               public static void var<Type>(Type val, double x, double y, Color col) { Main.canvas.var(val, x, y, col); }\r
+\r
+\r
+\r
+               public static void clear() { Main.canvas.clear(Color.black); }\r
+               public static void clear(double lum) { Main.canvas.clear(lum); }\r
+               public static void clear(Color col) { Main.canvas.clear(col); }\r
+               public static void flip(int n = 1) { Main.canvas.flip(n); }\r
+\r
+               public static double width { get { return Main.canvas.width; } }\r
+               public static double height { get { return Main.canvas.height; } }\r
+               public static Point center { get { return Main.canvas.center; } }\r
+               public static double getWidth() { return width; }\r
+               public static double getHeight() { return height; }\r
+               public static Point getCenter() { return center; }\r
+               public static double getHCenter() { return Main.canvas.getHCenter(); }\r
+               public static double getVCenter() { return Main.canvas.getVCenter(); }\r
+               public static double getRefreshRate() { return Main.canvas.getRefreshRate(); }\r
+\r
+               public static void showFPS(bool sw = true) { Main.canvas.showFPS(sw); }\r
+               public static void watchFPS(bool sw = true) { Main.canvas.watchFPS(sw); }\r
+\r
+       }\r
+\r
+}\r
diff --git a/dev5/psychlops/extension/experiments/experiments.cs b/dev5/psychlops/extension/experiments/experiments.cs
new file mode 100644 (file)
index 0000000..9a1aaf0
--- /dev/null
@@ -0,0 +1,17 @@
+namespace Psychlops\r
+{\r
+/*\r
+       public class Independent\r
+       {\r
+               public double value;\r
+\r
+               public Independent()\r
+               {\r
+                       value = 0;\r
+               }\r
+\r
+\r
+               public static implicit operator double(Independent i) { return i.value; }\r
+       }\r
+       */\r
+}\r
diff --git a/dev5/psychlops/extension/math/BigFloat.cs b/dev5/psychlops/extension/math/BigFloat.cs
new file mode 100644 (file)
index 0000000..767f5b4
--- /dev/null
@@ -0,0 +1,3789 @@
+// http://www.fractal-landscapes.co.uk/bigint.html\r
+\r
+using System;\r
+\r
+namespace BigNum\r
+{\r
+    /// <summary>\r
+    /// An arbitrary-precision floating-point class\r
+    /// \r
+    /// Format:\r
+    /// Each number is stored as an exponent (32-bit signed integer), and a mantissa\r
+    /// (n-bit) BigInteger. The sign of the number is stored in the BigInteger\r
+    /// \r
+    /// Applicability and Performance:\r
+    /// This class is designed to be used for small extended precisions. It may not be\r
+    /// safe (and certainly won't be fast) to use it with mixed-precision arguments.\r
+    /// It does support, but will not be efficient for, numbers over around 2048 bits.\r
+    /// \r
+    /// Notes:\r
+    /// All conversions to and from strings are slow.\r
+    /// \r
+    /// Conversions from simple integer types Int32, Int64, UInt32, UInt64 are performed\r
+    /// using the appropriate constructor, and are relatively fast.\r
+    /// \r
+    /// The class is written entirely in managed C# code, with not native or managed\r
+    /// assembler. The use of native assembler would speed up the multiplication operations\r
+    /// many times over, and therefore all higher-order operations too.\r
+    /// </summary>\r
+    public class BigFloat\r
+    {\r
+        /// <summary>\r
+        /// Floats can have 4 special value types:\r
+        /// \r
+        /// NaN: Not a number (cannot be changed using any operations)\r
+        /// Infinity: Positive infinity. Some operations e.g. Arctan() allow this input.\r
+        /// -Infinity: Negative infinity. Some operations allow this input.\r
+        /// Zero\r
+        /// </summary>\r
+        public enum SpecialValueType\r
+        {\r
+            /// <summary>\r
+            /// Not a special value\r
+            /// </summary>\r
+            NONE = 0,\r
+            /// <summary>\r
+            /// Zero\r
+            /// </summary>\r
+            ZERO,\r
+            /// <summary>\r
+            /// Positive infinity\r
+            /// </summary>\r
+            INF_PLUS,\r
+            /// <summary>\r
+            /// Negative infinity\r
+            /// </summary>\r
+            INF_MINUS,\r
+            /// <summary>\r
+            /// Not a number\r
+            /// </summary>\r
+            NAN\r
+        }\r
+\r
+        /// <summary>\r
+        /// This affects the ToString() method. \r
+        /// \r
+        /// With Trim rounding, all insignificant zero digits are drip\r
+        /// </summary>\r
+        public enum RoundingModeType\r
+        {\r
+            /// <summary>\r
+            /// Trim non-significant zeros from ToString output after rounding\r
+            /// </summary>\r
+            TRIM,\r
+            /// <summary>\r
+            /// Keep all non-significant zeroes in ToString output after rounding\r
+            /// </summary>\r
+            EXACT\r
+        }\r
+\r
+        /// <summary>\r
+        /// A wrapper for the signed exponent, avoiding overflow.\r
+        /// </summary>\r
+        protected struct ExponentAdaptor\r
+        {\r
+            /// <summary>\r
+            /// The 32-bit exponent\r
+            /// </summary>\r
+            public Int32 exponent\r
+            {\r
+                get { return expValue; }\r
+                set { expValue = value; }\r
+            }\r
+\r
+            /// <summary>\r
+            /// Implicit cast to Int32\r
+            /// </summary>\r
+            public static implicit operator Int32(ExponentAdaptor adaptor)\r
+            {\r
+                return adaptor.expValue;\r
+            }\r
+\r
+            /// <summary>\r
+            /// Implicit cast from Int32 to ExponentAdaptor\r
+            /// </summary>\r
+            /// <param name="value"></param>\r
+            /// <returns></returns>\r
+            public static implicit operator ExponentAdaptor(Int32 value)\r
+            {\r
+                ExponentAdaptor adaptor = new ExponentAdaptor();\r
+                adaptor.expValue = value;\r
+                return adaptor;\r
+            }\r
+\r
+            /// <summary>\r
+            /// Overloaded increment operator\r
+            /// </summary>\r
+            public static ExponentAdaptor operator ++(ExponentAdaptor adaptor)\r
+            {\r
+                adaptor = adaptor + 1;\r
+                return adaptor;\r
+            }\r
+\r
+            /// <summary>\r
+            /// Overloaded decrement operator\r
+            /// </summary>\r
+            public static ExponentAdaptor operator --(ExponentAdaptor adaptor)\r
+            {\r
+                adaptor = adaptor - 1;\r
+                return adaptor;\r
+            }\r
+\r
+            /// <summary>\r
+            /// Overloaded addition operator\r
+            /// </summary>\r
+            public static ExponentAdaptor operator +(ExponentAdaptor a1, ExponentAdaptor a2)\r
+            {\r
+                if (a1.expValue == Int32.MaxValue) return a1;\r
+\r
+                Int64 temp = (Int64)a1.expValue;\r
+                temp += (Int64)(a2.expValue);\r
+\r
+                if (temp > (Int64)Int32.MaxValue)\r
+                {\r
+                    a1.expValue = Int32.MaxValue;\r
+                }\r
+                else if (temp < (Int64)Int32.MinValue)\r
+                {\r
+                    a1.expValue = Int32.MinValue;\r
+                }\r
+                else\r
+                {\r
+                    a1.expValue = (Int32)temp;\r
+                }\r
+\r
+                return a1;\r
+            }\r
+\r
+            /// <summary>\r
+            /// Overloaded subtraction operator\r
+            /// </summary>\r
+            public static ExponentAdaptor operator -(ExponentAdaptor a1, ExponentAdaptor a2)\r
+            {\r
+                if (a1.expValue == Int32.MaxValue) return a1;\r
+\r
+                Int64 temp = (Int64)a1.expValue;\r
+                temp -= (Int64)(a2.expValue);\r
+\r
+                if (temp > (Int64)Int32.MaxValue)\r
+                {\r
+                    a1.expValue = Int32.MaxValue;\r
+                }\r
+                else if (temp < (Int64)Int32.MinValue)\r
+                {\r
+                    a1.expValue = Int32.MinValue;\r
+                }\r
+                else\r
+                {\r
+                    a1.expValue = (Int32)temp;\r
+                }\r
+\r
+                return a1;\r
+            }\r
+\r
+            /// <summary>\r
+            /// Overloaded multiplication operator\r
+            /// </summary>\r
+            public static ExponentAdaptor operator *(ExponentAdaptor a1, ExponentAdaptor a2)\r
+            {\r
+                if (a1.expValue == Int32.MaxValue) return a1;\r
+\r
+                Int64 temp = (Int64)a1.expValue;\r
+                temp *= (Int64)a2.expValue;\r
+\r
+                if (temp > (Int64)Int32.MaxValue)\r
+                {\r
+                    a1.expValue = Int32.MaxValue;\r
+                }\r
+                else if (temp < (Int64)Int32.MinValue)\r
+                {\r
+                    a1.expValue = Int32.MinValue;\r
+                }\r
+                else\r
+                {\r
+                    a1.expValue = (Int32)temp;\r
+                }\r
+\r
+                return a1;\r
+            }\r
+\r
+            /// <summary>\r
+            /// Overloaded division operator\r
+            /// </summary>\r
+            public static ExponentAdaptor operator /(ExponentAdaptor a1, ExponentAdaptor a2)\r
+            {\r
+                if (a1.expValue == Int32.MaxValue) return a1;\r
+\r
+                ExponentAdaptor res = new ExponentAdaptor();\r
+                res.expValue = a1.expValue / a2.expValue;\r
+                return res;\r
+            }\r
+\r
+            /// <summary>\r
+            /// Overloaded right-shift operator\r
+            /// </summary>\r
+            public static ExponentAdaptor operator >>(ExponentAdaptor a1, int shift)\r
+            {\r
+                if (a1.expValue == Int32.MaxValue) return a1;\r
+\r
+                ExponentAdaptor res = new ExponentAdaptor();\r
+                res.expValue = a1.expValue >> shift;\r
+                return res;\r
+            }\r
+\r
+            /// <summary>\r
+            /// Overloaded left-shift operator\r
+            /// </summary>\r
+            /// <param name="a1"></param>\r
+            /// <param name="shift"></param>\r
+            /// <returns></returns>\r
+            public static ExponentAdaptor operator <<(ExponentAdaptor a1, int shift)\r
+            {\r
+                if (a1.expValue == 0) return a1;\r
+\r
+                ExponentAdaptor res = new ExponentAdaptor();\r
+                res.expValue = a1.expValue;\r
+\r
+                if (shift > 31)\r
+                {\r
+                    res.expValue = Int32.MaxValue;\r
+                }\r
+                else\r
+                {\r
+                    Int64 temp = a1.expValue;\r
+                    temp = temp << shift;\r
+\r
+                    if (temp > (Int64)Int32.MaxValue)\r
+                    {\r
+                        res.expValue = Int32.MaxValue;\r
+                    }\r
+                    else if (temp < (Int64)Int32.MinValue)\r
+                    {\r
+                        res.expValue = Int32.MinValue;\r
+                    }\r
+                    else\r
+                    {\r
+                        res.expValue = (Int32)temp;\r
+                    }\r
+                }\r
+\r
+                return res;\r
+            }\r
+\r
+            private Int32 expValue;\r
+        }\r
+\r
+        //************************ Constructors **************************\r
+\r
+        /// <summary>\r
+        /// Constructs a 128-bit BigFloat\r
+        /// \r
+        /// Sets the value to zero\r
+        /// </summary>\r
+        static BigFloat()\r
+        {\r
+            RoundingDigits = 3;\r
+            RoundingMode = RoundingModeType.TRIM;\r
+            scratch = new BigInt(new PrecisionSpec(128, PrecisionSpec.BaseType.BIN));\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigFloat of the required precision\r
+        /// \r
+        /// Sets the value to zero\r
+        /// </summary>\r
+        /// <param name="mantissaPrec"></param>\r
+        public BigFloat(PrecisionSpec mantissaPrec)\r
+        {\r
+            Init(mantissaPrec);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a big float from a UInt32 to the required precision\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <param name="mantissaPrec"></param>\r
+        public BigFloat(UInt32 value, PrecisionSpec mantissaPrec)\r
+        {\r
+            int mbWords = ((mantissaPrec.NumBits) >> 5);\r
+            if ((mantissaPrec.NumBits & 31) != 0) mbWords++;\r
+            int newManBits = mbWords << 5;\r
+\r
+            //For efficiency, we just use a 32-bit exponent\r
+            exponent = 0;\r
+\r
+            mantissa = new BigInt(value, new PrecisionSpec(newManBits, PrecisionSpec.BaseType.BIN));\r
+            //scratch = new BigInt(mantissa.Precision);\r
+\r
+            int bit = BigInt.GetMSB(value);\r
+            if (bit == -1) return;\r
+\r
+            int shift = mantissa.Precision.NumBits - (bit + 1);\r
+            mantissa.LSH(shift);\r
+            exponent = bit;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigFloat from an Int32 to the required precision\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <param name="mantissaPrec"></param>\r
+        public BigFloat(Int32 value, PrecisionSpec mantissaPrec)\r
+        {\r
+            int mbWords = ((mantissaPrec.NumBits) >> 5);\r
+            if ((mantissaPrec.NumBits & 31) != 0) mbWords++;\r
+            int newManBits = mbWords << 5;\r
+\r
+            //For efficiency, we just use a 32-bit exponent\r
+            exponent = 0;\r
+            UInt32 uValue;\r
+            \r
+            if (value < 0)\r
+            {\r
+                if (value == Int32.MinValue)\r
+                {\r
+                    uValue = 0x80000000;\r
+                }\r
+                else\r
+                {\r
+                    uValue = (UInt32)(-value);\r
+                }\r
+            }\r
+            else\r
+            {\r
+                uValue = (UInt32)value;\r
+            }\r
+\r
+            mantissa = new BigInt(value, new PrecisionSpec(newManBits, PrecisionSpec.BaseType.BIN));\r
+            //scratch = new BigInt(new PrecisionSpec(newManBits, PrecisionSpec.BaseType.BIN));\r
+\r
+            int bit = BigInt.GetMSB(uValue);\r
+            if (bit == -1) return;\r
+\r
+            int shift = mantissa.Precision.NumBits - (bit + 1);\r
+            mantissa.LSH(shift);\r
+            exponent = bit;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigFloat from a 64-bit integer\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <param name="mantissaPrec"></param>\r
+        public BigFloat(Int64 value, PrecisionSpec mantissaPrec)\r
+        {\r
+            int mbWords = ((mantissaPrec.NumBits) >> 5);\r
+            if ((mantissaPrec.NumBits & 31) != 0) mbWords++;\r
+            int newManBits = mbWords << 5;\r
+\r
+            //For efficiency, we just use a 32-bit exponent\r
+            exponent = 0;\r
+            UInt64 uValue;\r
+\r
+            if (value < 0)\r
+            {\r
+                if (value == Int64.MinValue)\r
+                {\r
+                    uValue = 0x80000000;\r
+                }\r
+                else\r
+                {\r
+                    uValue = (UInt64)(-value);\r
+                }\r
+            }\r
+            else\r
+            {\r
+                uValue = (UInt64)value;\r
+            }\r
+\r
+            mantissa = new BigInt(value, new PrecisionSpec(newManBits, PrecisionSpec.BaseType.BIN));\r
+            //scratch = new BigInt(new PrecisionSpec(newManBits, PrecisionSpec.BaseType.BIN));\r
+\r
+            int bit = BigInt.GetMSB(uValue);\r
+            if (bit == -1) return;\r
+\r
+            int shift = mantissa.Precision.NumBits - (bit + 1);\r
+            if (shift > 0)\r
+            {\r
+                mantissa.LSH(shift);\r
+            }\r
+            else\r
+            {\r
+                mantissa.SetHighDigit((uint)(uValue >> (-shift)));\r
+            }\r
+            exponent = bit;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigFloat from a 64-bit unsigned integer\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <param name="mantissaPrec"></param>\r
+        public BigFloat(UInt64 value, PrecisionSpec mantissaPrec)\r
+        {\r
+            int mbWords = ((mantissaPrec.NumBits) >> 5);\r
+            if ((mantissaPrec.NumBits & 31) != 0) mbWords++;\r
+            int newManBits = mbWords << 5;\r
+\r
+            //For efficiency, we just use a 32-bit exponent\r
+            exponent = 0;\r
+\r
+            int bit = BigInt.GetMSB(value);\r
+\r
+            mantissa = new BigInt(value, new PrecisionSpec(newManBits, PrecisionSpec.BaseType.BIN));\r
+            //scratch = new BigInt(mantissa.Precision);\r
+\r
+            int shift = mantissa.Precision.NumBits - (bit + 1);\r
+            if (shift > 0)\r
+            {\r
+                mantissa.LSH(shift);\r
+            }\r
+            else\r
+            {\r
+                mantissa.SetHighDigit((uint)(value >> (-shift)));\r
+            }\r
+            exponent = bit;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigFloat from a BigInt, using the specified precision\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <param name="mantissaPrec"></param>\r
+        public BigFloat(BigInt value, PrecisionSpec mantissaPrec)\r
+        {\r
+            if (value.IsZero())\r
+            {\r
+                Init(mantissaPrec);\r
+                SetZero();\r
+                return;\r
+            }\r
+\r
+            mantissa = new BigInt(value, mantissaPrec);\r
+            exponent = BigInt.GetMSB(value);\r
+            mantissa.Normalise();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Construct a BigFloat from a double-precision floating point number\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <param name="mantissaPrec"></param>\r
+        public BigFloat(double value, PrecisionSpec mantissaPrec)\r
+        {\r
+            if (value == 0.0)\r
+            {\r
+                Init(mantissaPrec);\r
+                return;\r
+            }\r
+\r
+            bool sign = (value < 0) ? true : false;\r
+\r
+            long bits = BitConverter.DoubleToInt64Bits(value);\r
+            // Note that the shift is sign-extended, hence the test against -1 not 1\r
+            int valueExponent = (int)((bits >> 52) & 0x7ffL);\r
+            long valueMantissa = bits & 0xfffffffffffffL;\r
+\r
+            //The mantissa is stored with the top bit implied.\r
+            valueMantissa = valueMantissa | 0x10000000000000L;\r
+\r
+            //The exponent is biased by 1023.\r
+            exponent = valueExponent - 1023;\r
+\r
+            //Round the number of bits to the nearest word.\r
+            int mbWords = ((mantissaPrec.NumBits) >> 5);\r
+            if ((mantissaPrec.NumBits & 31) != 0) mbWords++;\r
+            int newManBits = mbWords << 5;\r
+\r
+            mantissa = new BigInt(new PrecisionSpec(newManBits, PrecisionSpec.BaseType.BIN));\r
+            //scratch = new BigInt(new PrecisionSpec(newManBits, PrecisionSpec.BaseType.BIN));\r
+\r
+            if (newManBits >= 64)\r
+            {\r
+                //The mantissa is 53 bits now, so add 11 to put it in the right place.\r
+                mantissa.SetHighDigits(valueMantissa << 11);\r
+            }\r
+            else\r
+            {\r
+                //To get the top word of the mantissa, shift up by 11 and down by 32 = down by 21\r
+                mantissa.SetHighDigit((uint)(valueMantissa >> 21));\r
+            }\r
+\r
+            mantissa.Sign = sign;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Copy constructor\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        public BigFloat(BigFloat value)\r
+        {\r
+            Init(value.mantissa.Precision);\r
+            exponent = value.exponent;\r
+            mantissa.Assign(value.mantissa);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Copy Constructor - constructs a new BigFloat with the specified precision, copying the old one.\r
+        /// \r
+        /// The value is rounded towards zero in the case where precision is decreased. The Round() function\r
+        /// should be used beforehand if a correctly rounded result is required.\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <param name="mantissaPrec"></param>\r
+        public BigFloat(BigFloat value, PrecisionSpec mantissaPrec)\r
+        {\r
+            Init(mantissaPrec);\r
+            exponent = value.exponent;\r
+            if (mantissa.AssignHigh(value.mantissa)) exponent++;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigFloat from a string\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <param name="mantissaPrec"></param>\r
+        public BigFloat(string value, PrecisionSpec mantissaPrec)\r
+        {\r
+            Init(mantissaPrec);\r
+\r
+            PrecisionSpec extendedPres = new PrecisionSpec(mantissa.Precision.NumBits + 1, PrecisionSpec.BaseType.BIN);\r
+            BigFloat ten = new BigFloat(10, extendedPres);\r
+            BigFloat iPart = new BigFloat(extendedPres);\r
+            BigFloat fPart = new BigFloat(extendedPres);\r
+            BigFloat tenRCP = ten.Reciprocal();\r
+\r
+            if (value.Contains(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NaNSymbol))\r
+            {\r
+                SetNaN();\r
+                return;\r
+            }\r
+            else if (value.Contains(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.PositiveInfinitySymbol))\r
+            {\r
+                SetInfPlus();\r
+                return;\r
+            }\r
+            else if (value.Contains(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NegativeInfinitySymbol))\r
+            {\r
+                SetInfMinus();\r
+                return;\r
+            }\r
+\r
+            string decimalpoint = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;\r
+\r
+            char[] digitChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ',', '.' };\r
+\r
+            //Read in the integer part up the the decimal point.\r
+            bool sign = false;\r
+            value = value.Trim();\r
+\r
+            int i = 0;\r
+\r
+            if (value.Length > i && value[i] == '-')\r
+            {\r
+                sign = true;\r
+                i++;\r
+            }\r
+\r
+            if (value.Length > i && value[i] == '+')\r
+            {\r
+                i++;\r
+            }\r
+\r
+            for ( ; i < value.Length; i++)\r
+            {\r
+                //break on decimal point\r
+                if (value[i] == decimalpoint[0]) break;\r
+\r
+                int digit = Array.IndexOf(digitChars, value[i]);\r
+                if (digit < 0) break;\r
+\r
+                //Ignore place separators (assumed either , or .)\r
+                if (digit > 9) continue;\r
+\r
+                if (i > 0) iPart.Mul(ten);\r
+                iPart.Add(new BigFloat(digit, extendedPres));\r
+            }\r
+\r
+            //If we've run out of characters, assign everything and return\r
+            if (i == value.Length)\r
+            {\r
+                iPart.mantissa.Sign = sign;\r
+                exponent = iPart.exponent;\r
+                if (mantissa.AssignHigh(iPart.mantissa)) exponent++;\r
+                return;\r
+            }\r
+\r
+            //Assign the characters after the decimal point to fPart\r
+            if (value[i] == '.' && i < value.Length - 1)\r
+            {\r
+                BigFloat RecipToUse = new BigFloat(tenRCP);\r
+\r
+                for (i++; i < value.Length; i++)\r
+                {\r
+                    int digit = Array.IndexOf(digitChars, value[i]);\r
+                    if (digit < 0) break;\r
+                    BigFloat temp = new BigFloat(digit, extendedPres);\r
+                    temp.Mul(RecipToUse);\r
+                    RecipToUse.Mul(tenRCP);\r
+                    fPart.Add(temp);\r
+                }\r
+            }\r
+\r
+            //If we're run out of characters, add fPart and iPart and return\r
+            if (i == value.Length)\r
+            {\r
+                iPart.Add(fPart);\r
+                iPart.mantissa.Sign = sign;\r
+                exponent = iPart.exponent;\r
+                if (mantissa.AssignHigh(iPart.mantissa)) exponent++;\r
+                return;\r
+            }\r
+\r
+            if (value[i] == '+' || value[i] == '-') i++;\r
+\r
+            if (i == value.Length)\r
+            {\r
+                iPart.Add(fPart);\r
+                iPart.mantissa.Sign = sign;\r
+                exponent = iPart.exponent;\r
+                if (mantissa.AssignHigh(iPart.mantissa)) exponent++;\r
+                return;\r
+            }\r
+\r
+            //Look for exponential notation.\r
+            if ((value[i] == 'e' || value[i] == 'E') && i < value.Length - 1)\r
+            {\r
+                //Convert the exponent to an int.\r
+                int exp;\r
+\r
+                try\r
+                {\r
+                                       exp = System.Convert.ToInt32(new string(value.ToCharArray()));// i + 1, value.Length - (i + 1))));\r
+                }\r
+                catch (Exception)\r
+                {\r
+                    iPart.Add(fPart);\r
+                    iPart.mantissa.Sign = sign;\r
+                    exponent = iPart.exponent;\r
+                    if (mantissa.AssignHigh(iPart.mantissa)) exponent++;\r
+                    return;\r
+                }\r
+\r
+                //Raise or lower 10 to the power of the exponent\r
+                BigFloat acc = new BigFloat(1, extendedPres);\r
+                BigFloat temp = new BigFloat(1, extendedPres);\r
+\r
+                int powerTemp = exp;\r
+\r
+                BigFloat multiplierToUse;\r
+\r
+                if (exp < 0)\r
+                {\r
+                    multiplierToUse = new BigFloat(tenRCP);\r
+                    powerTemp = -exp;\r
+                }\r
+                else\r
+                {\r
+                    multiplierToUse = new BigFloat(ten);\r
+                }\r
+\r
+                //Fast power function\r
+                while (powerTemp != 0)\r
+                {\r
+                    temp.Mul(multiplierToUse);\r
+                    multiplierToUse.Assign(temp);\r
+\r
+                    if ((powerTemp & 1) != 0)\r
+                    {\r
+                        acc.Mul(temp);\r
+                    }\r
+\r
+                    powerTemp >>= 1;\r
+                }\r
+\r
+                iPart.Add(fPart);\r
+                iPart.Mul(acc);\r
+                iPart.mantissa.Sign = sign;\r
+                exponent = iPart.exponent;\r
+                if (mantissa.AssignHigh(iPart.mantissa)) exponent++;\r
+\r
+                return;\r
+            }\r
+\r
+            iPart.Add(fPart);\r
+            iPart.mantissa.Sign = sign;\r
+            exponent = iPart.exponent;\r
+            if (mantissa.AssignHigh(iPart.mantissa)) exponent++;\r
+\r
+        }\r
+\r
+        private void Init(PrecisionSpec mantissaPrec)\r
+        {\r
+            int mbWords = ((mantissaPrec.NumBits) >> 5);\r
+            if ((mantissaPrec.NumBits & 31) != 0) mbWords++;\r
+            int newManBits = mbWords << 5;\r
+\r
+            //For efficiency, we just use a 32-bit exponent\r
+            exponent = 0;\r
+            mantissa = new BigInt(new PrecisionSpec(newManBits, PrecisionSpec.BaseType.BIN));\r
+            //scratch = new BigInt(new PrecisionSpec(newManBits, PrecisionSpec.BaseType.BIN));\r
+        }\r
+\r
+        //************************** Properties *************************\r
+\r
+        /// <summary>\r
+        /// Read-only property. Returns the precision specification of the mantissa.\r
+        /// \r
+        /// Floating point numbers are represented as 2^exponent * mantissa, where the\r
+        /// mantissa and exponent are integers. Note that the exponent in this class is\r
+        /// always a 32-bit integer. The precision therefore specifies how many bits\r
+        /// the mantissa will have.\r
+        /// </summary>\r
+        public PrecisionSpec Precision\r
+        {\r
+            get { return mantissa.Precision; }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Writable property:\r
+        ///     true iff the number is negative or in some cases zero (&lt;0)\r
+        ///     false iff the number if positive or in some cases zero (&gt;0)\r
+        /// </summary>\r
+        public bool Sign \r
+        { \r
+            get { return mantissa.Sign; }\r
+            set { mantissa.Sign = value; }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Read-only property. \r
+        /// True if the number is NAN, INF_PLUS, INF_MINUS or ZERO\r
+        /// False if the number has any other value.\r
+        /// </summary>\r
+        public bool IsSpecialValue\r
+        {\r
+            get\r
+            {\r
+                return (exponent == Int32.MaxValue || mantissa.IsZero());\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Read-only property, returns the type of number this is. Special values include:\r
+        /// \r
+        /// NONE - a regular number\r
+        /// ZERO - zero\r
+        /// NAN - Not a Number (some operations will return this if their inputs are out of range)\r
+        /// INF_PLUS - Positive infinity, not really a number, but a valid input to and output of some functions.\r
+        /// INF_MINUS - Negative infinity, not really a number, but a valid input to and output of some functions.\r
+        /// </summary>\r
+        public SpecialValueType SpecialValue\r
+        {\r
+            get\r
+            {\r
+                if (exponent == Int32.MaxValue)\r
+                {\r
+                    if (mantissa.IsZero())\r
+                    {\r
+                        if (mantissa.Sign) return SpecialValueType.INF_MINUS;\r
+                        return SpecialValueType.INF_PLUS;\r
+                    }\r
+\r
+                    return SpecialValueType.NAN;\r
+                }\r
+                else\r
+                {\r
+                    if (mantissa.IsZero()) return SpecialValueType.ZERO;\r
+                    return SpecialValueType.NONE;\r
+                }\r
+            }\r
+        }\r
+\r
+        //******************** Mathematical Constants *******************\r
+\r
+        /// <summary>\r
+        /// Gets pi to the indicated precision\r
+        /// </summary>\r
+        /// <param name="precision">The precision to perform the calculation to</param>\r
+        /// <returns>pi (the ratio of the area of a circle to its diameter)</returns>\r
+        public static BigFloat GetPi(PrecisionSpec precision)\r
+        {\r
+            if (pi == null || precision.NumBits <= pi.mantissa.Precision.NumBits)\r
+            {\r
+                CalculatePi(precision.NumBits);\r
+            }\r
+\r
+            BigFloat ret = new BigFloat (precision);\r
+            ret.Assign(pi);\r
+\r
+            return ret;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Get e to the indicated precision\r
+        /// </summary>\r
+        /// <param name="precision">The preicision to perform the calculation to</param>\r
+        /// <returns>e (the number for which the d/dx(e^x) = e^x)</returns>\r
+        public static BigFloat GetE(PrecisionSpec precision)\r
+        {\r
+            if (eCache == null || eCache.mantissa.Precision.NumBits < precision.NumBits)\r
+            {\r
+                CalculateEOnly(precision.NumBits);\r
+                //CalculateFactorials(precision.NumBits);\r
+            }\r
+\r
+            BigFloat ret = new BigFloat(precision);\r
+            ret.Assign(eCache);\r
+\r
+            return ret;\r
+        }\r
+\r
+\r
+        //******************** Arithmetic Functions ********************\r
+\r
+        /// <summary>\r
+        /// Addition (this = this + n2)\r
+        /// </summary>\r
+        /// <param name="n2">The number to add</param>\r
+        public void Add(BigFloat n2)\r
+        {\r
+            if (SpecialValueAddTest(n2)) return;\r
+\r
+            if (scratch.Precision.NumBits != n2.mantissa.Precision.NumBits)\r
+            {\r
+                scratch = new BigInt(n2.mantissa.Precision);\r
+            }\r
+\r
+            if (exponent <= n2.exponent)\r
+            {\r
+                int diff = n2.exponent - exponent;\r
+                exponent = n2.exponent;\r
+\r
+                if (diff != 0)\r
+                {\r
+                    mantissa.RSH(diff);\r
+                }\r
+\r
+                uint carry = mantissa.Add(n2.mantissa);\r
+\r
+                if (carry != 0)\r
+                {\r
+                    mantissa.RSH(1);\r
+                    mantissa.SetBit(mantissa.Precision.NumBits - 1);\r
+                    exponent++;\r
+                }\r
+\r
+                exponent -= mantissa.Normalise();\r
+            }\r
+            else\r
+            {\r
+                int diff = exponent - n2.exponent;\r
+\r
+                scratch.Assign(n2.mantissa);\r
+                scratch.RSH(diff);\r
+\r
+                uint carry = scratch.Add(mantissa);\r
+\r
+                if (carry != 0)\r
+                {\r
+                    scratch.RSH(1);\r
+                    scratch.SetBit(mantissa.Precision.NumBits - 1);\r
+                    exponent++;\r
+                }\r
+\r
+                mantissa.Assign(scratch);\r
+\r
+                exponent -= mantissa.Normalise();\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Subtraction (this = this - n2)\r
+        /// </summary>\r
+        /// <param name="n2">The number to subtract from this</param>\r
+        public void Sub(BigFloat n2)\r
+        {\r
+            n2.mantissa.Sign = !n2.mantissa.Sign;\r
+            Add(n2);\r
+            n2.mantissa.Sign = !n2.mantissa.Sign;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Multiplication (this = this * n2)\r
+        /// </summary>\r
+        /// <param name="n2">The number to multiply this by</param>\r
+        public void Mul(BigFloat n2)\r
+        {\r
+            if (SpecialValueMulTest(n2)) return;\r
+\r
+            //Anything times 0 = 0\r
+            if (n2.mantissa.IsZero())\r
+            {\r
+                mantissa.Assign(n2.mantissa);\r
+                exponent = 0;\r
+                return;\r
+            }\r
+\r
+            mantissa.MulHi(n2.mantissa);\r
+            int shift = mantissa.Normalise();\r
+            exponent = exponent + n2.exponent + 1 - shift;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Division (this = this / n2)\r
+        /// </summary>\r
+        /// <param name="n2">The number to divide this by</param>\r
+        public void Div(BigFloat n2)\r
+        {\r
+            if (SpecialValueDivTest(n2)) return;\r
+\r
+            if (mantissa.Precision.NumBits >= 8192)\r
+            {\r
+                BigFloat rcp = n2.Reciprocal();\r
+                Mul(rcp);\r
+            }\r
+            else\r
+            {\r
+                int shift = mantissa.DivAndShift(n2.mantissa);\r
+                exponent = exponent - (n2.exponent + shift);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Multiply by a power of 2 (-ve implies division)\r
+        /// </summary>\r
+        /// <param name="pow2"></param>\r
+        public void MulPow2(int pow2)\r
+        {\r
+            exponent += pow2;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Division-based reciprocal, fastest for small precisions up to 15,000 bits.\r
+        /// </summary>\r
+        /// <returns>The reciprocal 1/this</returns>\r
+        public BigFloat Reciprocal()\r
+        {\r
+            if (mantissa.Precision.NumBits >= 8192) return ReciprocalNewton();\r
+\r
+            BigFloat reciprocal = new BigFloat(1u, mantissa.Precision);\r
+            reciprocal.Div(this);\r
+            return reciprocal;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Newton's method reciprocal, fastest for larger precisions over 15,000 bits.\r
+        /// </summary>\r
+        /// <returns>The reciprocal 1/this</returns>\r
+        public BigFloat ReciprocalNewton()\r
+        {\r
+            if (mantissa.IsZero())\r
+            {\r
+                exponent = Int32.MaxValue;\r
+                return null;\r
+            }\r
+\r
+            bool oldSign = mantissa.Sign;\r
+            int oldExponent = exponent;\r
+\r
+            //Kill exponent for now (will re-institute later)\r
+            exponent = 0;\r
+\r
+            bool topBit = mantissa.IsTopBitOnlyBit();\r
+\r
+            PrecisionSpec curPrec = new PrecisionSpec(32, PrecisionSpec.BaseType.BIN);\r
+\r
+            BigFloat reciprocal = new BigFloat(curPrec);\r
+            BigFloat constant2 = new BigFloat(curPrec);\r
+            BigFloat temp = new BigFloat(curPrec);\r
+            BigFloat thisPrec = new BigFloat(this, curPrec);\r
+\r
+            reciprocal.exponent = 1;\r
+            reciprocal.mantissa.SetHighDigit(3129112985u);\r
+\r
+            constant2.exponent = 1;\r
+            constant2.mantissa.SetHighDigit(0x80000000u);\r
+\r
+            //D is deliberately left negative for all the following operations.\r
+            thisPrec.mantissa.Sign = true;\r
+\r
+            //Initial estimate.\r
+            reciprocal.Add(thisPrec);\r
+\r
+            //mantissa.Sign = false;\r
+\r
+            //Shift down into 0.5 < this < 1 range\r
+            thisPrec.mantissa.RSH(1);\r
+\r
+            //Iteration.\r
+            int accuracyBits = 2;\r
+            int mantissaBits = mantissa.Precision.NumBits;\r
+\r
+            //Each iteration is a pass of newton's method for RCP.\r
+            //The is a substantial optimisation to be done here...\r
+            //You can double the number of bits for the calculations\r
+            //at each iteration, meaning that the whole process only\r
+            //takes some constant multiplier of the time for the\r
+            //full-scale multiplication.\r
+            while (accuracyBits < mantissaBits)\r
+            {\r
+                //Increase the precision as needed\r
+                if (accuracyBits >= curPrec.NumBits / 2)\r
+                {\r
+                    int newBits = curPrec.NumBits * 2;\r
+                    if (newBits > mantissaBits) newBits = mantissaBits;\r
+                    curPrec = new PrecisionSpec(newBits, PrecisionSpec.BaseType.BIN);\r
+\r
+                    reciprocal = new BigFloat(reciprocal, curPrec);\r
+\r
+                    constant2 = new BigFloat(curPrec);\r
+                    constant2.exponent = 1;\r
+                    constant2.mantissa.SetHighDigit(0x80000000u);\r
+\r
+                    temp = new BigFloat(temp, curPrec);\r
+\r
+                    thisPrec = new BigFloat(this, curPrec);\r
+                    thisPrec.mantissa.Sign = true;\r
+                    thisPrec.mantissa.RSH(1);\r
+                }\r
+\r
+                //temp = Xn\r
+                temp.exponent = reciprocal.exponent;\r
+                temp.mantissa.Assign(reciprocal.mantissa);\r
+                //temp = -Xn * D\r
+                temp.Mul(thisPrec);\r
+                //temp = -Xn * D + 2 (= 2 - Xn * D)\r
+                temp.Add(constant2);\r
+                //reciprocal = X(n+1) = Xn * (2 - Xn * D)\r
+                reciprocal.Mul(temp);\r
+\r
+                accuracyBits *= 2;\r
+            }\r
+\r
+            //'reciprocal' is now the reciprocal of the shifted down, zero-exponent mantissa of 'this'\r
+            //Restore the mantissa.\r
+            //mantissa.LSH(1);\r
+            exponent = oldExponent;\r
+            //mantissa.Sign = oldSign;\r
+\r
+            if (topBit)\r
+            {\r
+                reciprocal.exponent = -(oldExponent);\r
+            }\r
+            else\r
+            {\r
+                reciprocal.exponent = -(oldExponent + 1);\r
+            }\r
+            reciprocal.mantissa.Sign = oldSign;\r
+\r
+            return reciprocal;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Newton's method reciprocal, fastest for larger precisions over 15,000 bits.\r
+        /// </summary>\r
+        /// <returns>The reciprocal 1/this</returns>\r
+        private BigFloat ReciprocalNewton2()\r
+        {\r
+            if (mantissa.IsZero())\r
+            {\r
+                exponent = Int32.MaxValue;\r
+                return null;\r
+            }\r
+\r
+            bool oldSign = mantissa.Sign;\r
+            int oldExponent = exponent;\r
+\r
+            //Kill exponent for now (will re-institute later)\r
+            exponent = 0;\r
+\r
+            BigFloat reciprocal = new BigFloat(mantissa.Precision);\r
+            BigFloat constant2 = new BigFloat(mantissa.Precision);\r
+            BigFloat temp = new BigFloat(mantissa.Precision);\r
+\r
+            reciprocal.exponent = 1;\r
+            reciprocal.mantissa.SetHighDigit(3129112985u);\r
+\r
+            constant2.exponent = 1;\r
+            constant2.mantissa.SetHighDigit(0x80000000u);\r
+\r
+            //D is deliberately left negative for all the following operations.\r
+            mantissa.Sign = true;\r
+\r
+            //Initial estimate.\r
+            reciprocal.Add(this);\r
+\r
+            //mantissa.Sign = false;\r
+\r
+            //Shift down into 0.5 < this < 1 range\r
+            mantissa.RSH(1);\r
+            \r
+            //Iteration.\r
+            int accuracyBits = 2;\r
+            int mantissaBits = mantissa.Precision.NumBits;\r
+\r
+            //Each iteration is a pass of newton's method for RCP.\r
+            //The is a substantial optimisation to be done here...\r
+            //You can double the number of bits for the calculations\r
+            //at each iteration, meaning that the whole process only\r
+            //takes some constant multiplier of the time for the\r
+            //full-scale multiplication.\r
+            while (accuracyBits < mantissaBits)\r
+            {\r
+                //temp = Xn\r
+                temp.exponent = reciprocal.exponent;\r
+                temp.mantissa.Assign(reciprocal.mantissa);\r
+                //temp = -Xn * D\r
+                temp.Mul(this);\r
+                //temp = -Xn * D + 2 (= 2 - Xn * D)\r
+                temp.Add(constant2);\r
+                //reciprocal = X(n+1) = Xn * (2 - Xn * D)\r
+                reciprocal.Mul(temp);\r
+\r
+                accuracyBits *= 2;\r
+            }\r
+\r
+            //'reciprocal' is now the reciprocal of the shifted down, zero-exponent mantissa of 'this'\r
+            //Restore the mantissa.\r
+            mantissa.LSH(1);\r
+            exponent = oldExponent;\r
+            mantissa.Sign = oldSign;\r
+\r
+            reciprocal.exponent = -(oldExponent + 1);\r
+            reciprocal.mantissa.Sign = oldSign;\r
+\r
+            return reciprocal;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Sets this equal to the input\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        public void Assign(BigFloat n2)\r
+        {\r
+            exponent = n2.exponent;\r
+            if (mantissa.AssignHigh(n2.mantissa)) exponent++;\r
+        }\r
+\r
+\r
+        //********************* Comparison Functions *******************\r
+\r
+        /// <summary>\r
+        /// Greater than comparison\r
+        /// </summary>\r
+        /// <param name="n2">the number to compare this to</param>\r
+        /// <returns>true iff this is greater than n2 (this &gt; n2)</returns>\r
+        public bool GreaterThan(BigFloat n2)\r
+        {\r
+            if (IsSpecialValue || n2.IsSpecialValue)\r
+            {\r
+                SpecialValueType s1 = SpecialValue;\r
+                SpecialValueType s2 = SpecialValue;\r
+\r
+                if (s1 == SpecialValueType.NAN || s2 == SpecialValueType.NAN) return false;\r
+                if (s1 == SpecialValueType.INF_MINUS) return false;\r
+                if (s2 == SpecialValueType.INF_PLUS) return false;\r
+                if (s1 == SpecialValueType.INF_PLUS) return true;\r
+                if (s2 == SpecialValueType.INF_MINUS) return true;\r
+\r
+                if (s1 == SpecialValueType.ZERO)\r
+                {\r
+                    if (s2 != SpecialValueType.ZERO && n2.Sign)\r
+                    {\r
+                        return true;\r
+                    }\r
+                    else\r
+                    {\r
+                        return false;\r
+                    }\r
+                }\r
+\r
+                if (s2 == SpecialValueType.ZERO)\r
+                {\r
+                    return !Sign;\r
+                }\r
+            }\r
+\r
+            if (!mantissa.Sign && n2.mantissa.Sign) return true;\r
+            if (mantissa.Sign && !n2.mantissa.Sign) return false;\r
+            if (!mantissa.Sign)\r
+            {\r
+                if (exponent > n2.exponent) return true;\r
+                if (exponent < n2.exponent) return false;\r
+            }\r
+            if (mantissa.Sign)\r
+            {\r
+                if (exponent > n2.exponent) return false;\r
+                if (exponent < n2.exponent) return true;\r
+            }\r
+\r
+            return mantissa.GreaterThan(n2.mantissa);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Less than comparison\r
+        /// </summary>\r
+        /// <param name="n2">the number to compare this to</param>\r
+        /// <returns>true iff this is less than n2 (this &lt; n2)</returns>\r
+        public bool LessThan(BigFloat n2)\r
+        {\r
+            if (IsSpecialValue || n2.IsSpecialValue)\r
+            {\r
+                SpecialValueType s1 = SpecialValue;\r
+                SpecialValueType s2 = SpecialValue;\r
+\r
+                if (s1 == SpecialValueType.NAN || s2 == SpecialValueType.NAN) return false;\r
+                if (s1 == SpecialValueType.INF_PLUS) return false;\r
+                if (s2 == SpecialValueType.INF_PLUS) return true;\r
+                if (s2 == SpecialValueType.INF_MINUS) return false;\r
+                if (s1 == SpecialValueType.INF_MINUS) return true;\r
+\r
+                if (s1 == SpecialValueType.ZERO)\r
+                {\r
+                    if (s2 != SpecialValueType.ZERO && !n2.Sign)\r
+                    {\r
+                        return true;\r
+                    }\r
+                    else\r
+                    {\r
+                        return false;\r
+                    }\r
+                }\r
+\r
+                if (s2 == SpecialValueType.ZERO)\r
+                {\r
+                    return Sign;\r
+                }\r
+            }\r
+\r
+            if (!mantissa.Sign && n2.mantissa.Sign) return false;\r
+            if (mantissa.Sign && !n2.mantissa.Sign) return true;\r
+            if (!mantissa.Sign)\r
+            {\r
+                if (exponent > n2.exponent) return false;\r
+                if (exponent < n2.exponent) return true;\r
+            }\r
+            if (mantissa.Sign)\r
+            {\r
+                if (exponent > n2.exponent) return true;\r
+                if (exponent < n2.exponent) return false;\r
+            }\r
+\r
+            return mantissa.LessThan(n2.mantissa);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Greater than comparison\r
+        /// </summary>\r
+        /// <param name="i">the number to compare this to</param>\r
+        /// <returns>true iff this is greater than n2 (this &gt; n2)</returns>\r
+        public bool GreaterThan(int i)\r
+        {\r
+            BigFloat integer = new BigFloat(i, mantissa.Precision);\r
+            return GreaterThan(integer);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Less than comparison\r
+        /// </summary>\r
+        /// <param name="i">the number to compare this to</param>\r
+        /// <returns>true iff this is less than n2 (this &lt; n2)</returns>\r
+        public bool LessThan(int i)\r
+        {\r
+            BigFloat integer = new BigFloat(i, mantissa.Precision);\r
+            return LessThan(integer);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Compare to zero\r
+        /// </summary>\r
+        /// <returns>true if this is zero (this == 0)</returns>\r
+        public bool IsZero()\r
+        {\r
+            return (mantissa.IsZero());\r
+        }\r
+\r
+\r
+        //******************** Mathematical Functions ******************\r
+\r
+        /// <summary>\r
+        /// Sets the number to the biggest integer numerically closer to zero, if possible.\r
+        /// </summary>\r
+        public void Floor()\r
+        {\r
+            //Already an integer.\r
+            if (exponent >= mantissa.Precision.NumBits) return;\r
+\r
+            if (exponent < 0)\r
+            {\r
+                mantissa.ZeroBits(mantissa.Precision.NumBits);\r
+                exponent = 0;\r
+                return;\r
+            }\r
+\r
+            mantissa.ZeroBits(mantissa.Precision.NumBits - (exponent + 1));\r
+        }\r
+\r
+        /// <summary>\r
+        /// Sets the number to its fractional component (equivalent to 'this' - (int)'this')\r
+        /// </summary>\r
+        public void FPart()\r
+        {\r
+            //Already fractional\r
+            if (exponent < 0)\r
+            {\r
+                return;\r
+            }\r
+\r
+            //Has no fractional part\r
+            if (exponent >= mantissa.Precision.NumBits)\r
+            {\r
+                mantissa.Zero();\r
+                exponent = 0;\r
+                return;\r
+            }\r
+\r
+            mantissa.ZeroBitsHigh(exponent + 1);\r
+            exponent -= mantissa.Normalise();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates tan(x)\r
+        /// </summary>\r
+        public void Tan()\r
+        {\r
+            if (IsSpecialValue)\r
+            {\r
+                //Tan(x) has no limit as x->inf\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || SpecialValue == SpecialValueType.INF_PLUS)\r
+                {\r
+                    SetNaN();\r
+                }\r
+                else if (SpecialValue == SpecialValueType.ZERO)\r
+                {\r
+                    SetZero();\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            if (pi == null || pi.mantissa.Precision.NumBits != mantissa.Precision.NumBits)\r
+            {\r
+                CalculatePi(mantissa.Precision.NumBits);\r
+            }\r
+\r
+            //Work out the sign change (involves replicating some rescaling).\r
+            bool sign = mantissa.Sign;\r
+            mantissa.Sign = false;\r
+\r
+            if (mantissa.IsZero())\r
+            {\r
+                return;\r
+            }\r
+\r
+            //Rescale into 0 <= x < pi\r
+            if (GreaterThan(pi))\r
+            {\r
+                //There will be an inherent loss of precision doing this.\r
+                BigFloat newAngle = new BigFloat(this);\r
+                newAngle.Mul(piRecip);\r
+                newAngle.FPart();\r
+                newAngle.Mul(pi);\r
+                Assign(newAngle);\r
+            }\r
+\r
+            //Rescale to -pi/2 <= x < pi/2\r
+            if (!LessThan(piBy2))\r
+            {\r
+                Sub(pi);\r
+            }\r
+\r
+            //Now the sign of the sin determines the sign of the tan.\r
+            //tan(x) = sin(x) / sqrt(1 - sin^2(x))\r
+            Sin();\r
+            BigFloat denom = new BigFloat(this);\r
+            denom.Mul(this);\r
+            denom.Sub(new BigFloat(1, mantissa.Precision));\r
+            denom.mantissa.Sign = !denom.mantissa.Sign;\r
+\r
+            if (denom.mantissa.Sign)\r
+            {\r
+                denom.SetZero();\r
+            }\r
+\r
+            denom.Sqrt();\r
+            Div(denom);\r
+            if (sign) mantissa.Sign = !mantissa.Sign;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates Cos(x)\r
+        /// </summary>\r
+        public void Cos()\r
+        {\r
+            if (IsSpecialValue)\r
+            {\r
+                //Cos(x) has no limit as x->inf\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || SpecialValue == SpecialValueType.INF_PLUS)\r
+                {\r
+                    SetNaN();\r
+                }\r
+                else if (SpecialValue == SpecialValueType.ZERO)\r
+                {\r
+                    Assign(new BigFloat(1, mantissa.Precision));\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            if (pi == null || pi.mantissa.Precision.NumBits != mantissa.Precision.NumBits)\r
+            {\r
+                CalculatePi(mantissa.Precision.NumBits);\r
+            }\r
+\r
+            Add(piBy2);\r
+            Sin();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates Sin(x):\r
+        /// This takes a little longer and is less accurate if the input is out of the range (-pi, pi].\r
+        /// </summary>\r
+        public void Sin()\r
+        {\r
+            if (IsSpecialValue)\r
+            {\r
+                //Sin(x) has no limit as x->inf\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || SpecialValue == SpecialValueType.INF_PLUS)\r
+                {\r
+                    SetNaN();\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            //Convert to positive range (0 <= x < inf)\r
+            bool sign = mantissa.Sign;\r
+            mantissa.Sign = false;\r
+\r
+            if (pi == null || pi.mantissa.Precision.NumBits != mantissa.Precision.NumBits)\r
+            {\r
+                CalculatePi(mantissa.Precision.NumBits);\r
+            }\r
+\r
+            if (inverseFactorialCache == null || invFactorialCutoff != mantissa.Precision.NumBits)\r
+            {\r
+                CalculateFactorials(mantissa.Precision.NumBits);\r
+            }\r
+\r
+            //Rescale into 0 <= x < 2*pi\r
+            if (GreaterThan(twoPi))\r
+            {\r
+                //There will be an inherent loss of precision doing this.\r
+                BigFloat newAngle = new BigFloat(this);\r
+                newAngle.Mul(twoPiRecip);\r
+                newAngle.FPart();\r
+                newAngle.Mul(twoPi);\r
+                Assign(newAngle);\r
+            }\r
+\r
+            //Rescale into range 0 <= x < pi\r
+            if (GreaterThan(pi))\r
+            {\r
+                //sin(pi + a) = sin(pi)cos(a) + sin(a)cos(pi) = 0 - sin(a) = -sin(a)\r
+                Sub(pi);\r
+                sign = !sign;\r
+            }\r
+\r
+            BigFloat temp = new BigFloat(mantissa.Precision);\r
+\r
+            //Rescale into range 0 <= x < pi/2\r
+            if (GreaterThan(piBy2))\r
+            {\r
+                temp.Assign(this);\r
+                Assign(pi);\r
+                Sub(temp);\r
+            }\r
+\r
+            //Rescale into range 0 <= x < pi/6 to accelerate convergence.\r
+            //This is done using sin(3x) = 3sin(x) - 4sin^3(x)\r
+            Mul(threeRecip);\r
+\r
+            if (mantissa.IsZero())\r
+            {\r
+                exponent = 0;\r
+                return;\r
+            }\r
+\r
+            BigFloat term = new BigFloat(this);\r
+\r
+            BigFloat square = new BigFloat(this);\r
+            square.Mul(term);\r
+\r
+            BigFloat sum = new BigFloat(this);\r
+\r
+            bool termSign = true;\r
+            int length = inverseFactorialCache.Length;\r
+            int numBits = mantissa.Precision.NumBits;\r
+\r
+            for (int i = 3; i < length; i += 2)\r
+            {\r
+                term.Mul(square);\r
+                temp.Assign(inverseFactorialCache[i]);\r
+                temp.Mul(term);\r
+                temp.mantissa.Sign = termSign;\r
+                termSign = !termSign;\r
+\r
+                if (temp.exponent < -numBits) break;\r
+\r
+                sum.Add(temp);\r
+            }\r
+\r
+            //Restore the triple-angle: sin(3x) = 3sin(x) - 4sin^3(x)\r
+            Assign(sum);\r
+            sum.Mul(this);\r
+            sum.Mul(this);\r
+            Mul(new BigFloat(3, mantissa.Precision));\r
+            sum.exponent += 2;\r
+            Sub(sum);\r
+\r
+            //Restore the sign\r
+            mantissa.Sign = sign;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Hyperbolic Sin (sinh) function\r
+        /// </summary>\r
+        public void Sinh()\r
+        {\r
+            if (IsSpecialValue)\r
+            {\r
+                return;\r
+            }\r
+\r
+            Exp();\r
+            Sub(Reciprocal());\r
+            exponent--;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Hyperbolic cosine (cosh) function\r
+        /// </summary>\r
+        public void Cosh()\r
+        {\r
+            if (IsSpecialValue)\r
+            {\r
+                if (SpecialValue == SpecialValueType.ZERO)\r
+                {\r
+                    Assign(new BigFloat(1, mantissa.Precision));\r
+                }\r
+                else if (SpecialValue == SpecialValueType.INF_MINUS)\r
+                {\r
+                    SetInfPlus();\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            Exp();\r
+            Add(Reciprocal());\r
+            exponent--;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Hyperbolic tangent function (tanh)\r
+        /// </summary>\r
+        public void Tanh()\r
+        {\r
+            if (IsSpecialValue)\r
+            {\r
+                if (SpecialValue == SpecialValueType.INF_MINUS)\r
+                {\r
+                    Assign(new BigFloat(-1, mantissa.Precision));\r
+                }\r
+                else if (SpecialValue == SpecialValueType.INF_PLUS)\r
+                {\r
+                    Assign(new BigFloat(1, mantissa.Precision));\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            exponent++;\r
+            Exp();\r
+            BigFloat temp = new BigFloat(this);\r
+            BigFloat one = new BigFloat(1, mantissa.Precision);\r
+            temp.Add(one);\r
+            Sub(one);\r
+            Div(temp);\r
+        }\r
+\r
+        /// <summary>\r
+        /// arcsin(): the inverse function of sin(), range of (-pi/2..pi/2)\r
+        /// </summary>\r
+        public void Arcsin()\r
+        {\r
+            if (IsSpecialValue)\r
+            {\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || SpecialValue == SpecialValueType.INF_PLUS || SpecialValue == SpecialValueType.NAN)\r
+                {\r
+                    SetNaN();\r
+                    return;\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            BigFloat one = new BigFloat(1, mantissa.Precision);\r
+            BigFloat plusABit = new BigFloat(1, mantissa.Precision);\r
+            plusABit.exponent -= (mantissa.Precision.NumBits - (mantissa.Precision.NumBits >> 6));\r
+            BigFloat onePlusABit = new BigFloat(1, mantissa.Precision);\r
+            onePlusABit.Add(plusABit);\r
+\r
+            bool sign = mantissa.Sign;\r
+            mantissa.Sign = false;\r
+\r
+            if (GreaterThan(onePlusABit))\r
+            {\r
+                SetNaN();\r
+            }\r
+            else if (LessThan(one))\r
+            {\r
+                BigFloat temp = new BigFloat(this);\r
+                temp.Mul(this);\r
+                temp.Sub(one);\r
+                temp.mantissa.Sign = !temp.mantissa.Sign;\r
+                temp.Sqrt();\r
+                temp.Add(one);\r
+                Div(temp);\r
+                Arctan();\r
+                exponent++;\r
+                mantissa.Sign = sign;\r
+            }\r
+            else\r
+            {\r
+                if (pi == null || pi.mantissa.Precision.NumBits != mantissa.Precision.NumBits)\r
+                {\r
+                    CalculatePi(mantissa.Precision.NumBits);\r
+                }\r
+\r
+                Assign(piBy2);\r
+                if (sign) mantissa.Sign = true;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// arccos(): the inverse function of cos(), range (0..pi)\r
+        /// </summary>\r
+        public void Arccos()\r
+        {\r
+            if (IsSpecialValue)\r
+            {\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || SpecialValue == SpecialValueType.INF_PLUS || SpecialValue == SpecialValueType.NAN)\r
+                {\r
+                    SetNaN();\r
+                }\r
+                else if (SpecialValue == SpecialValueType.ZERO)\r
+                {\r
+                    Assign(new BigFloat(1, mantissa.Precision));\r
+                    exponent = 0;\r
+                    Sign = false;\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            BigFloat one = new BigFloat(1, mantissa.Precision);\r
+            BigFloat plusABit = new BigFloat(1, mantissa.Precision);\r
+            plusABit.exponent -= (mantissa.Precision.NumBits - (mantissa.Precision.NumBits >> 6));\r
+            BigFloat onePlusABit = new BigFloat(1, mantissa.Precision);\r
+            onePlusABit.Add(plusABit);\r
+\r
+            bool sign = mantissa.Sign;\r
+            mantissa.Sign = false;\r
+\r
+            if (GreaterThan(onePlusABit))\r
+            {\r
+                SetNaN();\r
+            }\r
+            else if (LessThan(one))\r
+            {\r
+                if (pi == null || pi.mantissa.Precision.NumBits != mantissa.Precision.NumBits)\r
+                {\r
+                    CalculatePi(mantissa.Precision.NumBits);\r
+                }\r
+\r
+                mantissa.Sign = sign;\r
+                BigFloat temp = new BigFloat(this);\r
+                Mul(temp);\r
+                Sub(one);\r
+                mantissa.Sign = !mantissa.Sign;\r
+                Sqrt();\r
+                temp.Add(one);\r
+                Div(temp);\r
+                Arctan();\r
+                exponent++;\r
+            }\r
+            else\r
+            {\r
+                if (sign)\r
+                {\r
+                    if (pi == null || pi.mantissa.Precision.NumBits != mantissa.Precision.NumBits)\r
+                    {\r
+                        CalculatePi(mantissa.Precision.NumBits);\r
+                    }\r
+\r
+                    Assign(pi);\r
+                }\r
+                else\r
+                {\r
+                    mantissa.Zero();\r
+                    exponent = 0;\r
+                }\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// arctan(): the inverse function of sin(), range of (-pi/2..pi/2)\r
+        /// </summary>\r
+        public void Arctan()\r
+        {\r
+            //With 2 argument reductions, we increase precision by a minimum of 4 bits per term.\r
+            int numBits = mantissa.Precision.NumBits;\r
+            int maxTerms = numBits >> 2;\r
+\r
+            if (pi == null || pi.mantissa.Precision.NumBits != numBits)\r
+            {\r
+                CalculatePi(mantissa.Precision.NumBits);\r
+            }\r
+\r
+            //Make domain positive\r
+            bool sign = mantissa.Sign;\r
+            mantissa.Sign = false;\r
+\r
+            if (IsSpecialValue)\r
+            {\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || SpecialValue == SpecialValueType.INF_PLUS)\r
+                {\r
+                    Assign(piBy2);\r
+                    mantissa.Sign = sign;\r
+                    return;\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            if (reciprocals == null || reciprocals[0].mantissa.Precision.NumBits != numBits || reciprocals.Length < maxTerms)\r
+            {\r
+                CalculateReciprocals(numBits, maxTerms);\r
+            }\r
+\r
+            bool invert = false;\r
+            BigFloat one = new BigFloat(1, mantissa.Precision);\r
+\r
+            //Invert if outside of convergence\r
+            if (GreaterThan(one))\r
+            {\r
+                invert = true;\r
+                Assign(Reciprocal());\r
+            }\r
+\r
+            //Reduce using half-angle formula:\r
+            //arctan(2x) = 2 arctan (x / (1 + sqrt(1 + x)))\r
+\r
+            //First reduction (guarantees 2 bits per iteration)\r
+            BigFloat temp = new BigFloat(this);\r
+            temp.Mul(this);\r
+            temp.Add(one);\r
+            temp.Sqrt();\r
+            temp.Add(one);\r
+            this.Div(temp);\r
+\r
+            //Second reduction (guarantees 4 bits per iteration)\r
+            temp.Assign(this);\r
+            temp.Mul(this);\r
+            temp.Add(one);\r
+            temp.Sqrt();\r
+            temp.Add(one);\r
+            this.Div(temp);\r
+\r
+            //Actual series calculation\r
+            int length = reciprocals.Length;\r
+            BigFloat term = new BigFloat(this);\r
+\r
+            //pow = x^2\r
+            BigFloat pow = new BigFloat(this);\r
+            pow.Mul(this);\r
+\r
+            BigFloat sum = new BigFloat(this);\r
+\r
+            for (int i = 1; i < length; i++)\r
+            {\r
+                //u(n) = u(n-1) * x^2\r
+                //t(n) = u(n) / (2n+1)\r
+                term.Mul(pow);\r
+                term.Sign = !term.Sign;\r
+                temp.Assign(term);\r
+                temp.Mul(reciprocals[i]);\r
+\r
+                if (temp.exponent < -numBits) break;\r
+\r
+                sum.Add(temp);\r
+            }\r
+\r
+            //Undo the reductions.\r
+            Assign(sum);\r
+            exponent += 2;\r
+\r
+            if (invert)\r
+            {\r
+                //Assign(Reciprocal());\r
+                mantissa.Sign = true;\r
+                Add(piBy2);\r
+            }\r
+\r
+            if (sign)\r
+            {\r
+                mantissa.Sign = sign;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Arcsinh(): the inverse sinh function\r
+        /// </summary>\r
+        public void Arcsinh()\r
+        {\r
+            //Just let all special values fall through\r
+            if (IsSpecialValue)\r
+            {\r
+                return;\r
+            }\r
+\r
+            BigFloat temp = new BigFloat(this);\r
+            temp.Mul(this);\r
+            temp.Add(new BigFloat(1, mantissa.Precision));\r
+            temp.Sqrt();\r
+            Add(temp);\r
+            Log();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Arccosh(): the inverse cosh() function\r
+        /// </summary>\r
+        public void Arccosh()\r
+        {\r
+            //acosh isn't defined for x < 1\r
+            if (IsSpecialValue)\r
+            {\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || SpecialValue == SpecialValueType.ZERO)\r
+                {\r
+                    SetNaN();\r
+                    return;\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            BigFloat one = new BigFloat(1, mantissa.Precision);\r
+            if (LessThan(one))\r
+            {\r
+                SetNaN();\r
+                return;\r
+            }\r
+\r
+            BigFloat temp = new BigFloat(this);\r
+            temp.Mul(this);\r
+            temp.Sub(one);\r
+            temp.Sqrt();\r
+            Add(temp);\r
+            Log();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Arctanh(): the inverse tanh function\r
+        /// </summary>\r
+        public void Arctanh()\r
+        {\r
+            //|x| <= 1 for a non-NaN output\r
+            if (IsSpecialValue)\r
+            {\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || SpecialValue == SpecialValueType.INF_PLUS)\r
+                {\r
+                    SetNaN();\r
+                    return;\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            BigFloat one = new BigFloat(1, mantissa.Precision);\r
+            BigFloat plusABit = new BigFloat(1, mantissa.Precision);\r
+            plusABit.exponent -= (mantissa.Precision.NumBits - (mantissa.Precision.NumBits >> 6));\r
+            BigFloat onePlusABit = new BigFloat(1, mantissa.Precision);\r
+            onePlusABit.Add(plusABit);\r
+\r
+            bool sign = mantissa.Sign;\r
+            mantissa.Sign = false;\r
+\r
+            if (GreaterThan(onePlusABit))\r
+            {\r
+                SetNaN();\r
+            }\r
+            else if (LessThan(one))\r
+            {\r
+                BigFloat temp = new BigFloat(this);\r
+                Add(one);\r
+                one.Sub(temp);\r
+                Div(one);\r
+                Log();\r
+                exponent--;\r
+                mantissa.Sign = sign;\r
+            }\r
+            else\r
+            {\r
+                if (sign)\r
+                {\r
+                    SetInfMinus();\r
+                }\r
+                else\r
+                {\r
+                    SetInfPlus();\r
+                }\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Two-variable iterative square root, taken from\r
+        /// http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#A_two-variable_iterative_method\r
+        /// </summary>\r
+        public void Sqrt()\r
+        {\r
+            if (mantissa.Sign || IsSpecialValue)\r
+            {\r
+                if (SpecialValue == SpecialValueType.ZERO)\r
+                {\r
+                    return;\r
+                }\r
+\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || mantissa.Sign)\r
+                {\r
+                    SetNaN();\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            BigFloat temp2;\r
+            BigFloat temp3 = new BigFloat(mantissa.Precision);\r
+            BigFloat three = new BigFloat(3, mantissa.Precision);\r
+\r
+            int exponentScale = 0;\r
+\r
+            //Rescale to 0.5 <= x < 2\r
+            if (exponent < -1)\r
+            {\r
+                int diff = -exponent;\r
+                if ((diff & 1) != 0)\r
+                {\r
+                    diff--;\r
+                }\r
+\r
+                exponentScale = -diff;\r
+                exponent += diff;\r
+            }\r
+            else if (exponent > 0)\r
+            {\r
+                if ((exponent & 1) != 0)\r
+                {\r
+                    exponentScale = exponent + 1;\r
+                    exponent = -1;\r
+                }\r
+                else\r
+                {\r
+                    exponentScale = exponent;\r
+                    exponent = 0;\r
+                }\r
+            }\r
+\r
+            temp2 = new BigFloat(this);\r
+            temp2.Sub(new BigFloat(1, mantissa.Precision));\r
+\r
+            //if (temp2.mantissa.IsZero())\r
+            //{\r
+            //    exponent += exponentScale;\r
+            //    return;\r
+            //}\r
+\r
+            int numBits = mantissa.Precision.NumBits;\r
+\r
+            while ((exponent - temp2.exponent) < numBits && temp2.SpecialValue != SpecialValueType.ZERO)\r
+            {\r
+                //a(n+1) = an - an*cn / 2\r
+                temp3.Assign(this);\r
+                temp3.Mul(temp2);\r
+                temp3.MulPow2(-1);\r
+                this.Sub(temp3);\r
+\r
+                //c(n+1) = cn^2 * (cn - 3) / 4\r
+                temp3.Assign(temp2);\r
+                temp2.Sub(three);\r
+                temp2.Mul(temp3);\r
+                temp2.Mul(temp3);\r
+                temp2.MulPow2(-2);\r
+            }\r
+\r
+            exponent += (exponentScale >> 1);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The natural logarithm, ln(x)\r
+        /// </summary>\r
+        public void Log()\r
+        {\r
+            if (IsSpecialValue || mantissa.Sign)\r
+            {\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || mantissa.Sign)\r
+                {\r
+                    SetNaN();\r
+                }\r
+                else if (SpecialValue == SpecialValueType.ZERO)\r
+                {\r
+                    SetInfMinus();\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            if (mantissa.Precision.NumBits >= 512)\r
+            {\r
+                LogAGM1();\r
+                return;\r
+            }\r
+\r
+            //Compute ln2.\r
+            if (ln2cache == null || mantissa.Precision.NumBits > ln2cache.mantissa.Precision.NumBits)\r
+            {\r
+                CalculateLog2(mantissa.Precision.NumBits);\r
+            }\r
+\r
+            Log2();\r
+            Mul(ln2cache);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Log to the base 10\r
+        /// </summary>\r
+        public void Log10()\r
+        {\r
+            if (IsSpecialValue || mantissa.Sign)\r
+            {\r
+                if (SpecialValue == SpecialValueType.INF_MINUS || mantissa.Sign)\r
+                {\r
+                    SetNaN();\r
+                }\r
+                else if (SpecialValue == SpecialValueType.ZERO)\r
+                {\r
+                    SetInfMinus();\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            //Compute ln2.\r
+            if (ln2cache == null || mantissa.Precision.NumBits > ln2cache.mantissa.Precision.NumBits)\r
+            {\r
+                CalculateLog2(mantissa.Precision.NumBits);\r
+            }\r
+\r
+            Log();\r
+            Mul(log10recip);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The exponential function. Less accurate for high exponents, scales poorly with the number\r
+        /// of bits.\r
+        /// </summary>\r
+        public void Exp()\r
+        {\r
+            Exp(mantissa.Precision.NumBits);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Raises a number to an integer power (positive or negative). This is a very accurate and fast function,\r
+        /// comparable to or faster than division (although it is slightly slower for\r
+        /// negative powers, obviously)\r
+        /// \r
+        /// </summary>\r
+        /// <param name="power"></param>\r
+        public void Pow(int power)\r
+        {\r
+            BigFloat acc = new BigFloat(1, mantissa.Precision);\r
+            BigFloat temp = new BigFloat(1, mantissa.Precision);\r
+\r
+            int powerTemp = power;\r
+\r
+            if (power < 0)\r
+            {\r
+                Assign(Reciprocal());\r
+                powerTemp = -power;\r
+            }\r
+\r
+            //Fast power function\r
+            while (powerTemp != 0)\r
+            {\r
+                temp.Mul(this);\r
+                Assign(temp);\r
+\r
+                if ((powerTemp & 1) != 0)\r
+                {\r
+                    acc.Mul(temp);\r
+                }\r
+\r
+                powerTemp >>= 1;\r
+            }\r
+\r
+            Assign(acc);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Raises to an aribitrary power. This is both slow (uses Log) and inaccurate. If you need to\r
+        /// raise e^x use exp(). If you need an integer power, use the integer power function Pow(int)\r
+        /// Accuracy Note:\r
+        ///    The function is only ever accurate to a maximum of 4 decimal digits\r
+        ///    For every 10x larger (or smaller) the power gets, you lose an additional decimal digit\r
+        ///    If you really need a precise result, do the calculation with an extra 32-bits and round\r
+        /// Domain Note:\r
+        ///    This only works for powers of positive real numbers. Negative numbers will fail.\r
+        /// </summary>\r
+        /// <param name="power"></param>\r
+        public void Pow(BigFloat power)\r
+        {\r
+            Log();\r
+            Mul(power);\r
+            Exp();\r
+        }\r
+\r
+\r
+        //******************** Static Math Functions *******************\r
+\r
+        /// <summary>\r
+        /// Returns the integer component of the input\r
+        /// </summary>\r
+        /// <param name="n1">The input number</param>\r
+        /// <remarks>The integer component returned will always be numerically closer to zero\r
+        /// than the input: an input of -3.49 for instance would produce a value of 3.</remarks>\r
+        public static BigFloat Floor(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Floor();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Returns the fractional (non-integer component of the input)\r
+        /// </summary>\r
+        /// <param name="n1">The input number</param>\r
+        public static BigFloat FPart(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.FPart();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates tan(x)\r
+        /// </summary>\r
+        /// <param name="n1">The angle (in radians) to find the tangent of</param>\r
+        public static BigFloat Tan(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Tan();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates Cos(x)\r
+        /// </summary>\r
+        /// <param name="n1">The angle (in radians) to find the cosine of</param>\r
+        /// <remarks>This is a reasonably fast function for smaller precisions, but\r
+        /// doesn't scale well for higher precision arguments</remarks>\r
+        public static BigFloat Cos(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Cos();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates Sin(x):\r
+        /// This takes a little longer and is less accurate if the input is out of the range (-pi, pi].\r
+        /// </summary>\r
+        /// <param name="n1">The angle to find the sine of (in radians)</param>\r
+        /// <remarks>This is a resonably fast function, for smaller precision arguments, but doesn't\r
+        /// scale very well with the number of bits in the input.</remarks>\r
+        public static BigFloat Sin(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Sin();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Hyperbolic Sin (sinh) function\r
+        /// </summary>\r
+        /// <param name="n1">The number to find the hyperbolic sine of</param>\r
+        public static BigFloat Sinh(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Sinh();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Hyperbolic cosine (cosh) function\r
+        /// </summary>\r
+        /// <param name="n1">The number to find the hyperbolic cosine of</param>\r
+        public static BigFloat Cosh(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Cosh();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Hyperbolic tangent function (tanh)\r
+        /// </summary>\r
+        /// <param name="n1">The number to find the hyperbolic tangent of</param>\r
+        public static BigFloat Tanh(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Tanh();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// arcsin(): the inverse function of sin(), range of (-pi/2..pi/2)\r
+        /// </summary>\r
+        /// <param name="n1">The number to find the arcsine of (-pi/2..pi/2)</param>\r
+        /// <remarks>Note that inverse trig functions are only defined within a specific range.\r
+        /// Values outside this range will return NaN, although some margin for error is assumed.\r
+        /// </remarks>\r
+        public static BigFloat Arcsin(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Arcsin();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// arccos(): the inverse function of cos(), input range (0..pi)\r
+        /// </summary>\r
+        /// <param name="n1">The number to find the arccosine of (0..pi)</param>\r
+        /// <remarks>Note that inverse trig functions are only defined within a specific range.\r
+        /// Values outside this range will return NaN, although some margin for error is assumed.\r
+        /// </remarks>\r
+        public static BigFloat Arccos(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Arccos();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// arctan(): the inverse function of sin(), input range of (-pi/2..pi/2)\r
+        /// </summary>\r
+        /// <param name="n1">The number to find the arctangent of (-pi/2..pi/2)</param>\r
+        /// <remarks>Note that inverse trig functions are only defined within a specific range.\r
+        /// Values outside this range will return NaN, although some margin for error is assumed.\r
+        /// </remarks>\r
+        public static BigFloat Arctan(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Arctan();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Arcsinh(): the inverse sinh function\r
+        /// </summary>\r
+        /// <param name="n1">The number to find the inverse hyperbolic sine of</param>\r
+        public static BigFloat Arcsinh(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Arcsinh();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Arccosh(): the inverse cosh() function\r
+        /// </summary>\r
+        /// <param name="n1">The number to find the inverse hyperbolic cosine of</param>\r
+        public static BigFloat Arccosh(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Arccosh();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Arctanh(): the inverse tanh function\r
+        /// </summary>\r
+        /// <param name="n1">The number to fine the inverse hyperbolic tan of</param>\r
+        public static BigFloat Arctanh(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Arctanh();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Two-variable iterative square root, taken from\r
+        /// http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#A_two-variable_iterative_method\r
+        /// </summary>\r
+        /// <remarks>This is quite a fast function, as elementary functions go. You can expect it to take\r
+        /// about twice as long as a floating-point division.\r
+        /// </remarks>\r
+        public static BigFloat Sqrt(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Sqrt();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The natural logarithm, ln(x) (log base e)\r
+        /// </summary>\r
+        /// <remarks>This is a very slow function, despite repeated attempts at optimisation.\r
+        /// To make it any faster, different strategies would be needed for integer operations.\r
+        /// It does, however, scale well with the number of bits.\r
+        /// </remarks>\r
+        /// <param name="n1">The number to find the natural logarithm of</param>\r
+        public static BigFloat Log(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Log();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Base 10 logarithm of a number\r
+        /// </summary>\r
+        /// <remarks>This is a very slow function, despite repeated attempts at optimisation.\r
+        /// To make it any faster, different strategies would be needed for integer operations.\r
+        /// It does, however, scale well with the number of bits.\r
+        /// </remarks>\r
+        /// <param name="n1">The number to find the base 10 logarithm of</param>\r
+        public static BigFloat Log10(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Log10();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The exponential function. Less accurate for high exponents, scales poorly with the number\r
+        /// of bits. This is quite fast for low-precision arguments.\r
+        /// </summary>\r
+        public static BigFloat Exp(BigFloat n1)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Exp();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Raises a number to an integer power (positive or negative). This is a very accurate and fast function,\r
+        /// comparable to or faster than division (although it is slightly slower for\r
+        /// negative powers, obviously).\r
+        /// </summary>\r
+        /// <param name="n1">The number to raise to the power</param>\r
+        /// <param name="power">The power to raise it to</param>\r
+        public static BigFloat Pow(BigFloat n1, int power)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Pow(power);\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Raises to an aribitrary power. This is both slow (uses Log) and inaccurate. If you need to\r
+        /// raise e^x use exp(). If you need an integer power, use the integer power function Pow(int)\r
+        /// </summary>\r
+        /// <remarks>\r
+        /// Accuracy Note:\r
+        ///    The function is only ever accurate to a maximum of 4 decimal digits\r
+        ///    For every 10x larger (or smaller) the power gets, you lose an additional decimal digit\r
+        ///    If you really need a precise result, do the calculation with an extra 32-bits and round\r
+        ///    \r
+        /// Domain Note:\r
+        ///    This only works for powers of positive real numbers. Negative numbers will fail.\r
+        /// </remarks>\r
+        /// <param name="n1">The number to raise to a power</param>\r
+        /// <param name="power">The power to raise it to</param>\r
+        public static BigFloat Pow(BigFloat n1, BigFloat power)\r
+        {\r
+            BigFloat res = new BigFloat(n1);\r
+            n1.Pow(power);\r
+            return n1;\r
+        }\r
+\r
+        //********************** Static functions **********************\r
+\r
+        /// <summary>\r
+        /// Adds two numbers and returns the result\r
+        /// </summary>\r
+        public static BigFloat Add(BigFloat n1, BigFloat n2)\r
+        {\r
+            BigFloat ret = new BigFloat(n1);\r
+            ret.Add(n2);\r
+            return ret;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Subtracts two numbers and returns the result\r
+        /// </summary>\r
+        public static BigFloat Sub(BigFloat n1, BigFloat n2)\r
+        {\r
+            BigFloat ret = new BigFloat(n1);\r
+            ret.Sub(n2);\r
+            return ret;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Multiplies two numbers and returns the result\r
+        /// </summary>\r
+        public static BigFloat Mul(BigFloat n1, BigFloat n2)\r
+        {\r
+            BigFloat ret = new BigFloat(n1);\r
+            ret.Mul(n2);\r
+            return ret;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Divides two numbers and returns the result\r
+        /// </summary>\r
+        public static BigFloat Div(BigFloat n1, BigFloat n2)\r
+        {\r
+            BigFloat ret = new BigFloat(n1);\r
+            ret.Div(n2);\r
+            return ret;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Tests whether n1 is greater than n2\r
+        /// </summary>\r
+        public static bool GreaterThan(BigFloat n1, BigFloat n2)\r
+        {\r
+            return n1.GreaterThan(n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Tests whether n1 is less than n2\r
+        /// </summary>\r
+        public static bool LessThan(BigFloat n1, BigFloat n2)\r
+        {\r
+            return n1.LessThan(n2);\r
+        }\r
+\r
+\r
+        //******************* Fast static functions ********************\r
+\r
+        /// <summary>\r
+        /// Adds two numbers and assigns the result to res.\r
+        /// </summary>\r
+        /// <param name="res">a pre-existing BigFloat to take the result</param>\r
+        /// <param name="n1">the first number</param>\r
+        /// <param name="n2">the second number</param>\r
+        /// <returns>a handle to res</returns>\r
+        public static BigFloat Add(BigFloat res, BigFloat n1, BigFloat n2)\r
+        {\r
+            res.Assign(n1);\r
+            res.Add(n2);\r
+            return res;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Subtracts two numbers and assigns the result to res.\r
+        /// </summary>\r
+        /// <param name="res">a pre-existing BigFloat to take the result</param>\r
+        /// <param name="n1">the first number</param>\r
+        /// <param name="n2">the second number</param>\r
+        /// <returns>a handle to res</returns>\r
+        public static BigFloat Sub(BigFloat res, BigFloat n1, BigFloat n2)\r
+        {\r
+            res.Assign(n1);\r
+            res.Sub(n2);\r
+            return res;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Multiplies two numbers and assigns the result to res.\r
+        /// </summary>\r
+        /// <param name="res">a pre-existing BigFloat to take the result</param>\r
+        /// <param name="n1">the first number</param>\r
+        /// <param name="n2">the second number</param>\r
+        /// <returns>a handle to res</returns>\r
+        public static BigFloat Mul(BigFloat res, BigFloat n1, BigFloat n2)\r
+        {\r
+            res.Assign(n1);\r
+            res.Mul(n2);\r
+            return res;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Divides two numbers and assigns the result to res.\r
+        /// </summary>\r
+        /// <param name="res">a pre-existing BigFloat to take the result</param>\r
+        /// <param name="n1">the first number</param>\r
+        /// <param name="n2">the second number</param>\r
+        /// <returns>a handle to res</returns>\r
+        public static BigFloat Div(BigFloat res, BigFloat n1, BigFloat n2)\r
+        {\r
+            res.Assign(n1);\r
+            res.Div(n2);\r
+            return res;\r
+        }\r
+\r
+\r
+        //************************* Operators **************************\r
+\r
+        /// <summary>\r
+        /// The addition operator\r
+        /// </summary>\r
+        public static BigFloat operator +(BigFloat n1, BigFloat n2)\r
+        {\r
+            return Add(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The subtraction operator\r
+        /// </summary>\r
+        public static BigFloat operator -(BigFloat n1, BigFloat n2)\r
+        {\r
+            return Sub(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The multiplication operator\r
+        /// </summary>\r
+        public static BigFloat operator *(BigFloat n1, BigFloat n2)\r
+        {\r
+            return Mul(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The division operator\r
+        /// </summary>\r
+        public static BigFloat operator /(BigFloat n1, BigFloat n2)\r
+        {\r
+            return Div(n1, n2);\r
+        }\r
+\r
+        //************************** Conversions *************************\r
+\r
+        /// <summary>\r
+        /// Converts a BigFloat to an BigInt with the specified precision\r
+        /// </summary>\r
+        /// <param name="n1">The number to convert</param>\r
+        /// <param name="precision">The precision to convert it with</param>\r
+        /// <param name="round">Do we round the number if we are truncating the mantissa?</param>\r
+        /// <returns></returns>\r
+        public static BigInt ConvertToInt(BigFloat n1, PrecisionSpec precision, bool round)\r
+        {\r
+            BigInt ret = new BigInt(precision);\r
+\r
+            int numBits = n1.mantissa.Precision.NumBits;\r
+            int shift = numBits - (n1.exponent + 1);\r
+\r
+            BigFloat copy = new BigFloat(n1);\r
+            bool inc = false;\r
+\r
+            //Rounding\r
+            if (copy.mantissa.Precision.NumBits > ret.Precision.NumBits)\r
+            {\r
+                inc = true;\r
+\r
+                for (int i = copy.exponent + 1; i <= ret.Precision.NumBits; i++)\r
+                {\r
+                    if (copy.mantissa.GetBitFromTop(i) == 0)\r
+                    {\r
+                        inc = false;\r
+                        break;\r
+                    }\r
+                }\r
+            }\r
+\r
+            if (shift > 0)\r
+            {\r
+                copy.mantissa.RSH(shift);\r
+            }\r
+            else if (shift < 0)\r
+            {\r
+                copy.mantissa.LSH(-shift);\r
+            }\r
+\r
+            ret.Assign(copy.mantissa);\r
+\r
+            if (inc) ret.Increment();\r
+\r
+            return ret;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Returns a base-10 string representing the number.\r
+        /// \r
+        /// Note: This is inefficient and possibly inaccurate. Please use with enough\r
+        /// rounding digits (set using the RoundingDigits property) to ensure accuracy\r
+        /// </summary>\r
+        public override string ToString()\r
+        {\r
+            if (IsSpecialValue)\r
+            {\r
+                SpecialValueType s = SpecialValue;\r
+                if (s == SpecialValueType.ZERO)\r
+                {\r
+                    return String.Format("0{0}0", System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);\r
+                }\r
+                else if (s == SpecialValueType.INF_PLUS)\r
+                {\r
+                    return System.Globalization.CultureInfo.CurrentCulture.NumberFormat.PositiveInfinitySymbol;\r
+                }\r
+                else if (s == SpecialValueType.INF_MINUS)\r
+                {\r
+                    return System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NegativeInfinitySymbol;\r
+                }\r
+                else if (s == SpecialValueType.NAN)\r
+                {\r
+                    return System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NaNSymbol;\r
+                }\r
+                else\r
+                {\r
+                    return "Unrecognised special type";\r
+                }\r
+            }\r
+\r
+            if (scratch.Precision.NumBits != mantissa.Precision.NumBits)\r
+            {\r
+                scratch = new BigInt(mantissa.Precision);\r
+            }\r
+\r
+            //The mantissa expresses 1.xxxxxxxxxxx\r
+            //The highest possible value for the mantissa without the implicit 1. is 0.9999999...\r
+            scratch.Assign(mantissa);\r
+            //scratch.Round(3);\r
+            scratch.Sign = false;\r
+            BigInt denom = new BigInt("0", mantissa.Precision);\r
+            denom.SetBit(mantissa.Precision.NumBits - 1);\r
+\r
+            bool useExponentialNotation = false;\r
+            int halfBits = mantissa.Precision.NumBits / 2;\r
+            if (halfBits > 60) halfBits = 60;\r
+            int precDec = 10;\r
+\r
+            if (exponent > 0)\r
+            {\r
+                if (exponent < halfBits)\r
+                {\r
+                    denom.RSH(exponent);\r
+                }\r
+                else\r
+                {\r
+                    useExponentialNotation = true;\r
+                }\r
+            }\r
+            else if (exponent < 0)\r
+            {\r
+                int shift = -(exponent);\r
+                if (shift < precDec)\r
+                {\r
+                    scratch.RSH(shift);\r
+                }\r
+                else\r
+                {\r
+                    useExponentialNotation = true;\r
+                }\r
+            }\r
+\r
+            string output;\r
+\r
+            if (useExponentialNotation)\r
+            {\r
+                int absExponent = exponent;\r
+                if (absExponent < 0) absExponent = -absExponent;\r
+                int powerOf10 = (int)((double)absExponent * Math.Log10(2.0));\r
+\r
+                //Use 1 extra digit of precision (this is actually 32 bits more, nb)\r
+                BigFloat thisFloat = new BigFloat(this, new PrecisionSpec(mantissa.Precision.NumBits + 1, PrecisionSpec.BaseType.BIN));\r
+                thisFloat.mantissa.Sign = false;\r
+\r
+                //Multiplicative correction factor to bring number into range.\r
+                BigFloat one = new BigFloat(1, new PrecisionSpec(mantissa.Precision.NumBits + 1, PrecisionSpec.BaseType.BIN));\r
+                BigFloat ten = new BigFloat(10, new PrecisionSpec(mantissa.Precision.NumBits + 1, PrecisionSpec.BaseType.BIN));\r
+                BigFloat tenRCP = ten.Reciprocal();\r
+\r
+                //Accumulator for the power of 10 calculation.\r
+                BigFloat acc = new BigFloat(1, new PrecisionSpec(mantissa.Precision.NumBits + 1, PrecisionSpec.BaseType.BIN));\r
+\r
+                BigFloat tenToUse;\r
+\r
+                if (exponent > 0)\r
+                {\r
+                    tenToUse = new BigFloat(tenRCP, new PrecisionSpec(mantissa.Precision.NumBits + 1, PrecisionSpec.BaseType.BIN));\r
+                }\r
+                else\r
+                {\r
+                    tenToUse = new BigFloat(ten, new PrecisionSpec(mantissa.Precision.NumBits + 1, PrecisionSpec.BaseType.BIN));\r
+                }\r
+\r
+                BigFloat tenToPower = new BigFloat(1, new PrecisionSpec(mantissa.Precision.NumBits + 1, PrecisionSpec.BaseType.BIN));\r
+\r
+                int powerTemp = powerOf10;\r
+\r
+                //Fast power function\r
+                while (powerTemp != 0)\r
+                {\r
+                    tenToPower.Mul(tenToUse);\r
+                    tenToUse.Assign(tenToPower);\r
+\r
+                    if ((powerTemp & 1) != 0)\r
+                    {\r
+                        acc.Mul(tenToPower);\r
+                    }\r
+\r
+                    powerTemp >>= 1;\r
+                }\r
+\r
+                thisFloat.Mul(acc);\r
+\r
+                //If we are out of range, correct.           \r
+                if (thisFloat.GreaterThan(ten))\r
+                {\r
+                    thisFloat.Mul(tenRCP);\r
+                    if (exponent > 0)\r
+                    {\r
+                        powerOf10++;\r
+                    }\r
+                    else\r
+                    {\r
+                        powerOf10--;\r
+                    }\r
+                }\r
+                else if (thisFloat.LessThan(one))\r
+                {\r
+                    thisFloat.Mul(ten);\r
+                    if (exponent > 0)\r
+                    {\r
+                        powerOf10--;\r
+                    }\r
+                    else\r
+                    {\r
+                        powerOf10++;\r
+                    }\r
+                }\r
+\r
+                //Restore the precision and the sign.\r
+                BigFloat printable = new BigFloat(thisFloat, mantissa.Precision);\r
+                printable.mantissa.Sign = mantissa.Sign;\r
+                output = printable.ToString();\r
+\r
+                if (exponent < 0) powerOf10 = -powerOf10;\r
+\r
+                output = String.Format("{0}E{1}", output, powerOf10);\r
+            }\r
+            else\r
+            {\r
+                BigInt bigDigit = BigInt.Div(scratch, denom);\r
+                bigDigit.Sign = false;\r
+                scratch.Sub(BigInt.Mul(denom, bigDigit));\r
+\r
+                if (mantissa.Sign)\r
+                {\r
+                    output = String.Format("-{0}.", bigDigit);\r
+                }\r
+                else\r
+                {\r
+                    output = String.Format("{0}.", bigDigit);\r
+                }\r
+\r
+                denom = BigInt.Div(denom, 10u);\r
+\r
+                while (!denom.IsZero())\r
+                {\r
+                    uint digit = (uint)BigInt.Div(scratch, denom);\r
+                    if (digit == 10) digit--;\r
+                    scratch.Sub(BigInt.Mul(denom, digit));\r
+                    output = String.Format("{0}{1}", output, digit);\r
+                    denom = BigInt.Div(denom, 10u);\r
+                }\r
+\r
+                output = RoundString(output, RoundingDigits);\r
+            }\r
+\r
+            return output;\r
+        }\r
+\r
+        //**************** Special value handling for ops ***************\r
+\r
+        private void SetNaN()\r
+        {\r
+            exponent = Int32.MaxValue;\r
+            mantissa.SetBit(mantissa.Precision.NumBits - 1);\r
+        }\r
+\r
+        private void SetZero()\r
+        {\r
+            exponent = 0;\r
+            mantissa.Zero();\r
+            Sign = false;\r
+        }\r
+\r
+        private void SetInfPlus()\r
+        {\r
+            Sign = false;\r
+            exponent = Int32.MaxValue;\r
+            mantissa.Zero();\r
+        }\r
+\r
+        private void SetInfMinus()\r
+        {\r
+            Sign = true;\r
+            exponent = Int32.MaxValue;\r
+            mantissa.Zero();\r
+        }\r
+\r
+        private bool SpecialValueAddTest(BigFloat n2)\r
+        {\r
+            if (IsSpecialValue || n2.IsSpecialValue)\r
+            {\r
+                SpecialValueType s1 = SpecialValue;\r
+                SpecialValueType s2 = n2.SpecialValue;\r
+\r
+                if (s1 == SpecialValueType.NAN) return true;\r
+                if (s2 == SpecialValueType.NAN)\r
+                {\r
+                    //Set NaN and return.\r
+                    SetNaN();\r
+                    return true;\r
+                }\r
+\r
+                if (s1 == SpecialValueType.INF_PLUS)\r
+                {\r
+                    //INF+ + INF- = NAN\r
+                    if (s2 == SpecialValueType.INF_MINUS)\r
+                    {\r
+                        SetNaN();\r
+                        return true;\r
+                    }\r
+\r
+                    return true;\r
+                }\r
+\r
+                if (s1 == SpecialValueType.INF_MINUS)\r
+                {\r
+                    //INF+ + INF- = NAN\r
+                    if (s2 == SpecialValueType.INF_PLUS)\r
+                    {\r
+                        SetNaN();\r
+                        return true;\r
+                    }\r
+\r
+                    return true;\r
+                }\r
+\r
+                if (s2 == SpecialValueType.ZERO)\r
+                {\r
+                    return true;\r
+                }\r
+\r
+                if (s1 == SpecialValueType.ZERO)\r
+                {\r
+                    Assign(n2);\r
+                    return true;\r
+                }\r
+            }\r
+\r
+            return false;\r
+        }\r
+\r
+        private bool SpecialValueMulTest(BigFloat n2)\r
+        {\r
+            if (IsSpecialValue || n2.IsSpecialValue)\r
+            {\r
+                SpecialValueType s1 = SpecialValue;\r
+                SpecialValueType s2 = n2.SpecialValue;\r
+\r
+                if (s1 == SpecialValueType.NAN) return true;\r
+                if (s2 == SpecialValueType.NAN)\r
+                {\r
+                    //Set NaN and return.\r
+                    SetNaN();\r
+                    return true;\r
+                }\r
+\r
+                if (s1 == SpecialValueType.INF_PLUS)\r
+                {\r
+                    //Inf+ * Inf- = Inf-\r
+                    if (s2 == SpecialValueType.INF_MINUS)\r
+                    {\r
+                        Assign(n2);\r
+                        return true;\r
+                    }\r
+\r
+                    //Inf+ * 0 = NaN\r
+                    if (s2 == SpecialValueType.ZERO)\r
+                    {\r
+                        //Set NaN and return.\r
+                        SetNaN();\r
+                        return true;\r
+                    }\r
+\r
+                    return true;\r
+                }\r
+\r
+                if (s1 == SpecialValueType.INF_MINUS)\r
+                {\r
+                    //Inf- * Inf- = Inf+\r
+                    if (s2 == SpecialValueType.INF_MINUS)\r
+                    {\r
+                        Sign = false;\r
+                        return true;\r
+                    }\r
+\r
+                    //Inf- * 0 = NaN\r
+                    if (s2 == SpecialValueType.ZERO)\r
+                    {\r
+                        //Set NaN and return.\r
+                        SetNaN();\r
+                        return true;\r
+                    }\r
+\r
+                    return true;\r
+                }\r
+\r
+                if (s2 == SpecialValueType.ZERO)\r
+                {\r
+                    SetZero();\r
+                    return true;\r
+                }\r
+\r
+                if (s1 == SpecialValueType.ZERO)\r
+                {\r
+                    return true;\r
+                }\r
+            }\r
+\r
+            return false;\r
+        }\r
+\r
+        private bool SpecialValueDivTest(BigFloat n2)\r
+        {\r
+            if (IsSpecialValue || n2.IsSpecialValue)\r
+            {\r
+                SpecialValueType s1 = SpecialValue;\r
+                SpecialValueType s2 = n2.SpecialValue;\r
+\r
+                if (s1 == SpecialValueType.NAN) return true;\r
+                if (s2 == SpecialValueType.NAN)\r
+                {\r
+                    //Set NaN and return.\r
+                    SetNaN();\r
+                    return true;\r
+                }\r
+\r
+                if ((s1 == SpecialValueType.INF_PLUS || s1 == SpecialValueType.INF_MINUS))\r
+                {\r
+                    if (s2 == SpecialValueType.INF_PLUS || s2 == SpecialValueType.INF_MINUS)\r
+                    {\r
+                        //Set NaN and return.\r
+                        SetNaN();\r
+                        return true;\r
+                    }\r
+\r
+                    if (n2.Sign)\r
+                    {\r
+                        if (s1 == SpecialValueType.INF_PLUS)\r
+                        {\r
+                            SetInfMinus();\r
+                            return true;\r
+                        }\r
+\r
+                        SetInfPlus();\r
+                        return true;\r
+                    }\r
+\r
+                    //Keep inf\r
+                    return true;\r
+                }\r
+\r
+                if (s2 == SpecialValueType.ZERO)\r
+                {\r
+                    if (s1 == SpecialValueType.ZERO)\r
+                    {\r
+                        SetNaN();\r
+                        return true;\r
+                    }\r
+\r
+                    if (Sign)\r
+                    {\r
+                        SetInfMinus();\r
+                        return true;\r
+                    }\r
+\r
+                    SetInfPlus();\r
+                    return true;\r
+                }\r
+            }\r
+\r
+            return false;\r
+        }\r
+\r
+        //****************** Internal helper functions *****************\r
+\r
+        /// <summary>\r
+        /// Used for fixed point speed-ups (where the extra precision is not required). Note that Denormalised\r
+        /// floats break the assumptions that underly Add() and Sub(), so they can only be used for multiplication\r
+        /// </summary>\r
+        /// <param name="targetExponent"></param>\r
+        private void Denormalise(int targetExponent)\r
+        {\r
+            int diff = targetExponent - exponent;\r
+            if (diff <= 0) return;\r
+\r
+            //This only works to reduce the precision, so if the difference implies an increase, we can't do anything.\r
+            mantissa.RSH(diff);\r
+            exponent += diff;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The binary logarithm, log2(x) - for precisions above 1000 bits, use Log() and convert the base.\r
+        /// </summary>\r
+        private void Log2()\r
+        {\r
+            if (scratch.Precision.NumBits != mantissa.Precision.NumBits)\r
+            {\r
+                scratch = new BigInt(mantissa.Precision);\r
+            }\r
+\r
+            int bits = mantissa.Precision.NumBits;\r
+            BigFloat temp = new BigFloat(this);\r
+            BigFloat result = new BigFloat(exponent, mantissa.Precision);\r
+            BigFloat pow2 = new BigFloat(1, mantissa.Precision);\r
+            temp.exponent = 0;\r
+            int bitsCalculated = 0;\r
+\r
+            while (bitsCalculated < bits)\r
+            {\r
+                int i;\r
+                for (i = 0; (temp.exponent == 0); i++)\r
+                {\r
+                    temp.mantissa.SquareHiFast(scratch);\r
+                    int shift = temp.mantissa.Normalise();\r
+                    temp.exponent += 1 - shift;\r
+                    if (i + bitsCalculated >= bits) break;\r
+                }\r
+\r
+                pow2.MulPow2(-i);\r
+                result.Add(pow2);\r
+                temp.exponent = 0;\r
+                bitsCalculated += i;\r
+            }\r
+\r
+            this.Assign(result);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Tried the newton method for logs, but the exponential function is too slow to do it.\r
+        /// </summary>\r
+        private void LogNewton()\r
+        {\r
+            if (mantissa.IsZero() || mantissa.Sign)\r
+            {\r
+                return;\r
+            }\r
+\r
+            //Compute ln2.\r
+            if (ln2cache == null || mantissa.Precision.NumBits > ln2cache.mantissa.Precision.NumBits)\r
+            {\r
+                CalculateLog2(mantissa.Precision.NumBits);\r
+            }\r
+\r
+            int numBits = mantissa.Precision.NumBits;\r
+\r
+            //Use inverse exp function with Newton's method.\r
+            BigFloat xn = new BigFloat(this);\r
+            BigFloat oldExponent = new BigFloat(xn.exponent, mantissa.Precision);\r
+            xn.exponent = 0;\r
+            this.exponent = 0;\r
+            //Hack to subtract 1\r
+            xn.mantissa.ClearBit(numBits - 1);\r
+            //x0 = (x - 1) * log2 - this is a straight line fit between log(1) = 0 and log(2) = ln2\r
+            xn.Mul(ln2cache);\r
+            //x0 = (x - 1) * log2 + C - this corrects for minimum error over the range.\r
+            xn.Add(logNewtonConstant);\r
+            BigFloat term = new BigFloat(mantissa.Precision);\r
+            BigFloat one = new BigFloat(1, mantissa.Precision);\r
+\r
+            int precision = 32;\r
+            int normalPrecision = mantissa.Precision.NumBits;\r
+\r
+            int iterations = 0;\r
+\r
+            while (true)\r
+            {\r
+                term.Assign(xn);\r
+                term.mantissa.Sign = true;\r
+                term.Exp(precision);\r
+                term.Mul(this);\r
+                term.Sub(one);\r
+\r
+                iterations++;\r
+                if (term.exponent < -((precision >> 1) - 4))\r
+                {\r
+                    if (precision == normalPrecision)\r
+                    {\r
+                        if (term.exponent < -(precision - 4)) break;\r
+                    }\r
+                    else\r
+                    {\r
+                        precision = precision << 1;\r
+                        if (precision > normalPrecision) precision = normalPrecision;\r
+                    }\r
+                }\r
+\r
+                xn.Add(term);\r
+            }\r
+\r
+            //log(2^n*s) = log(2^n) + log(s) = nlog(2) + log(s)\r
+            term.Assign(ln2cache);\r
+            term.Mul(oldExponent);\r
+\r
+            this.Assign(xn);\r
+            this.Add(term);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Log(x) implemented as an Arithmetic-Geometric Mean. Fast for high precisions.\r
+        /// </summary>\r
+        private void LogAGM1()\r
+        {\r
+            if (mantissa.IsZero() || mantissa.Sign)\r
+            {\r
+                return;\r
+            }\r
+\r
+            //Compute ln2.\r
+            if (ln2cache == null || mantissa.Precision.NumBits > ln2cache.mantissa.Precision.NumBits)\r
+            {\r
+                CalculateLog2(mantissa.Precision.NumBits);\r
+            }\r
+\r
+            //Compute ln(x) using AGM formula\r
+\r
+            //1. Re-write the input as 2^n * (0.5 <= x < 1)\r
+            int power2 = exponent + 1;\r
+            exponent = -1;\r
+\r
+            //BigFloat res = new BigFloat(firstAGMcache);\r
+            BigFloat a0 = new BigFloat(1, mantissa.Precision);\r
+            BigFloat b0 = new BigFloat(pow10cache);\r
+            b0.Mul(this);\r
+\r
+            BigFloat r = R(a0, b0);\r
+\r
+            this.Assign(firstAGMcache);\r
+            this.Sub(r);\r
+\r
+            a0.Assign(ln2cache);\r
+            a0.Mul(new BigFloat(power2, mantissa.Precision));\r
+            this.Add(a0);\r
+        }\r
+\r
+        private void Exp(int numBits)\r
+        {\r
+            if (IsSpecialValue)\r
+            {\r
+                if (SpecialValue == SpecialValueType.ZERO)\r
+                {\r
+                    //e^0 = 1\r
+                    exponent = 0;\r
+                    mantissa.SetHighDigit(0x80000000);\r
+                }\r
+                else if (SpecialValue == SpecialValueType.INF_MINUS)\r
+                {\r
+                    //e^-inf = 0\r
+                    SetZero();\r
+                }\r
+\r
+                return;\r
+            }\r
+\r
+            PrecisionSpec prec = new PrecisionSpec(numBits, PrecisionSpec.BaseType.BIN);\r
+            numBits = prec.NumBits;\r
+\r
+            if (scratch.Precision.NumBits != prec.NumBits)\r
+            {\r
+                scratch = new BigInt(prec);\r
+            }\r
+\r
+            if (inverseFactorialCache == null || invFactorialCutoff < numBits)\r
+            {\r
+                CalculateFactorials(numBits);\r
+            }\r
+\r
+            //let x = 1 * 'this'.mantissa (i.e. 1 <= x < 2)\r
+            //exp(2^n * x) = e^(2^n * x) = (e^x)^2n = exp(x)^2n\r
+\r
+            int oldExponent = 0;\r
+\r
+            if (exponent > -4)\r
+            {\r
+                oldExponent = exponent + 4;\r
+                exponent = -4;\r
+            }\r
+\r
+            BigFloat thisSave = new BigFloat(this, prec);\r
+            BigFloat temp = new BigFloat(1, prec);\r
+            BigFloat temp2 = new BigFloat(this, prec);\r
+            BigFloat res = new BigFloat(1, prec);\r
+            int length = inverseFactorialCache.Length;\r
+\r
+            int iterations;\r
+            for (int i = 1; i < length; i++)\r
+            {\r
+                //temp = x^i\r
+                temp.Mul(thisSave);\r
+                temp2.Assign(inverseFactorialCache[i]);\r
+                temp2.Mul(temp);\r
+\r
+                if (temp2.exponent < -(numBits + 4)) { iterations = i; break; }\r
+\r
+                res.Add(temp2);\r
+            }\r
+\r
+            //res = exp(x)\r
+            //Now... x^(2^n) = (x^2)^(2^(n - 1))\r
+            for (int i = 0; i < oldExponent; i++)\r
+            {\r
+                res.mantissa.SquareHiFast(scratch);\r
+                int shift = res.mantissa.Normalise();\r
+                res.exponent = res.exponent << 1;\r
+                res.exponent += 1 - shift;\r
+            }\r
+\r
+            //Deal with +/- inf\r
+            if (res.exponent == Int32.MaxValue)\r
+            {\r
+                res.mantissa.Zero();\r
+            }\r
+\r
+            Assign(res);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates ln(2) and returns -10^(n/2 + a bit) for reuse, using the AGM method as described in\r
+        /// http://lacim.uqam.ca/~plouffe/articles/log2.pdf\r
+        /// </summary>\r
+        /// <param name="numBits"></param>\r
+        /// <returns></returns>\r
+        private static void CalculateLog2(int numBits)\r
+        {\r
+            //Use the AGM method formula to get log2 to N digits.\r
+            //R(a0, b0) = 1 / (1 - Sum(2^-n*(an^2 - bn^2)))\r
+            //log(1/2) = R(1, 10^-n) - R(1, 10^-n/2)\r
+            PrecisionSpec normalPres = new PrecisionSpec(numBits, PrecisionSpec.BaseType.BIN);\r
+            PrecisionSpec extendedPres = new PrecisionSpec(numBits + 1, PrecisionSpec.BaseType.BIN);\r
+            BigFloat a0 = new BigFloat(1, extendedPres);\r
+            BigFloat b0 = TenPow(-(int)((double)((numBits >> 1) + 2) * 0.302), extendedPres);\r
+            BigFloat pow10saved = new BigFloat(b0);\r
+            BigFloat firstAGMcacheSaved = new BigFloat(extendedPres);\r
+\r
+            //save power of 10 (in normal precision)\r
+            pow10cache = new BigFloat(b0, normalPres);\r
+\r
+            ln2cache = R(a0, b0);\r
+\r
+            //save the first half of the log calculation\r
+            firstAGMcache = new BigFloat(ln2cache, normalPres);\r
+            firstAGMcacheSaved.Assign(ln2cache);\r
+\r
+            b0.MulPow2(-1);\r
+            ln2cache.Sub(R(a0, b0));\r
+\r
+            //Convert to log(2)\r
+            ln2cache.mantissa.Sign = false;\r
+\r
+            //Save magic constant for newton log\r
+            //First guess in range 1 <= x < 2 is x0 = ln2 * (x - 1) + C\r
+            logNewtonConstant = new BigFloat(ln2cache);\r
+            logNewtonConstant.Mul(new BigFloat(3, extendedPres));\r
+            logNewtonConstant.exponent--;\r
+            logNewtonConstant.Sub(new BigFloat(1, extendedPres));\r
+            logNewtonConstant = new BigFloat(logNewtonConstant, normalPres);\r
+\r
+            //Save the inverse.\r
+            log2ecache = new BigFloat(ln2cache);\r
+            log2ecache = new BigFloat(log2ecache.Reciprocal(), normalPres);\r
+\r
+            //Now cache log10\r
+            //Because the log functions call this function to the precision to which they\r
+            //are called, we cannot call them without causing an infinite loop, so we need\r
+            //to inline the code.\r
+            log10recip = new BigFloat(10, extendedPres);\r
+\r
+            {\r
+                int power2 = log10recip.exponent + 1;\r
+                log10recip.exponent = -1;\r
+\r
+                //BigFloat res = new BigFloat(firstAGMcache);\r
+                BigFloat ax = new BigFloat(1, extendedPres);\r
+                BigFloat bx = new BigFloat(pow10saved);\r
+                bx.Mul(log10recip);\r
+\r
+                BigFloat r = R(ax, bx);\r
+\r
+                log10recip.Assign(firstAGMcacheSaved);\r
+                log10recip.Sub(r);\r
+\r
+                ax.Assign(ln2cache);\r
+                ax.Mul(new BigFloat(power2, log10recip.mantissa.Precision));\r
+                log10recip.Add(ax);\r
+            }\r
+\r
+            log10recip = log10recip.Reciprocal();\r
+            log10recip = new BigFloat(log10recip, normalPres);\r
+\r
+\r
+            //Trim to n bits\r
+            ln2cache = new BigFloat(ln2cache, normalPres);\r
+        }\r
+\r
+        private static BigFloat TenPow(int power, PrecisionSpec precision)\r
+        {\r
+            BigFloat acc = new BigFloat(1, precision);\r
+            BigFloat temp = new BigFloat(1, precision);\r
+\r
+            int powerTemp = power;\r
+\r
+            BigFloat multiplierToUse = new BigFloat(10, precision);\r
+\r
+            if (power < 0)\r
+            {\r
+                multiplierToUse = multiplierToUse.Reciprocal();\r
+                powerTemp = -power;\r
+            }\r
+\r
+            //Fast power function\r
+            while (powerTemp != 0)\r
+            {\r
+                temp.Mul(multiplierToUse);\r
+                multiplierToUse.Assign(temp);\r
+\r
+                if ((powerTemp & 1) != 0)\r
+                {\r
+                    acc.Mul(temp);\r
+                }\r
+\r
+                powerTemp >>= 1;\r
+            }\r
+\r
+            return acc;\r
+        }\r
+\r
+        private static BigFloat R(BigFloat a0, BigFloat b0)\r
+        {\r
+            //Precision extend taken out.\r
+            int bits = a0.mantissa.Precision.NumBits;\r
+            PrecisionSpec extendedPres = new PrecisionSpec(bits, PrecisionSpec.BaseType.BIN);\r
+            BigFloat an = new BigFloat(a0, extendedPres);\r
+            BigFloat bn = new BigFloat(b0, extendedPres);\r
+            BigFloat sum = new BigFloat(extendedPres);\r
+            BigFloat term = new BigFloat(extendedPres);\r
+            BigFloat temp1 = new BigFloat(extendedPres);\r
+            BigFloat one = new BigFloat(1, extendedPres);\r
+\r
+            int iteration = 0;\r
+\r
+            for (iteration = 0; ; iteration++)\r
+            {\r
+                //Get the sum term for this iteration.\r
+                term.Assign(an);\r
+                term.Mul(an);\r
+                temp1.Assign(bn);\r
+                temp1.Mul(bn);\r
+                //term = an^2 - bn^2\r
+                term.Sub(temp1);\r
+                //term = 2^(n-1) * (an^2 - bn^2)\r
+                term.exponent += iteration - 1;\r
+                sum.Add(term);\r
+\r
+                if (term.exponent < -(bits - 8)) break;\r
+\r
+                //Calculate the new AGM estimates.\r
+                temp1.Assign(an);\r
+                an.Add(bn);\r
+                //a(n+1) = (an + bn) / 2\r
+                an.MulPow2(-1);\r
+\r
+                //b(n+1) = sqrt(an*bn)\r
+                bn.Mul(temp1);\r
+                bn.Sqrt();\r
+            }\r
+\r
+            one.Sub(sum);\r
+            one = one.Reciprocal();\r
+            return new BigFloat(one, a0.mantissa.Precision);\r
+        }\r
+\r
+        private static void CalculateFactorials(int numBits)\r
+        {\r
+            System.Collections.Generic.List<BigFloat> list = new System.Collections.Generic.List<BigFloat>(64);\r
+            System.Collections.Generic.List<BigFloat> list2 = new System.Collections.Generic.List<BigFloat>(64);\r
+\r
+            PrecisionSpec extendedPrecision = new PrecisionSpec(numBits + 1, PrecisionSpec.BaseType.BIN);\r
+            PrecisionSpec normalPrecision = new PrecisionSpec(numBits, PrecisionSpec.BaseType.BIN);\r
+\r
+            BigFloat factorial = new BigFloat(1, extendedPrecision);\r
+            BigFloat reciprocal;\r
+\r
+            //Calculate e while we're at it\r
+            BigFloat e = new BigFloat(1, extendedPrecision);\r
+\r
+            list.Add(new BigFloat(factorial, normalPrecision));\r
+\r
+            for (int i = 1; i < Int32.MaxValue; i++)\r
+            {\r
+                BigFloat number = new BigFloat(i, extendedPrecision);\r
+                factorial.Mul(number);\r
+\r
+                if (factorial.exponent > numBits) break;\r
+\r
+                list2.Add(new BigFloat(factorial, normalPrecision));\r
+                reciprocal = factorial.Reciprocal();\r
+\r
+                e.Add(reciprocal);\r
+                list.Add(new BigFloat(reciprocal, normalPrecision));\r
+            }\r
+\r
+            //Set the cached static values.\r
+            inverseFactorialCache = list.ToArray();\r
+            factorialCache = list2.ToArray();\r
+            invFactorialCutoff = numBits;\r
+            eCache = new BigFloat(e, normalPrecision);\r
+            eRCPCache = new BigFloat(e.Reciprocal(), normalPrecision);\r
+        }\r
+\r
+        private static void CalculateEOnly(int numBits)\r
+        {\r
+            PrecisionSpec extendedPrecision = new PrecisionSpec(numBits + 1, PrecisionSpec.BaseType.BIN);\r
+            PrecisionSpec normalPrecision = new PrecisionSpec(numBits, PrecisionSpec.BaseType.BIN);\r
+\r
+            int iExponent = (int)(Math.Sqrt(numBits));\r
+\r
+            BigFloat factorial = new BigFloat(1, extendedPrecision);\r
+            BigFloat constant = new BigFloat(1, extendedPrecision);\r
+            constant.exponent -= iExponent;\r
+            BigFloat numerator = new BigFloat(constant);\r
+            BigFloat reciprocal;\r
+\r
+            //Calculate the 2^iExponent th root of e\r
+            BigFloat e = new BigFloat(1, extendedPrecision);\r
+\r
+            int i;\r
+            for (i = 1; i < Int32.MaxValue; i++)\r
+            {\r
+                BigFloat number = new BigFloat(i, extendedPrecision);\r
+                factorial.Mul(number);\r
+                reciprocal = factorial.Reciprocal();\r
+                reciprocal.Mul(numerator);\r
+\r
+                if (-reciprocal.exponent > numBits) break;\r
+\r
+                e.Add(reciprocal);\r
+                numerator.Mul(constant);\r
+                System.GC.Collect();\r
+            }\r
+\r
+            for (i = 0; i < iExponent; i++)\r
+            {\r
+                numerator.Assign(e);\r
+                e.Mul(numerator);\r
+            }\r
+\r
+            //Set the cached static values.\r
+            eCache = new BigFloat(e, normalPrecision);\r
+            eRCPCache = new BigFloat(e.Reciprocal(), normalPrecision);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Uses the Gauss-Legendre formula for pi\r
+        /// Taken from http://en.wikipedia.org/wiki/Gauss%E2%80%93Legendre_algorithm\r
+        /// </summary>\r
+        /// <param name="numBits"></param>\r
+        private static void CalculatePi(int numBits)\r
+        {\r
+            int bits = numBits + 32;\r
+            //Precision extend taken out.\r
+            PrecisionSpec normalPres = new PrecisionSpec(numBits, PrecisionSpec.BaseType.BIN);\r
+            PrecisionSpec extendedPres = new PrecisionSpec(bits, PrecisionSpec.BaseType.BIN);\r
+\r
+            if (scratch.Precision.NumBits != bits)\r
+            {\r
+                scratch = new BigInt(extendedPres);\r
+            }\r
+\r
+            //a0 = 1\r
+            BigFloat an = new BigFloat(1, extendedPres);\r
+\r
+            //b0 = 1/sqrt(2)\r
+            BigFloat bn = new BigFloat(2, extendedPres);\r
+            bn.Sqrt();\r
+            bn.exponent--;\r
+\r
+            //to = 1/4\r
+            BigFloat tn = new BigFloat(1, extendedPres);\r
+            tn.exponent -= 2;\r
+\r
+            int pn = 0;\r
+\r
+            BigFloat anTemp = new BigFloat(extendedPres);\r
+\r
+            int iteration = 0;\r
+            int cutoffBits = numBits >> 5;\r
+\r
+            for (iteration = 0; ; iteration++)\r
+            {\r
+                //Save a(n)\r
+                anTemp.Assign(an);\r
+\r
+                //Calculate new an\r
+                an.Add(bn);\r
+                an.exponent--;\r
+\r
+                //Calculate new bn\r
+                bn.Mul(anTemp);\r
+                bn.Sqrt();\r
+\r
+                //Calculate new tn\r
+                anTemp.Sub(an);\r
+                anTemp.mantissa.SquareHiFast(scratch);\r
+                anTemp.exponent += anTemp.exponent + pn + 1 - anTemp.mantissa.Normalise();\r
+                tn.Sub(anTemp);\r
+\r
+                anTemp.Assign(an);\r
+                anTemp.Sub(bn);\r
+\r
+                if (anTemp.exponent < -(bits - cutoffBits)) break;\r
+\r
+                //New pn\r
+                pn++;\r
+            }\r
+\r
+            an.Add(bn);\r
+            an.mantissa.SquareHiFast(scratch);\r
+            an.exponent += an.exponent + 1 - an.mantissa.Normalise();\r
+            tn.exponent += 2;\r
+            an.Div(tn);\r
+\r
+            pi = new BigFloat(an, normalPres);\r
+            piBy2 = new BigFloat(pi);\r
+            piBy2.exponent--;\r
+            twoPi = new BigFloat(pi, normalPres);\r
+            twoPi.exponent++;\r
+            piRecip = new BigFloat(an.Reciprocal(), normalPres);\r
+            twoPiRecip = new BigFloat(piRecip);\r
+            twoPiRecip.exponent--;\r
+            //1/3 is going to be useful for sin.\r
+            threeRecip = new BigFloat((new BigFloat(3, extendedPres)).Reciprocal(), normalPres);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates the odd reciprocals of the natural numbers (for atan series)\r
+        /// </summary>\r
+        /// <param name="numBits"></param>\r
+        /// <param name="terms"></param>\r
+        private static void CalculateReciprocals(int numBits, int terms)\r
+        {\r
+            int bits = numBits + 32;\r
+            PrecisionSpec extendedPres = new PrecisionSpec(bits, PrecisionSpec.BaseType.BIN);\r
+            PrecisionSpec normalPres = new PrecisionSpec(numBits, PrecisionSpec.BaseType.BIN);\r
+\r
+            System.Collections.Generic.List<BigFloat> list = new System.Collections.Generic.List<BigFloat>(terms);\r
+\r
+            for (int i = 0; i < terms; i++)\r
+            {\r
+                BigFloat term = new BigFloat(i*2 + 1, extendedPres);\r
+                list.Add(new BigFloat(term.Reciprocal(), normalPres));\r
+            }\r
+\r
+            reciprocals = list.ToArray();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Does decimal rounding, for numbers without E notation.\r
+        /// </summary>\r
+        /// <param name="input"></param>\r
+        /// <param name="places"></param>\r
+        /// <returns></returns>\r
+        private static string RoundString(string input, int places)\r
+        {\r
+            if (places <= 0) return input;\r
+            string trim = input.Trim();\r
+            char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};\r
+\r
+            /*\r
+            for (int i = 1; i <= places; i++)\r
+            {\r
+                //Skip decimal points.\r
+                if (trim[trim.Length - i] == '.')\r
+                {\r
+                    places++;\r
+                    continue;\r
+                }\r
+\r
+                int index = Array.IndexOf(digits, trim[trim.Length - i]);\r
+\r
+                if (index < 0) return input;\r
+\r
+                value += ten * index;\r
+                ten *= 10;\r
+            }\r
+             * */\r
+\r
+            //Look for a decimal point\r
+            string decimalPoint = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;\r
+\r
+            int indexPoint = trim.LastIndexOf(decimalPoint);\r
+            if (indexPoint < 0)\r
+            {\r
+                //We can't modify a string which doesn't have a decimal point.\r
+                return trim;\r
+            }\r
+\r
+            int trimPoint = trim.Length - places;\r
+            if (trimPoint < indexPoint) trimPoint = indexPoint;\r
+\r
+            bool roundDown = false;\r
+\r
+            if (trim[trimPoint] == '.')\r
+            {\r
+                if (trimPoint + 1 >= trim.Length)\r
+                {\r
+                    roundDown = true;\r
+                }\r
+                else\r
+                {\r
+                    int digit = Array.IndexOf(digits, trim[trimPoint + 1]);\r
+                    if (digit < 5) roundDown = true;\r
+                }\r
+            }\r
+            else\r
+            {\r
+                int digit = Array.IndexOf(digits, trim[trimPoint]);\r
+                if (digit < 5) roundDown = true;\r
+            }\r
+\r
+            string output;\r
+\r
+            //Round down - just return a new string without the extra digits.\r
+            if (roundDown)\r
+            {\r
+                if (RoundingMode == RoundingModeType.EXACT)\r
+                {\r
+                    return trim.Substring(0, trimPoint);\r
+                }\r
+                else\r
+                {\r
+                    char[] trimChars = { '0' };\r
+                    output = trim.Substring(0, trimPoint).TrimEnd(trimChars);\r
+                    trimChars[0] = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0];\r
+                    return output.TrimEnd(trimChars);\r
+                }\r
+            }\r
+            \r
+            //Round up - bit more complicated.\r
+            char [] arrayOutput = trim.ToCharArray();//0, trimPoint);\r
+\r
+            //Now, we round going from the back to the front.\r
+            int j;\r
+            for (j = trimPoint - 1; j >= 0; j--)\r
+            {\r
+                int index = Array.IndexOf(digits, arrayOutput[j]);\r
+\r
+                //Skip decimal points etc...\r
+                if (index < 0) continue;\r
+\r
+                if (index < 9)\r
+                {\r
+                    arrayOutput[j] = digits[index + 1];\r
+                    break;\r
+                }\r
+                else\r
+                {\r
+                    arrayOutput[j] = digits[0];\r
+                }\r
+            }\r
+\r
+            output = new string(arrayOutput);\r
+\r
+            if (j < 0)\r
+            {\r
+                //Need to add a new digit.\r
+                output = String.Format("{0}{1}", "1", output);\r
+            }\r
+\r
+            if (RoundingMode == RoundingModeType.EXACT)\r
+            {\r
+                return output;\r
+            }\r
+            else\r
+            {\r
+                char[] trimChars = { '0' };\r
+                output = output.TrimEnd(trimChars);\r
+                trimChars[0] = System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0];\r
+                return output.TrimEnd(trimChars);\r
+            }\r
+        }\r
+\r
+        //***************************** Data *****************************\r
+\r
+\r
+        //Side node - this way of doing things is far from optimal, both in terms of memory use and performance.\r
+        private ExponentAdaptor exponent;\r
+        private BigInt mantissa;\r
+\r
+        /// <summary>\r
+        /// Storage area for calculations.\r
+        /// </summary>\r
+        private static BigInt scratch;\r
+\r
+        private static BigFloat ln2cache;                 //Value of ln(2)\r
+        private static BigFloat log2ecache;               //Value of log2(e) = 1/ln(2)\r
+        private static BigFloat pow10cache;               //Cached power of 10 for AGM log calculation\r
+        private static BigFloat log10recip;               //1/ln(10)\r
+        private static BigFloat firstAGMcache;            //Cached half of AGM operation.\r
+        private static BigFloat[] factorialCache;         //The values of n!\r
+        private static BigFloat[] inverseFactorialCache;  //Values of 1/n! up to 2^-m where m = invFactorialCutoff (below)\r
+        private static int invFactorialCutoff;            //The number of significant bits for the cutoff of the inverse factorials.\r
+        private static BigFloat eCache;                   //Value of e cached to invFactorialCutoff bits\r
+        private static BigFloat eRCPCache;                //Reciprocal of e\r
+        private static BigFloat logNewtonConstant;        //1.5*ln(2) - 1\r
+        private static BigFloat pi;                       //pi\r
+        private static BigFloat piBy2;                    //pi/2\r
+        private static BigFloat twoPi;                    //2*pi\r
+        private static BigFloat piRecip;                  //1/pi\r
+        private static BigFloat twoPiRecip;               //1/2*pi\r
+        private static BigFloat threeRecip;               //1/3\r
+        private static BigFloat[] reciprocals;            //1/x\r
+        \r
+        /// <summary>\r
+        /// The number of decimal digits to round the output of ToString() by\r
+        /// </summary>\r
+        public static int RoundingDigits { get; set; }\r
+\r
+        /// <summary>\r
+        /// The way in which ToString() should deal with insignificant trailing zeroes\r
+        /// </summary>\r
+        public static RoundingModeType RoundingMode { get; set; }\r
+    }\r
+}
\ No newline at end of file
diff --git a/dev5/psychlops/extension/math/BigInt.cs b/dev5/psychlops/extension/math/BigInt.cs
new file mode 100644 (file)
index 0000000..56a484e
--- /dev/null
@@ -0,0 +1,2901 @@
+// http://www.fractal-landscapes.co.uk/bigint.html\r
+\r
+using System;\r
+\r
+namespace BigNum\r
+{\r
+    /// <summary>\r
+    /// Specifies the desired precision for a BigInt or a BigFloat. \r
+    /// </summary>\r
+    public struct PrecisionSpec\r
+    {\r
+        /// <summary>\r
+        /// Precision can be specified in a choice of 8 bases.\r
+        /// Note that precision for decimals is approximate.\r
+        /// </summary>\r
+        public enum BaseType\r
+        {\r
+            /// <summary>\r
+            /// Binary base\r
+            /// </summary>\r
+            BIN,\r
+            /// <summary>\r
+            /// Octal base\r
+            /// </summary>\r
+            OCT,\r
+            /// <summary>\r
+            /// Decimal base\r
+            /// </summary>\r
+            DEC,\r
+            /// <summary>\r
+            /// Hexadecimal base\r
+            /// </summary>\r
+            HEX,\r
+            /// <summary>\r
+            /// 8-bits per digit\r
+            /// </summary>\r
+            BYTES,\r
+            /// <summary>\r
+            /// 16-bits per digit\r
+            /// </summary>\r
+            WORDS,\r
+            /// <summary>\r
+            /// 32-bits per digit\r
+            /// </summary>\r
+            DWORDS,\r
+            /// <summary>\r
+            /// 64-bits per digit\r
+            /// </summary>\r
+            QWORDS\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructor: Constructs a precision specification\r
+        /// </summary>\r
+        /// <param name="precision">The number of digits</param>\r
+        /// <param name="numberBase">The base of the digits</param>\r
+        public PrecisionSpec(int precision, BaseType numberBase)\r
+        {\r
+            this.prec = precision;\r
+            this.nB = numberBase;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Explicit cast from integer value.\r
+        /// </summary>\r
+        /// <param name="value">The value in bits for the new precision specification</param>\r
+        /// <returns>A new precision specification with the number of bits specified</returns>\r
+        public static explicit operator PrecisionSpec(int value)\r
+        {\r
+            return new PrecisionSpec(value, BaseType.BIN);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Equality test\r
+        /// </summary>\r
+        /// <param name="spec1">the first parameter</param>\r
+        /// <param name="spec2">the second parameter</param>\r
+        /// <returns>true iff both precisions have the same number of bits</returns>\r
+        public static bool operator ==(PrecisionSpec spec1, PrecisionSpec spec2)\r
+        {\r
+            return (spec1.NumBits == spec2.NumBits);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Inequality operator\r
+        /// </summary>\r
+        /// <param name="spec1">the first parameter</param>\r
+        /// <param name="spec2">the second parameter</param>\r
+        /// <returns>true iff the parameters do not have the same number of bits</returns>\r
+        public static bool operator !=(PrecisionSpec spec1, PrecisionSpec spec2)\r
+        {\r
+            return !(spec1 == spec2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Object equality override\r
+        /// </summary>\r
+        /// <param name="obj">the PrecisionSpec struct to compare</param>\r
+        /// <returns>true iff obj has the same number of bits as this</returns>\r
+        public override bool Equals(object obj)\r
+        {\r
+            return NumBits == ((PrecisionSpec)obj).NumBits;     \r
+        }\r
+\r
+        /// <summary>\r
+        /// Override of the hash code\r
+        /// </summary>\r
+        /// <returns>A basic hash</returns>\r
+        public override int GetHashCode()\r
+        {\r
+            return NumBits * prec + NumBits;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The precision in units specified by the base type (e.g. number of decimal digits)\r
+        /// </summary>\r
+        public int Precision\r
+        {\r
+            get { return prec; }\r
+        }\r
+\r
+        /// <summary>\r
+        /// The base type in which precision is specified\r
+        /// </summary>\r
+        public BaseType NumberBaseType\r
+        {\r
+            get { return nB; }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Converts the number-base to an integer\r
+        /// </summary>\r
+        public int NumberBase\r
+        {\r
+            get { return (int)nB; }\r
+        }\r
+\r
+        /// <summary>\r
+        /// The number of bits that this PrecisionSpec structure specifies.\r
+        /// </summary>\r
+        public int NumBits\r
+        {\r
+            get\r
+            {\r
+                if (nB == BaseType.BIN) return prec;\r
+                if (nB == BaseType.OCT) return prec * 3;\r
+                if (nB == BaseType.HEX) return prec * 4;\r
+                if (nB == BaseType.BYTES) return prec * 8;\r
+                if (nB == BaseType.WORDS) return prec * 16;\r
+                if (nB == BaseType.DWORDS) return prec * 32;\r
+                if (nB == BaseType.QWORDS) return prec * 64;\r
+\r
+                double factor = 3.322;\r
+                int bits = ((int)Math.Ceiling(factor * (double)prec));\r
+                return bits;\r
+            }\r
+        }\r
+\r
+        private int prec;\r
+        private BaseType nB;\r
+    }\r
+\r
+    \r
+    /// <summary>\r
+    /// An arbitrary-precision integer class\r
+    /// \r
+    /// Format:\r
+    /// Each number consists of an array of 32-bit unsigned integers, and a bool sign\r
+    /// value.\r
+    /// \r
+    /// Applicability and Performance:\r
+    /// This class is designed to be used for small extended precisions. It may not be\r
+    /// safe (and certainly won't be fast) to use it with mixed-precision arguments.\r
+    /// It does support, but will not be efficient for, numbers over around 2048 bits.\r
+    /// \r
+    /// Notes:\r
+    /// All conversions to and from strings are slow.\r
+    /// \r
+    /// Conversions from simple integer types Int32, Int64, UInt32, UInt64 are performed\r
+    /// using the appropriate constructor, and are relatively fast.\r
+    /// \r
+    /// The class is written entirely in managed C# code, with not native or managed\r
+    /// assembler. The use of native assembler would speed up the multiplication operations\r
+    /// many times over, and therefore all higher-order operations too.\r
+    /// </summary>\r
+    public class BigInt\r
+    {\r
+        //*************** Constructors ******************\r
+\r
+        /// <summary>\r
+        /// Constructs an empty BigInt to the desired precision.\r
+        /// </summary>\r
+        /// <param name="precision"></param>\r
+        public BigInt(PrecisionSpec precision)\r
+        {\r
+            Init(precision);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigInt from a string, using the string length to determine the precision\r
+        /// Note, operations on BigInts of non-matching precision are slow, so avoid using this constructor\r
+        /// </summary>\r
+        /// <param name="init"></param>\r
+        public BigInt(string init)\r
+        {\r
+            InitFromString(init, (PrecisionSpec)init.Length, 10);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructor for copying length and precision\r
+        /// </summary>\r
+        /// <param name="inputToCopy">The BigInt to copy</param>\r
+        /// <param name="precision">The precision of the new BigInt</param>\r
+        /// <param name="bCopyLengthOnly">decides whether to copy the actual input, or just its digit length</param>\r
+        /// <example><code>//Create an integer\r
+        /// BigInt four = new BigInt(4, new PrecisionSpec(128, PrecisionSpec.BaseType.BIN));\r
+        /// \r
+        /// //Pad four to double its usual number of digits (this does not affect the precision)\r
+        /// four.Pad();\r
+        /// \r
+        /// //Create a new, empty integer with matching precision, also padded to twice the usual length\r
+        /// BigInt newCopy = new BigInt(four, four.Precision, true);</code></example>\r
+        public BigInt(BigInt inputToCopy, PrecisionSpec precision, bool bCopyLengthOnly)\r
+        {\r
+            digitArray = new uint[inputToCopy.digitArray.Length];\r
+            workingSet = new uint[inputToCopy.digitArray.Length];\r
+            if (!bCopyLengthOnly) Array.Copy(inputToCopy.digitArray, digitArray, digitArray.Length);\r
+            sign = inputToCopy.sign;\r
+            pres = inputToCopy.pres;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a bigint from the string, with the desired precision, using base 10\r
+        /// </summary>\r
+        /// <param name="init"></param>\r
+        /// <param name="precision"></param>\r
+        public BigInt(string init, PrecisionSpec precision)\r
+        {\r
+            InitFromString(init, precision, 10);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigInt from a string, using the specified precision and base\r
+        /// </summary>\r
+        /// <param name="init"></param>\r
+        /// <param name="precision"></param>\r
+        /// <param name="numberBase"></param>\r
+        public BigInt(string init, PrecisionSpec precision, int numberBase)\r
+        {\r
+            InitFromString(init, precision, numberBase);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a bigint from the input.\r
+        /// </summary>\r
+        /// <param name="input"></param>\r
+        public BigInt(BigInt input)\r
+        {\r
+            digitArray = new uint[input.digitArray.Length];\r
+            workingSet = new uint[input.digitArray.Length];\r
+            Array.Copy(input.digitArray, digitArray, digitArray.Length);\r
+            sign = input.sign;\r
+            pres = input.pres;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a bigint from the input, matching the new precision provided\r
+        /// </summary>\r
+        public BigInt(BigInt input, PrecisionSpec precision)\r
+        {\r
+            //Casts the input to the new precision.\r
+            Init(precision);\r
+            int Min = (input.digitArray.Length < digitArray.Length) ? input.digitArray.Length : digitArray.Length;\r
+\r
+            for (int i = 0; i < Min; i++)\r
+            {\r
+                digitArray[i] = input.digitArray[i];\r
+            }\r
+\r
+            sign = input.sign;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigInt from a UInt32\r
+        /// </summary>\r
+        /// <param name="input"></param>\r
+        /// <param name="precision"></param>\r
+        public BigInt(UInt32 input, PrecisionSpec precision)\r
+        {\r
+            Init(precision);\r
+            digitArray[0] = input;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigInt from a UInt64\r
+        /// </summary>\r
+        /// <param name="input"></param>\r
+        /// <param name="precision"></param>\r
+        public BigInt(UInt64 input, PrecisionSpec precision)\r
+        {\r
+            Init(precision);\r
+            digitArray[0] = (UInt32)(input & 0xffffffff);\r
+            if (digitArray.Length > 1) digitArray[1] = (UInt32)(input >> 32);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigInt from an Int32\r
+        /// </summary>\r
+        /// <param name="input"></param>\r
+        /// <param name="precision"></param>\r
+        public BigInt(Int32 input, PrecisionSpec precision)\r
+        {\r
+            Init(precision);\r
+            if (input < 0)\r
+            {\r
+                sign = true;\r
+\r
+                if (input == Int32.MinValue)\r
+                {\r
+                    digitArray[0] = 0x80000000;\r
+                }\r
+                else\r
+                {\r
+                    digitArray[0] = (UInt32)(-input);\r
+                }\r
+            }\r
+            else\r
+            {\r
+                digitArray[0] = ((UInt32)input);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Constructs a BigInt from a UInt32\r
+        /// </summary>\r
+        /// <param name="input"></param>\r
+        /// <param name="precision"></param>\r
+        public BigInt(Int64 input, PrecisionSpec precision)\r
+        {\r
+            Init(precision);\r
+            if (input < 0) sign = true;\r
+\r
+            digitArray[0] = (UInt32)(input & 0xffffffff);\r
+\r
+            if (digitArray.Length >= 2)\r
+            {\r
+                if (input == Int64.MinValue)\r
+                {\r
+                    digitArray[1] = 0x80000000;\r
+                }\r
+                else\r
+                {\r
+                    digitArray[1] = (UInt32)((input >> 32) & 0x7fffffff);\r
+                }\r
+            }\r
+        }\r
+\r
+        //***************** Properties *******************\r
+\r
+        /// <summary>\r
+        /// true iff the number is negative\r
+        /// </summary>\r
+        public bool Sign { get { return sign; } set { sign = value; } }\r
+\r
+        /// <summary>\r
+        /// The precision of the number.\r
+        /// </summary>\r
+        public PrecisionSpec Precision { get { return pres; } }\r
+\r
+        //*************** Utility Functions **************\r
+\r
+        /// <summary>\r
+        /// Casts a BigInt to the new precision provided.\r
+        /// Note: This will return the input if the precision already matches.\r
+        /// </summary>\r
+        /// <param name="input"></param>\r
+        /// <param name="precision"></param>\r
+        /// <returns></returns>\r
+        public static BigInt CastToPrecision(BigInt input, PrecisionSpec precision)\r
+        {\r
+            if (input.pres == precision) return input;\r
+            return new BigInt(input, precision);\r
+        }\r
+\r
+\r
+        //*************** Member Functions ***************\r
+\r
+        /// <summary>\r
+        /// Addition and assignment - without intermediate memory allocation.\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public uint Add(BigInt n2)\r
+        {\r
+            if (n2.digitArray.Length != digitArray.Length) MakeSafe(ref n2);\r
+\r
+            if (sign == n2.sign)\r
+            {\r
+                return AddInternalBits(n2.digitArray);\r
+            }\r
+            else\r
+            {\r
+                bool lessThan = LtInt(this, n2);\r
+\r
+                if (lessThan)\r
+                {\r
+                    int Length = digitArray.Length;\r
+\r
+                    for (int i = 0; i < Length; i++)\r
+                    {\r
+                        workingSet[i] = digitArray[i];\r
+                        digitArray[i] = n2.digitArray[i];\r
+                    }\r
+\r
+                    sign = !sign;\r
+                    return SubInternalBits(workingSet);\r
+                }\r
+                else\r
+                {\r
+                    return SubInternalBits(n2.digitArray);\r
+                }\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Subtraction and assignment - without intermediate memory allocation.\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        public uint Sub(BigInt n2)\r
+        {\r
+            if (n2.digitArray.Length != digitArray.Length) MakeSafe(ref n2);\r
+\r
+            if (sign != n2.sign)\r
+            {\r
+                return AddInternalBits(n2.digitArray);\r
+            }\r
+            else\r
+            {\r
+                bool lessThan = LtInt(this, n2);\r
+\r
+                if (lessThan)\r
+                {\r
+                    int Length = digitArray.Length;\r
+\r
+                    for (int i = 0; i < Length; i++)\r
+                    {\r
+                        workingSet[i] = digitArray[i];\r
+                        digitArray[i] = n2.digitArray[i];\r
+                    }\r
+\r
+                    sign = !sign;\r
+                    return SubInternalBits(workingSet);\r
+                }\r
+                else\r
+                {\r
+                    return SubInternalBits(n2.digitArray);\r
+                }\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Multiplication and assignmnet - with minimal intermediate memory allocation.\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        public void Mul(BigInt n2)\r
+        {\r
+            if (n2.digitArray.Length != digitArray.Length) MakeSafe(ref n2);\r
+\r
+            int Length = n2.digitArray.Length;\r
+\r
+            //Inner loop zero-mul avoidance\r
+            int maxDigit = 0;\r
+            for (int i = Length - 1; i >= 0; i--)\r
+            {\r
+                if (digitArray[i] != 0)\r
+                {\r
+                    maxDigit = i + 1;\r
+                    break;\r
+                }\r
+            }\r
+\r
+            //Result is zero, 'this' is unchanged\r
+            if (maxDigit == 0) return;\r
+\r
+            //Temp storage for source (both working sets are used by the calculation)\r
+            uint[] thisTemp = new uint [Length];\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                thisTemp[i] = digitArray[i];\r
+                digitArray[i] = 0;\r
+            }\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                //Clear the working set\r
+                for (int j = 0; j < i; j++)\r
+                {\r
+                    workingSet[j] = 0;\r
+                    n2.workingSet[j] = 0;\r
+                }\r
+\r
+                n2.workingSet[i] = 0;\r
+\r
+                ulong digit = n2.digitArray[i];\r
+                if (digit == 0) continue;\r
+\r
+                for (int j = 0; j + i < Length && j < maxDigit; j++)\r
+                {\r
+                    //Multiply n1 by each of the integer digits of n2.\r
+                    ulong temp = (ulong)thisTemp[j] * digit;\r
+                    //n1.workingSet stores the low bits of each piecewise multiplication\r
+                    workingSet[j + i] = (uint)(temp & 0xffffffff);\r
+                    if (j + i + 1 < Length)\r
+                    {\r
+                        //n2.workingSet stores the high bits of each multiplication\r
+                        n2.workingSet[j + i + 1] = (uint)(temp >> 32);\r
+                    }\r
+                }\r
+\r
+                AddInternalBits(workingSet);\r
+                AddInternalBits(n2.workingSet);\r
+            }\r
+\r
+            sign = (sign != n2.sign);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Squares the number.\r
+        /// </summary>\r
+        public void Square()\r
+        {\r
+            int Length = digitArray.Length;\r
+\r
+            //Inner loop zero-mul avoidance\r
+            int maxDigit = 0;\r
+            for (int i = Length - 1; i >= 0; i--)\r
+            {\r
+                if (digitArray[i] != 0)\r
+                {\r
+                    maxDigit = i + 1;\r
+                    break;\r
+                }\r
+            }\r
+\r
+            //Result is zero, 'this' is unchanged\r
+            if (maxDigit == 0) return;\r
+\r
+            //Temp storage for source (both working sets are used by the calculation)\r
+            uint[] thisTemp = new uint[Length];\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                thisTemp[i] = digitArray[i];\r
+                digitArray[i] = 0;\r
+            }\r
+\r
+            UInt32 [] workingSet2 = new UInt32[Length];\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                //Clear the working set\r
+                for (int j = 0; j < i; j++)\r
+                {\r
+                    workingSet[j] = 0;\r
+                    workingSet2[j] = 0;\r
+                }\r
+\r
+                workingSet2[i] = 0;\r
+\r
+                ulong digit = thisTemp[i];\r
+                if (digit == 0) continue;\r
+\r
+                for (int j = 0; j + i < Length && j < maxDigit; j++)\r
+                {\r
+                    //Multiply n1 by each of the integer digits of n2.\r
+                    ulong temp = (ulong)thisTemp[j] * digit;\r
+                    //n1.workingSet stores the low bits of each piecewise multiplication\r
+                    workingSet[j + i] = (uint)(temp & 0xffffffff);\r
+                    if (j + i + 1 < Length)\r
+                    {\r
+                        //n2.workingSet stores the high bits of each multiplication\r
+                        workingSet2[j + i + 1] = (uint)(temp >> 32);\r
+                    }\r
+                }\r
+\r
+                AddInternalBits(workingSet);\r
+                AddInternalBits(workingSet2);\r
+            }\r
+\r
+            sign = false;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Used for floating-point multiplication\r
+        /// Stores the high bits of the multiplication only (the carry bit from the\r
+        /// lower bits is missing, so the true answer might be 1 greater).\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        public void MulHi(BigInt n2)\r
+        {\r
+            if (n2.digitArray.Length != digitArray.Length) MakeSafe(ref n2);\r
+\r
+            int Length = n2.digitArray.Length;\r
+\r
+            //Inner loop zero-mul avoidance\r
+            int maxDigit = 0;\r
+            for (int i = Length - 1; i >= 0; i--)\r
+            {\r
+                if (digitArray[i] != 0)\r
+                {\r
+                    maxDigit = i + 1;\r
+                    break;\r
+                }\r
+            }\r
+\r
+            //Result is zero, 'this' is unchanged\r
+            if (maxDigit == 0) return;\r
+\r
+            //Temp storage for source (both working sets are used by the calculation)\r
+            uint[] thisTemp = new uint[Length];\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                thisTemp[i] = digitArray[i];\r
+                digitArray[i] = 0;\r
+            }\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                //Clear the working set\r
+                for (int j = 0; j < Length; j++)\r
+                {\r
+                    workingSet[j] = 0;\r
+                    n2.workingSet[j] = 0;\r
+                }\r
+\r
+                n2.workingSet[i] = 0;\r
+\r
+                ulong digit = n2.digitArray[i];\r
+                if (digit == 0) continue;\r
+\r
+                //Only the high bits\r
+                if (maxDigit + i < Length - 1) continue;\r
+\r
+                for (int j = 0; j < maxDigit; j++)\r
+                {\r
+                    if (j + i + 1 < Length) continue;\r
+                    //Multiply n1 by each of the integer digits of n2.\r
+                    ulong temp = (ulong)thisTemp[j] * digit;\r
+                    //n1.workingSet stores the low bits of each piecewise multiplication\r
+                    if (j + i >= Length)\r
+                    {\r
+                        workingSet[j + i - Length] = (uint)(temp & 0xffffffff);\r
+                    }\r
+                    \r
+                    //n2.workingSet stores the high bits of each multiplication\r
+                    n2.workingSet[j + i + 1 - Length] = (uint)(temp >> 32);\r
+                }\r
+\r
+                AddInternalBits(workingSet);\r
+                AddInternalBits(n2.workingSet);\r
+            }\r
+\r
+            sign = (sign != n2.sign);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Floating-point helper function.\r
+        /// Squares the number and keeps the high bits of the calculation.\r
+        /// Takes a temporary BigInt as a working set.\r
+        /// </summary>\r
+        public void SquareHiFast(BigInt scratch)\r
+        {\r
+            int Length = digitArray.Length;\r
+            uint[] tempDigits = scratch.digitArray;\r
+            uint[] workingSet2 = scratch.workingSet;\r
+\r
+            //Temp storage for source (both working sets are used by the calculation)\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                tempDigits[i] = digitArray[i];\r
+                digitArray[i] = 0;\r
+            }\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                //Clear the working set\r
+                for (int j = i; j < Length; j++)\r
+                {\r
+                    workingSet[j] = 0;\r
+                    workingSet2[j] = 0;\r
+                }\r
+\r
+                if (i - 1 >= 0) workingSet[i - 1] = 0;\r
+\r
+                ulong digit = tempDigits[i];\r
+                if (digit == 0) continue;\r
+\r
+                for (int j = 0; j < Length; j++)\r
+                {\r
+                    if (j + i + 1 < Length) continue;\r
+                    //Multiply n1 by each of the integer digits of n2.\r
+                    ulong temp = (ulong)tempDigits[j] * digit;\r
+                    //n1.workingSet stores the low bits of each piecewise multiplication\r
+                    if (j + i >= Length)\r
+                    {\r
+                        workingSet[j + i - Length] = (uint)(temp & 0xffffffff);\r
+                    }\r
+\r
+                    //n2.workingSet stores the high bits of each multiplication\r
+                    workingSet2[j + i + 1 - Length] = (uint)(temp >> 32);\r
+                }\r
+\r
+                AddInternalBits(workingSet);\r
+                AddInternalBits(workingSet2);\r
+            }\r
+\r
+            sign = false;\r
+        }\r
+\r
+        /// <summary>\r
+        /// This uses the schoolbook division algorithm, as decribed by http://www.treskal.com/kalle/exjobb/original-report.pdf\r
+        /// Algorithms 3.1 (implemented by Div_31) and 3.2 (implemented by Div_32)\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        public void Div(BigInt n2)\r
+        {\r
+            if (n2.digitArray.Length != digitArray.Length) MakeSafe(ref n2);\r
+\r
+            int OldLength = digitArray.Length;\r
+\r
+            //First, we need to prepare the operands for division using Div_32, which requires\r
+            //That the most significant digit of n2 be set. To do this, we need to shift n2 (and therefore n1) up.\r
+            //This operation can potentially increase the precision of the operands.\r
+            int shift = MakeSafeDiv(this, n2);\r
+\r
+            BigInt Q = new BigInt(this, this.pres, true);\r
+            BigInt R = new BigInt(this, this.pres, true);\r
+\r
+            Div_32(this, n2, Q, R);\r
+\r
+            //Restore n2 to its pre-shift value\r
+            n2.RSH(shift);\r
+            AssignInt(Q);\r
+            sign = (sign != n2.sign);\r
+\r
+            //Reset the lengths of the operands\r
+            SetNumDigits(OldLength);\r
+            n2.SetNumDigits(OldLength);\r
+        }\r
+\r
+        /// <summary>\r
+        /// This function is used for floating-point division.\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        //Given two numbers:\r
+        //  In floating point 1 <= a, b < 2, meaning that both numbers have their top bits set.\r
+        //  To calculate a / b, maintaining precision, we:\r
+        //    1. Double the number of digits available to both numbers.\r
+        //    2. set a = a * 2^d (where d is the number of digits)\r
+        //    3. calculate the quotient a <- q:  2^(d-1) <= q < 2^(d+1)\r
+        //    4. if a >= 2^d, s = 1, else s = 0\r
+        //    6. shift a down by s, and undo the precision extension\r
+        //    7. return 1 - shift (change necessary to exponent)\r
+        public int DivAndShift(BigInt n2)\r
+        {\r
+            if (n2.IsZero()) return -1;\r
+            if (digitArray.Length != n2.digitArray.Length) MakeSafe(ref n2);\r
+\r
+            int oldLength = digitArray.Length;\r
+\r
+            //Double the number of digits, and shift a into the higher digits.\r
+            Pad();\r
+            n2.Extend();\r
+\r
+            //Do the divide (at double precision, ouch!)\r
+            Div(n2);\r
+\r
+            //Shift down if 'this' >= 2^d\r
+            int ret = 1;\r
+\r
+            if (digitArray[oldLength] != 0)\r
+            {\r
+                RSH(1);\r
+                ret--;\r
+            }\r
+\r
+            SetNumDigits(oldLength);\r
+            n2.SetNumDigits(oldLength);\r
+\r
+            return ret;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates 'this' mod n2 (using the schoolbook division algorithm as above)\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        public void Mod(BigInt n2)\r
+        {\r
+            if (n2.digitArray.Length != digitArray.Length) MakeSafe(ref n2);\r
+\r
+            int OldLength = digitArray.Length;\r
+\r
+            //First, we need to prepare the operands for division using Div_32, which requires\r
+            //That the most significant digit of n2 be set. To do this, we need to shift n2 (and therefore n1) up.\r
+            //This operation can potentially increase the precision of the operands.\r
+            int shift = MakeSafeDiv(this, n2);\r
+\r
+            BigInt Q = new BigInt(this.pres);\r
+            BigInt R = new BigInt(this.pres);\r
+\r
+            Q.digitArray = new UInt32[this.digitArray.Length];\r
+            R.digitArray = new UInt32[this.digitArray.Length];\r
+\r
+            Div_32(this, n2, Q, R);\r
+\r
+            //Restore n2 to its pre-shift value\r
+            n2.RSH(shift);\r
+            R.RSH(shift);\r
+            R.sign = (sign != n2.sign);\r
+            AssignInt(R);\r
+\r
+            //Reset the lengths of the operands\r
+            SetNumDigits(OldLength);\r
+            n2.SetNumDigits(OldLength);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Logical left shift\r
+        /// </summary>\r
+        /// <param name="shift"></param>\r
+        public void LSH(int shift)\r
+        {\r
+            if (shift <= 0) return;\r
+            int length = digitArray.Length;\r
+            int digits = shift >> 5;\r
+            int rem = shift & 31;\r
+\r
+            for (int i = length - 1; i >= digits; i--)\r
+            {\r
+                digitArray[i] = digitArray[i - digits];\r
+            }\r
+\r
+            if (digits > 0)\r
+            {\r
+                for (int i = digits - 1; i >= 0; i--)\r
+                {\r
+                    digitArray[i] = 0;\r
+                }\r
+            }\r
+\r
+            UInt64 lastShift = 0;\r
+\r
+            for (int i = 0; i < length; i++)\r
+            {\r
+                UInt64 temp = (((UInt64)digitArray[i]) << rem) | lastShift;\r
+                digitArray[i] = (UInt32)(temp & 0xffffffff);\r
+                lastShift = temp >> 32;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Logical right-shift\r
+        /// </summary>\r
+        /// <param name="shift"></param>\r
+        public void RSH(int shift)\r
+        {\r
+            if (shift < 0) return;\r
+            int length = digitArray.Length;\r
+            int digits = shift >> 5;\r
+            int rem = shift & 31;\r
+\r
+            for (int i = 0; i < length - digits; i++)\r
+            {\r
+                digitArray[i] = digitArray[i + digits];\r
+            }\r
+\r
+            int start = (length - digits);\r
+            if (start < 0) start = 0;\r
+\r
+            for (int i = start; i < length; i++)\r
+            {\r
+                digitArray[i] = 0;\r
+            }\r
+\r
+            UInt64 lastShift = 0;\r
+\r
+            for (int i = length - 1; i >= 0; i--)\r
+            {\r
+                UInt64 temp = ((((UInt64)digitArray[i]) << 32) >> rem) | lastShift;\r
+                digitArray[i] = (UInt32)(temp >> 32);\r
+                lastShift = (temp & 0xffffffff) << 32;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Changes the sign of the number\r
+        /// </summary>\r
+        public void Negate()\r
+        {\r
+            sign = !sign;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Increments the number.\r
+        /// </summary>\r
+        public void Increment()\r
+        {\r
+            if (sign)\r
+            {\r
+                DecrementInt();\r
+            }\r
+            else\r
+            {\r
+                IncrementInt();\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Decrements the number.\r
+        /// </summary>\r
+        public void Decrement()\r
+        {\r
+            if (sign)\r
+            {\r
+                IncrementInt();\r
+            }\r
+            else\r
+            {\r
+                DecrementInt();\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates the factorial 'this'!\r
+        /// </summary>\r
+        public void Factorial()\r
+        {\r
+            if (sign) return;\r
+\r
+            //Clamp to a reasonable range.\r
+            int factToUse = (int)(digitArray[0]);\r
+            if (factToUse > 65536) factToUse = 65536;\r
+\r
+            Zero();\r
+            digitArray[0] = 1;\r
+\r
+            for (uint i = 1; i <= factToUse; i++)\r
+            {\r
+                MulInternal(i);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Calculates 'this'^power\r
+        /// </summary>\r
+        /// <param name="power"></param>\r
+        public void Power(BigInt power)\r
+        {\r
+            if (power.IsZero() || power.sign)\r
+            {\r
+                Zero();\r
+                digitArray[0] = 1;\r
+                return;\r
+            }\r
+\r
+            BigInt pow = new BigInt(power);\r
+            BigInt temp = new BigInt(this);\r
+            BigInt powTerm = new BigInt(this);\r
+\r
+            pow.Decrement();\r
+            for (; !pow.IsZero(); pow.RSH(1))\r
+            {\r
+                if ((pow.digitArray[0] & 1) == 1)\r
+                {\r
+                    temp.Mul(powTerm);\r
+                }\r
+\r
+                powTerm.Square();\r
+            }\r
+\r
+            Assign(temp);\r
+        }\r
+\r
+        //***************** Comparison member functions *****************\r
+\r
+        /// <summary>\r
+        /// returns true if this bigint == 0\r
+        /// </summary>\r
+        /// <returns></returns>\r
+        public bool IsZero()\r
+        {\r
+            for (int i = 0; i < digitArray.Length; i++)\r
+            {\r
+                if (digitArray[i] != 0) return false;\r
+            }\r
+\r
+            return true;\r
+        }\r
+\r
+        /// <summary>\r
+        /// true iff n2 (precision adjusted to this) is less than 'this'\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public bool LessThan(BigInt n2)\r
+        {\r
+            if (digitArray.Length != n2.digitArray.Length) MakeSafe(ref n2);\r
+\r
+            if (sign)\r
+            {\r
+                if (!n2.sign) return true;\r
+                return GtInt(this, n2);\r
+            }\r
+            else\r
+            {\r
+                if (n2.sign) return false;\r
+                return LtInt(this, n2);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// true iff n2 (precision adjusted to this) is greater than 'this'\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public bool GreaterThan(BigInt n2)\r
+        {\r
+            if (digitArray.Length != n2.digitArray.Length) MakeSafe(ref n2);\r
+\r
+            if (sign)\r
+            {\r
+                if (!n2.sign) return false;\r
+                return LtInt(this, n2);\r
+            }\r
+            else\r
+            {\r
+                if (n2.sign) return true;\r
+                return GtInt(this, n2);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Override of base-class equals\r
+        /// </summary>\r
+        /// <param name="obj"></param>\r
+        /// <returns></returns>\r
+        public override bool Equals(object obj)\r
+        {\r
+            BigInt n2 = ((BigInt)obj);\r
+            return Equals(n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Get hash code\r
+        /// </summary>\r
+        /// <returns></returns>\r
+        public override int GetHashCode()\r
+        {\r
+            return (Int32)digitArray[0];\r
+        }\r
+\r
+        /// <summary>\r
+        /// True iff n2 (precision-adjusted to this) == n1\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public bool Equals(BigInt n2)\r
+        {\r
+            if (IsZero() && n2.IsZero()) return true;\r
+\r
+            if (sign != n2.sign) return false;\r
+\r
+            int Length = digitArray.Length;\r
+            if (n2.digitArray.Length != Length) MakeSafe(ref n2);\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                if (digitArray[i] != n2.digitArray[i]) return false;\r
+            }\r
+\r
+            return true;\r
+        }\r
+\r
+        //******************* Bitwise member functions ********************\r
+\r
+        /// <summary>\r
+        /// Takes the bitwise complement of the number\r
+        /// </summary>\r
+        public void Complement()\r
+        {\r
+            int Length = digitArray.Length;\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                digitArray[i] = ~digitArray[i];\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Bitwise And\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        public void And(BigInt n2)\r
+        {\r
+            int Length = digitArray.Length;\r
+            if (n2.digitArray.Length != Length) MakeSafe(ref n2);\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                digitArray[i] &= n2.digitArray[i];\r
+            }\r
+\r
+            sign &= n2.sign;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Bitwise Or\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        public void Or(BigInt n2)\r
+        {\r
+            int Length = digitArray.Length;\r
+            if (n2.digitArray.Length != Length) MakeSafe(ref n2);\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                digitArray[i] |= n2.digitArray[i];\r
+            }\r
+\r
+            sign |= n2.sign;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Bitwise Xor\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        public void Xor(BigInt n2)\r
+        {\r
+            int Length = digitArray.Length;\r
+            if (n2.digitArray.Length != Length) MakeSafe(ref n2);\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                digitArray[i] ^= n2.digitArray[i];\r
+            }\r
+\r
+            sign ^= n2.sign;\r
+        }\r
+\r
+        //*************** Fast Static Arithmetic Functions *****************\r
+\r
+        /// <summary>\r
+        /// Adds n1 and n2 and puts result in dest, without intermediate memory allocation\r
+        /// (unsafe if n1 and n2 disagree in precision, safe even if dest is n1 or n2)\r
+        /// </summary>\r
+        /// <param name="dest"></param>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        public static void AddFast(BigInt dest, BigInt n1, BigInt n2)\r
+        {\r
+            //We cast to the highest input precision...\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+\r
+            //Then we up the output precision if less than the input precision.\r
+            if (dest.digitArray.Length < n1.digitArray.Length) n1.MakeSafe(ref dest);\r
+\r
+            int Length = n1.digitArray.Length;\r
+\r
+            if (n1.sign == n2.sign)\r
+            {\r
+                //Copies sources into digit array and working set for all cases, to avoid\r
+                //problems when dest is n1 or n2\r
+                for (int i = 0; i < Length; i++)\r
+                {\r
+                    dest.workingSet[i] = n2.digitArray[i];\r
+                    dest.digitArray[i] = n1.digitArray[i];\r
+                }\r
+                dest.AddInternalBits(dest.workingSet);\r
+                dest.sign = n1.sign;\r
+            }\r
+            else\r
+            {\r
+                bool lessThan = LtInt(n1, n2);\r
+\r
+                if (lessThan)\r
+                {\r
+                    for (int i = 0; i < Length; i++)\r
+                    {\r
+                        dest.workingSet[i] = n1.digitArray[i];\r
+                        dest.digitArray[i] = n2.digitArray[i];\r
+                    }\r
+                    dest.SubInternalBits(dest.workingSet);\r
+                    dest.sign = !n1.sign;\r
+                }\r
+                else\r
+                {\r
+                    for (int i = 0; i < Length; i++)\r
+                    {\r
+                        dest.workingSet[i] = n2.digitArray[i];\r
+                        dest.digitArray[i] = n1.digitArray[i];\r
+                    }\r
+                    dest.SubInternalBits(dest.workingSet);\r
+                    dest.sign = n1.sign;\r
+                }\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Adds n1 and n2 and puts result in dest, without intermediate memory allocation\r
+        /// (unsafe if n1 and n2 disagree in precision, safe even if dest is n1 or n2)\r
+        /// </summary>\r
+        /// <param name="dest"></param>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        public static void SubFast(BigInt dest, BigInt n1, BigInt n2)\r
+        {\r
+            //We cast to the highest input precision...\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+\r
+            //Then we up the output precision if less than the input precision.\r
+            if (dest.digitArray.Length < n1.digitArray.Length) n1.MakeSafe(ref dest);\r
+\r
+            int Length = n1.digitArray.Length;\r
+\r
+            if (n1.sign != n2.sign)\r
+            {\r
+                //Copies sources into digit array and working set for all cases, to avoid\r
+                //problems when dest is n1 or n2\r
+                for (int i = 0; i < Length; i++)\r
+                {\r
+                    dest.workingSet[i] = n2.digitArray[i];\r
+                    dest.digitArray[i] = n1.digitArray[i];\r
+                }\r
+                dest.AddInternalBits(dest.workingSet);\r
+                dest.sign = n1.sign;\r
+            }\r
+            else\r
+            {\r
+                bool lessThan = LtInt(n1, n2);\r
+\r
+                if (lessThan)\r
+                {\r
+                    for (int i = 0; i < Length; i++)\r
+                    {\r
+                        dest.workingSet[i] = n1.digitArray[i];\r
+                        dest.digitArray[i] = n2.digitArray[i];\r
+                    }\r
+                    dest.SubInternalBits(dest.workingSet);\r
+                    dest.sign = !n1.sign;\r
+                }\r
+                else\r
+                {\r
+                    for (int i = 0; i < Length; i++)\r
+                    {\r
+                        dest.workingSet[i] = n2.digitArray[i];\r
+                        dest.digitArray[i] = n1.digitArray[i];\r
+                    }\r
+                    dest.SubInternalBits(dest.workingSet);\r
+                    dest.sign = n1.sign;\r
+                }\r
+            }\r
+        }\r
+\r
+        //*************** Static Arithmetic Functions ***************\r
+\r
+        /// <summary>\r
+        /// signed addition of 2 numbers.\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static BigInt Add(BigInt n1, BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+            BigInt result; \r
+\r
+            if (n1.sign == n2.sign)\r
+            {\r
+                result = new BigInt(n1);\r
+                result.AddInternal(n2);\r
+                result.sign = n1.sign;\r
+            }\r
+            else\r
+            {\r
+                bool lessThan = LtInt(n1, n2);\r
+\r
+                if (lessThan)\r
+                {\r
+                    result = new BigInt(n2);\r
+                    result.SubInternal(n1);\r
+                    result.sign = !n1.sign;\r
+                }\r
+                else\r
+                {\r
+                    result = new BigInt(n1);\r
+                    result.SubInternal(n2);\r
+                    result.sign = n1.sign;\r
+                }\r
+            }\r
+\r
+            return result;\r
+        }\r
+\r
+        /// <summary>\r
+        /// signed subtraction of 2 numbers.\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static BigInt Sub(BigInt n1, BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+            BigInt result;\r
+\r
+            if ((n1.sign && !n2.sign) || (!n1.sign && n2.sign))\r
+            {\r
+                result = new BigInt(n1);\r
+                result.AddInternal(n2);\r
+                result.sign = n1.sign;\r
+            }\r
+            else\r
+            {\r
+                bool lessThan = LtInt(n1, n2);\r
+\r
+                if (lessThan)\r
+                {\r
+                    result = new BigInt(n2);\r
+                    result.SubInternal(n1);\r
+                    result.sign = !n1.sign;\r
+                }\r
+                else\r
+                {\r
+                    result = new BigInt(n1);\r
+                    result.SubInternal(n2);\r
+                    result.sign = n1.sign;\r
+                }\r
+            }\r
+\r
+            return result;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Multiplication of two BigInts\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static BigInt Mul(BigInt n1, BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+            \r
+            BigInt result = new BigInt(n1);\r
+            result.Mul(n2);\r
+            return result;\r
+        }\r
+\r
+        /// <summary>\r
+        /// True arbitrary precision divide.\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static BigInt Div(BigInt n1, BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+            BigInt res = new BigInt(n1);\r
+            res.Div(n2);\r
+            return res;\r
+        }\r
+\r
+        /// <summary>\r
+        /// True arbitrary-precision mod operation\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static BigInt Mod(BigInt n1, BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+            BigInt res = new BigInt(n1);\r
+            res.Mod(n2);\r
+            return res;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Unsigned multiplication of a BigInt by a small number\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static BigInt Mul(BigInt n1, uint n2)\r
+        {\r
+            BigInt result = new BigInt(n1);\r
+            result.MulInternal(n2);\r
+            return result;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Division of a BigInt by a small (unsigned) number\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static BigInt Div(BigInt n1, uint n2)\r
+        {\r
+            BigInt result = new BigInt(n1);\r
+            result.DivInternal(n2);\r
+            return result;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Division and remainder of a BigInt by a small (unsigned) number\r
+        /// n1 / n2 = div remainder mod\r
+        /// </summary>\r
+        /// <param name="n1">The number to divide (dividend)</param>\r
+        /// <param name="n2">The number to divide by (divisor)</param>\r
+        /// <param name="div">The quotient (output parameter)</param>\r
+        /// <param name="mod">The remainder (output parameter)</param>\r
+        public static void DivMod(BigInt n1, uint n2, out BigInt div, out BigInt mod)\r
+        {\r
+            div = Div(n1, n2);\r
+            mod = Mul(div, n2);\r
+            mod = Sub(n1, mod);\r
+        }\r
+\r
+        //**************** Static Comparison Functions ***************\r
+\r
+        /// <summary>\r
+        /// true iff n1 is less than n2\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static bool LessThan(BigInt n1, BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+\r
+            if (n1.sign)\r
+            {\r
+                if (!n2.sign) return true;\r
+                return GtInt(n1, n2);\r
+            }\r
+            else\r
+            {\r
+                if (n2.sign) return false;\r
+                return LtInt(n1, n2);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// true iff n1 is greater than n2\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static bool GreaterThan(BigInt n1, BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+\r
+            if (n1.sign)\r
+            {\r
+                if (!n2.sign) return false;\r
+                return LtInt(n1, n2);\r
+            }\r
+            else\r
+            {\r
+                if (n2.sign) return true;\r
+                return GtInt(n1, n2);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// true iff n1 == n2\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static bool Equals(BigInt n1, BigInt n2)\r
+        {\r
+            return n1.Equals(n2);\r
+        }\r
+\r
+        //***************** Static Bitwise Functions *****************\r
+\r
+        /// <summary>\r
+        /// Bitwise And\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static BigInt And(BigInt n1, BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+            BigInt res = new BigInt(n1);\r
+            res.And(n2);\r
+            return res;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Bitwise Or\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static BigInt Or(BigInt n1, BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+            BigInt res = new BigInt(n1);\r
+            res.Or(n2);\r
+            return res;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Bitwise Xor\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        public static BigInt Xor(BigInt n1, BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length != n2.digitArray.Length) MakeSafe(ref n1, ref n2);\r
+            BigInt res = new BigInt(n1);\r
+            res.And(n2);\r
+            return res;\r
+        }\r
+\r
+        //**************** Static Operator Overloads *****************\r
+\r
+        /// <summary>\r
+        /// Addition operator\r
+        /// </summary>\r
+        public static BigInt operator +(BigInt n1, BigInt n2)\r
+        {\r
+            return Add(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The subtraction operator\r
+        /// </summary>\r
+        public static BigInt operator -(BigInt n1, BigInt n2)\r
+        {\r
+            return Sub(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The multiplication operator\r
+        /// </summary>\r
+        public static BigInt operator *(BigInt n1, BigInt n2)\r
+        {\r
+            return Mul(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The division operator\r
+        /// </summary>\r
+        public static BigInt operator /(BigInt n1, BigInt n2)\r
+        {\r
+            return Div(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The remainder (mod) operator\r
+        /// </summary>\r
+        public static BigInt operator %(BigInt n1, BigInt n2)\r
+        {\r
+            return Mod(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The left-shift operator\r
+        /// </summary>\r
+        public static BigInt operator <<(BigInt n1, int n2)\r
+        {\r
+            BigInt res = new BigInt(n1);\r
+            res.LSH(n2);\r
+            return res;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The right-shift operator\r
+        /// </summary>\r
+        public static BigInt operator >>(BigInt n1, int n2)\r
+        {\r
+            BigInt res = new BigInt(n1);\r
+            res.RSH(n2);\r
+            return res;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The less than operator\r
+        /// </summary>\r
+        public static bool operator <(BigInt n1, BigInt n2)\r
+        {\r
+            return LessThan(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The greater than operator\r
+        /// </summary>\r
+        public static bool operator >(BigInt n1, BigInt n2)\r
+        {\r
+            return GreaterThan(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The less than or equal to operator\r
+        /// </summary>\r
+        public static bool operator <=(BigInt n1, BigInt n2)\r
+        {\r
+            return !GreaterThan(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The greater than or equal to operator\r
+        /// </summary>\r
+        public static bool operator >=(BigInt n1, BigInt n2)\r
+        {\r
+            return !LessThan(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The equality operator\r
+        /// </summary>\r
+        public static bool operator ==(BigInt n1, BigInt n2)\r
+        {\r
+            return Equals(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The inequality operator\r
+        /// </summary>\r
+        public static bool operator !=(BigInt n1, BigInt n2)\r
+        {\r
+            return !Equals(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The bitwise AND operator\r
+        /// </summary>\r
+        public static BigInt operator &(BigInt n1, BigInt n2)\r
+        {\r
+            return And(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The bitwise OR operator\r
+        /// </summary>\r
+        public static BigInt operator |(BigInt n1, BigInt n2)\r
+        {\r
+            return Or(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The bitwise eXclusive OR operator\r
+        /// </summary>\r
+        public static BigInt operator ^(BigInt n1, BigInt n2)\r
+        {\r
+            return Xor(n1, n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The increment operator\r
+        /// </summary>\r
+        public static BigInt operator ++(BigInt n1)\r
+        {\r
+            n1.Increment();\r
+            return n1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The decrement operator\r
+        /// </summary>\r
+        public static BigInt operator --(BigInt n1)\r
+        {\r
+            n1.Decrement();\r
+            return n1;\r
+        }\r
+\r
+        //**************** Private Member Functions *****************\r
+\r
+        /// <summary>\r
+        /// Unsigned multiplication and assignment by a small number\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        private void MulInternal(uint n2)\r
+        {\r
+            int Length = digitArray.Length;\r
+            ulong n2long = (ulong)n2;\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                workingSet[i] = 0;\r
+            }\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                if (digitArray[i] == 0) continue;\r
+                ulong temp = (ulong)digitArray[i] * n2long;\r
+                digitArray[i] = (uint)(temp & 0xffffffff);\r
+                if (i + 1 < Length) workingSet[i + 1] = (uint)(temp >> 32);\r
+            }\r
+\r
+            AddInternalBits(workingSet);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Unsigned division and assignment by a small number\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        private void DivInternal(uint n2)\r
+        {\r
+            int Length = digitArray.Length;\r
+            ulong carry = 0;\r
+\r
+            //Divide each digit by the small number.\r
+            for (int i = Length - 1; i >= 0; i--)\r
+            {\r
+                ulong temp = (ulong)digitArray[i] + (carry << 32);\r
+                digitArray[i] = (uint)(temp / (ulong)n2);\r
+                carry = temp % (ulong)n2;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Adds a signed integer to the number.\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        private void AddInternal(int n1)\r
+        {\r
+            if (n1 < 0)\r
+            {\r
+                SubInternal(-n1);\r
+                return;\r
+            }\r
+\r
+            uint carry = 0;\r
+            int length = digitArray.Length;\r
+\r
+            for (int i = 0; i < length && !(n1 == 0 && carry == 0); i++)\r
+            {\r
+                uint temp = digitArray[i];\r
+                digitArray[i] += (uint)n1 + carry;\r
+\r
+                carry = (digitArray[i] <= temp) ? 1u: 0u;\r
+                \r
+                n1 = 0;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Subtract a signed integer from the number.\r
+        /// This is internal because it will fail spectacularly if this number is negative or if n1 is bigger than this number.\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        private void SubInternal(int n1)\r
+        {\r
+            if (n1 < 0)\r
+            {\r
+                AddInternal(-n1);\r
+                return;\r
+            }\r
+\r
+            uint carry = 0;\r
+            int length = digitArray.Length;\r
+\r
+            for (int i = 0; i < length && !(n1 == 0 && carry == 0); i++)\r
+            {\r
+                uint temp = digitArray[i];\r
+                digitArray[i] -= ((uint)n1 + carry);\r
+\r
+                carry = (digitArray[i] >= temp) ? 1u: 0u;\r
+\r
+                n1 = 0;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Adds a signed integer to the number.\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        private bool AddInternal(uint n1)\r
+        {\r
+            uint carry = 0;\r
+            int length = digitArray.Length;\r
+\r
+            for (int i = 0; i < length && !(n1 == 0 && carry == 0); i++)\r
+            {\r
+                uint temp = digitArray[i];\r
+                digitArray[i] += n1 + carry;\r
+\r
+                carry = (digitArray[i] <= temp) ? 1u: 0u;\r
+\r
+                n1 = 0;\r
+            }\r
+\r
+            return (carry != 0);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Internally subtracts a uint from the number (sign insensitive)\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <returns></returns>\r
+        private bool SubInternal(uint n1)\r
+        {\r
+            uint carry = 0;\r
+            int length = digitArray.Length;\r
+\r
+            for (int i = 0; i < length && !(n1 == 0 && carry == 0); i++)\r
+            {\r
+                uint temp = digitArray[i];\r
+                digitArray[i] -= (n1 + carry);\r
+\r
+                carry = (digitArray[i] >= temp) ? 1u: 0u;\r
+\r
+                n1 = 0;\r
+            }\r
+\r
+            return (carry != 0);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Internal increment function (sign insensitive)\r
+        /// </summary>\r
+        private bool IncrementInt()\r
+        {\r
+            uint carry = 1;\r
+\r
+            int length = digitArray.Length;\r
+\r
+            for (int i = 0; i < length && carry != 0; i++)\r
+            {\r
+                uint temp = digitArray[i];\r
+                digitArray[i]++;\r
+\r
+                if (digitArray[i] > temp) carry = 0;\r
+            }\r
+\r
+            return (carry != 0);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Internal increment function (sign insensitive)\r
+        /// </summary>\r
+        private bool DecrementInt()\r
+        {\r
+            uint carry = 1;\r
+\r
+            int length = digitArray.Length;\r
+\r
+            for (int i = 0; i < length && carry != 0; i++)\r
+            {\r
+                uint temp = digitArray[i];\r
+                digitArray[i]--;\r
+\r
+                if (digitArray[i] < temp) carry = 0;\r
+            }\r
+\r
+            return (carry != 0);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Used to add a digit array to a big int.\r
+        /// </summary>\r
+        /// <param name="digitsToAdd"></param>\r
+        private uint AddInternalBits(uint[] digitsToAdd)\r
+        {\r
+            uint carry = 0;\r
+\r
+            int Length = digitArray.Length;\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                //Necessary because otherwise the carry calculation could go bad.\r
+                if (digitsToAdd[i] == 0 && carry == 0) continue;\r
+\r
+                uint temp = digitArray[i];\r
+                digitArray[i] += (digitsToAdd[i] + carry);\r
+\r
+                carry = 0;\r
+                if (digitArray[i] <= temp) carry = 1;\r
+            }\r
+\r
+            return carry;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Used to add with matching signs (true addition of the digit arrays)\r
+        /// This is internal because it will fail spectacularly if n1 is negative.\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        private uint AddInternal(BigInt n1)\r
+        {\r
+            return AddInternalBits(n1.digitArray);\r
+        }\r
+\r
+        private uint SubInternalBits(uint[] digitsToAdd)\r
+        {\r
+            uint carry = 0;\r
+\r
+            int Length = digitArray.Length;\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                //Necessary because otherwise the carry calculation could go bad.\r
+                if (digitsToAdd[i] == 0 && carry == 0) continue;\r
+\r
+                uint temp = digitArray[i];\r
+                digitArray[i] -= (digitsToAdd[i] + carry);\r
+\r
+                carry = 0;\r
+                if (digitArray[i] >= temp) carry = 1;\r
+            }\r
+\r
+            return carry;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Used to subtract n1 (true subtraction of digit arrays) - n1 must be less than or equal to this number\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        private uint SubInternal(BigInt n1)\r
+        {\r
+            return SubInternalBits(n1.digitArray);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Returns the length of the BigInt in 32-bit words for a given decimal precision\r
+        /// </summary>\r
+        /// <param name="precision"></param>\r
+        /// <returns></returns>\r
+        private static int GetRequiredDigitsForPrecision(PrecisionSpec precision)\r
+        {\r
+            int bits = precision.NumBits;\r
+            return ((bits - 1) >> 5) + 1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Initialises the BigInt to a desired decimal precision\r
+        /// </summary>\r
+        /// <param name="precision"></param>\r
+        private void Init(PrecisionSpec precision)\r
+        {\r
+            int numDigits = GetRequiredDigitsForPrecision(precision);\r
+            digitArray = new uint[numDigits];\r
+            workingSet = new uint[numDigits];\r
+            pres = precision;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Initialises the BigInt from a string, given a base and precision\r
+        /// </summary>\r
+        /// <param name="init"></param>\r
+        /// <param name="precision"></param>\r
+        /// <param name="numberBase"></param>\r
+        private void InitFromString(string init, PrecisionSpec precision, int numberBase)\r
+        {\r
+            PrecisionSpec test;\r
+            if (numberBase == 2)\r
+            {\r
+                test = new PrecisionSpec(init.Length, PrecisionSpec.BaseType.BIN);\r
+            }\r
+            else if (numberBase == 8)\r
+            {\r
+                test = new PrecisionSpec(init.Length, PrecisionSpec.BaseType.OCT);\r
+            }\r
+            else if (numberBase == 10)\r
+            {\r
+                test = new PrecisionSpec(init.Length, PrecisionSpec.BaseType.DEC);\r
+            }\r
+            else if (numberBase == 16)\r
+            {\r
+                test = new PrecisionSpec(init.Length, PrecisionSpec.BaseType.HEX);\r
+            }\r
+            else\r
+            {\r
+                throw new ArgumentOutOfRangeException();\r
+            }\r
+\r
+            //if (test.NumBits > precision.NumBits) precision = test;\r
+            Init(precision);\r
+            FromStringInt(init, numberBase);\r
+        }\r
+\r
+        //************ Helper Functions for floating point *************\r
+\r
+        /// <summary>\r
+        /// Returns true if only the top bit is set: i.e. if the floating-point number is a power of 2\r
+        /// </summary>\r
+        /// <returns></returns>\r
+        public bool IsTopBitOnlyBit()\r
+        {\r
+            int length = digitArray.Length;\r
+\r
+            if (digitArray[length - 1] != 0x80000000u) return false;\r
+            length--;\r
+            for (int i = 0; i < length; i++)\r
+            {\r
+                if (digitArray[i] != 0) return false;\r
+            }\r
+\r
+            return true;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Zeroes the n most significant bits of the number\r
+        /// </summary>\r
+        /// <param name="bits"></param>\r
+        public void ZeroBitsHigh(int bits)\r
+        {\r
+            //Already done.\r
+            if (bits <= 0) return;\r
+\r
+            int length = digitArray.Length;\r
+\r
+            //The entire digit array.\r
+            if ((bits >> 5) > length)\r
+            {\r
+                bits = length << 5;\r
+            }\r
+\r
+            int remBits = (bits & 31);\r
+            int startDigit = length - ((bits >> 5) + 1);\r
+\r
+            if (remBits != 0)\r
+            {\r
+                digitArray[startDigit] = digitArray[startDigit] & (0xffffffffu >> remBits);\r
+            }\r
+\r
+            for (int i = startDigit + 1; i < length; i++)\r
+            {\r
+                digitArray[i] = 0;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Zeroes the least-significant n bits.\r
+        /// </summary>\r
+        /// <param name="bits"></param>\r
+        public void ZeroBits(int bits)\r
+        {\r
+            //Already done.\r
+            if (bits <= 0) return;\r
+\r
+            //The entire digit array.\r
+            if ((bits >> 5) > digitArray.Length)\r
+            {\r
+                bits = digitArray.Length << 5;\r
+            }\r
+\r
+            int remBits = (bits & 31);\r
+            int startDigit = bits >> 5;\r
+            \r
+            if (remBits != 0)\r
+            {\r
+                UInt32 startMask = 0xffffffffu & ~(UInt32)(((1 << remBits) - 1));\r
+                digitArray[startDigit] = digitArray[startDigit] & startMask;\r
+            }\r
+\r
+            for (int i = startDigit - 1; i >= 0; i--)\r
+            {\r
+                digitArray[i] = 0;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Sets the number to 0\r
+        /// </summary>\r
+        public void Zero()\r
+        {\r
+            int length = digitArray.Length;\r
+\r
+            for (int i = 0; i < length; i++)\r
+            {\r
+                digitArray[i] = 0;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Rounds off the least significant bits of the number.\r
+        /// Can only round off up to 31 bits.\r
+        /// </summary>\r
+        /// <param name="bits">number of bits to round</param>\r
+        /// <returns></returns>\r
+        public bool Round(int bits)\r
+        {\r
+            //Always less than 32 bits, please!\r
+            if (bits < 32)\r
+            {\r
+                uint pow2 = 1u << bits;\r
+                uint test = digitArray[0] & (pow2 >> 1);\r
+\r
+                //Zero the lower bits\r
+                digitArray[0] = digitArray[0] & ~(pow2 - 1);\r
+\r
+                if (test != 0)\r
+                {\r
+                    bool bRet = AddInternal(pow2);\r
+                    digitArray[digitArray.Length - 1] = digitArray[digitArray.Length - 1] | 0x80000000;\r
+                    return bRet;\r
+                }\r
+            }\r
+\r
+            return false;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Used for casting between BigFloats of different precisions - this assumes\r
+        /// that the number is a normalised mantissa.\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        /// <returns>true if a round-up caused the high bits to become zero</returns>\r
+        public bool AssignHigh(BigInt n2)\r
+        {\r
+            int length = digitArray.Length;\r
+            int length2 = n2.digitArray.Length;\r
+            int minWords = (length < length2) ? length: length2;\r
+            bool bRet = false;\r
+\r
+            for (int i = 1; i <= minWords; i++)\r
+            {\r
+                digitArray[length - i] = n2.digitArray[length2 - i];\r
+            }\r
+\r
+            if (length2 > length && n2.digitArray[length2 - (length + 1)] >= 0x80000000)\r
+            {\r
+                bRet = IncrementInt();\r
+\r
+                //Because we are assuming normalisation, we set the top bit (it will already be set if\r
+                //bRet is false.\r
+                digitArray[length - 1] = digitArray[length - 1] | 0x80000000;\r
+            }\r
+\r
+            sign = n2.sign;\r
+\r
+            return bRet;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Used for casting between long ints or doubles and floating-point numbers\r
+        /// </summary>\r
+        /// <param name="digits"></param>\r
+        public void SetHighDigits(Int64 digits)\r
+        {\r
+            digitArray[digitArray.Length - 1] = (uint)(digits >> 32);\r
+            if (digitArray.Length > 1) digitArray[digitArray.Length - 2] = (uint)(digits & 0xffffffff);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Used for casting between ints and doubles or floats.\r
+        /// </summary>\r
+        /// <param name="digit"></param>\r
+        public void SetHighDigit(UInt32 digit)\r
+        {\r
+            digitArray[digitArray.Length - 1] = digit;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Helper function for floating-point - extends the number to twice the precision\r
+        /// and shifts the digits into the upper bits.\r
+        /// </summary>\r
+        public void Pad()\r
+        {\r
+            int length = digitArray.Length;\r
+            int digits = length << 1;\r
+\r
+            UInt32[] newDigitArray = new UInt32[digits];\r
+            workingSet = new UInt32[digits];\r
+\r
+            for (int i = 0; i < length; i++)\r
+            {\r
+                newDigitArray[i + length] = digitArray[i];\r
+            }\r
+\r
+            digitArray = newDigitArray;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Helper function for floating-point - extends the number to twice the precision...\r
+        /// This is a necessary step in floating-point division.\r
+        /// </summary>\r
+        public void Extend()\r
+        {\r
+            SetNumDigits(digitArray.Length * 2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets the highest big of the integer (used for floating point stuff)\r
+        /// </summary>\r
+        /// <returns></returns>\r
+        public uint GetTopBit()\r
+        {\r
+            return (digitArray[digitArray.Length - 1] >> 31);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Used for floating point multiplication, this shifts the number so that\r
+        /// the highest bit is set, and returns the number of places shifted.\r
+        /// </summary>\r
+        /// <returns></returns>\r
+        public int Normalise()\r
+        {\r
+            if (IsZero()) return 0;\r
+\r
+            int MSD = GetMSD();\r
+            int digitShift = (digitArray.Length - (MSD + 1));\r
+            int bitShift = (31 - GetMSB(digitArray[MSD])) + (digitShift << 5);\r
+            LSH(bitShift);\r
+            return bitShift;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets the most significant bit\r
+        /// </summary>\r
+        /// <param name="value">the input to search for the MSB in</param>\r
+        /// <returns>-1 if the input was zero, the position of the MSB otherwise</returns>\r
+        public static int GetMSB(UInt32 value)\r
+        {\r
+            if (value == 0) return -1;\r
+\r
+            uint mask1 = 0xffff0000;\r
+            uint mask2 = 0xff00;\r
+            uint mask3 = 0xf0;\r
+            uint mask4 = 0xc;   //1100 in binary\r
+            uint mask5 = 0x2;   //10 in binary\r
+\r
+            int iPos = 0;\r
+\r
+            //Unrolled binary search for the most significant bit.\r
+            if ((value & mask1) != 0) iPos += 16;\r
+            mask2 <<= iPos;\r
+\r
+            if ((value & mask2) != 0) iPos += 8;\r
+            mask3 <<= iPos;\r
+\r
+            if ((value & mask3) != 0) iPos += 4;\r
+            mask4 <<= iPos;\r
+\r
+            if ((value & mask4) != 0) iPos += 2;\r
+            mask5 <<= iPos;\r
+\r
+            if ((value & mask5) != 0) iPos++;\r
+\r
+            return iPos;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets the most significant bit\r
+        /// </summary>\r
+        /// <param name="value">the input to search for the MSB in</param>\r
+        /// <returns>-1 if the input was zero, the position of the MSB otherwise</returns>\r
+        public static int GetMSB(UInt64 value)\r
+        {\r
+            if (value == 0) return -1;\r
+\r
+            UInt64 mask0 = 0xffffffff00000000ul;\r
+            UInt64 mask1 = 0xffff0000;\r
+            UInt64 mask2 = 0xff00;\r
+            UInt64 mask3 = 0xf0;\r
+            UInt64 mask4 = 0xc;   //1100 in binary\r
+            UInt64 mask5 = 0x2;   //10 in binary\r
+\r
+            int iPos = 0;\r
+\r
+            //Unrolled binary search for the most significant bit.\r
+            if ((value & mask0) != 0) iPos += 32;\r
+            mask1 <<= iPos;\r
+\r
+            if ((value & mask1) != 0) iPos += 16;\r
+            mask2 <<= iPos;\r
+\r
+            if ((value & mask2) != 0) iPos += 8;\r
+            mask3 <<= iPos;\r
+\r
+            if ((value & mask3) != 0) iPos += 4;\r
+            mask4 <<= iPos;\r
+\r
+            if ((value & mask4) != 0) iPos += 2;\r
+            mask5 <<= iPos;\r
+\r
+            if ((value & mask5) != 0) iPos++;\r
+\r
+            return iPos;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets the most significant bit\r
+        /// </summary>\r
+        /// <param name="value">the input to search for the MSB in</param>\r
+        /// <returns>-1 if the input was zero, the position of the MSB otherwise</returns>\r
+        public static int GetMSB(BigInt value)\r
+        {\r
+            int digit = value.GetMSD();\r
+            int bit = GetMSB(value.digitArray[digit]);\r
+            return (digit << 5) + bit;\r
+        }\r
+\r
+        //**************** Helper Functions for Div ********************\r
+\r
+        /// <summary>\r
+        /// Gets the index of the most significant digit\r
+        /// </summary>\r
+        /// <returns></returns>\r
+        private int GetMSD()\r
+        {\r
+            for (int i = digitArray.Length - 1; i >= 0; i--)\r
+            {\r
+                if (digitArray[i] != 0) return i;\r
+            }\r
+\r
+            return 0;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets the required bitshift for the Div_32 algorithm\r
+        /// </summary>\r
+        /// <returns></returns>\r
+        private int GetDivBitshift()\r
+        {\r
+            uint digit = digitArray[GetMSD()];\r
+            uint mask1 = 0xffff0000;\r
+            uint mask2 = 0xff00;\r
+            uint mask3 = 0xf0;  \r
+            uint mask4 = 0xc;   //1100 in binary\r
+            uint mask5 = 0x2;   //10 in binary\r
+\r
+            int iPos = 0;\r
+\r
+            //Unrolled binary search for the most significant bit.\r
+            if ((digit & mask1) != 0) iPos += 16;\r
+            mask2 <<= iPos;\r
+\r
+            if ((digit & mask2) != 0) iPos += 8;\r
+            mask3 <<= iPos;\r
+            \r
+            if ((digit & mask3) != 0) iPos += 4;\r
+            mask4 <<= iPos;\r
+\r
+            if ((digit & mask4) != 0) iPos += 2;\r
+            mask5 <<= iPos;\r
+\r
+            if ((digit & mask5) != 0) return 30 - iPos;\r
+\r
+            return 31 - iPos;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Shifts and optionally precision-extends the arguments to prepare for Div_32\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        private static int MakeSafeDiv(BigInt n1, BigInt n2)\r
+        {\r
+            int shift = n2.GetDivBitshift();\r
+            int n1MSD = n1.GetMSD();\r
+\r
+            uint temp = n1.digitArray[n1MSD];\r
+            if (n1MSD == n1.digitArray.Length - 1 && ((temp << shift) >> shift) != n1.digitArray[n1MSD])\r
+            {\r
+                //Precision-extend n1 and n2 if necessary\r
+                int digits = n1.digitArray.Length;\r
+                n1.SetNumDigits(digits + 1);\r
+                n2.SetNumDigits(digits + 1);\r
+            }\r
+\r
+            //Logical left-shift n1 and n2\r
+            n1.LSH(shift);\r
+            n2.LSH(shift);\r
+\r
+            return shift;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Schoolbook division helper function.\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <param name="Q">Quotient output value</param>\r
+        /// <param name="R">Remainder output value</param>\r
+        private static void Div_31(BigInt n1, BigInt n2, BigInt Q, BigInt R)\r
+        {\r
+            int digitsN1 = n1.GetMSD() + 1;\r
+            int digitsN2 = n2.GetMSD() + 1;            \r
+\r
+            if ((digitsN1 > digitsN2))\r
+            {\r
+                BigInt n1New = new BigInt(n2);\r
+                n1New.DigitShiftSelfLeft(1);\r
+\r
+                //If n1 >= n2 * 2^32\r
+                if (!LtInt(n1, n1New))\r
+                {\r
+                    n1New.sign = n1.sign;\r
+                    SubFast(n1New, n1, n1New);\r
+\r
+                    Div_32(n1New, n2, Q, R);\r
+\r
+                    //Q = (A - B*2^32)/B + 2^32\r
+                    Q.Add2Pow32Self();\r
+                    return;\r
+                }\r
+            }\r
+\r
+            UInt32 q = 0;\r
+\r
+            if (digitsN1 >= 2)\r
+            {\r
+                UInt64 q64 = ((((UInt64)n1.digitArray[digitsN1 - 1]) << 32) + n1.digitArray[digitsN1 - 2]) / (UInt64)n2.digitArray[digitsN2 - 1];\r
+\r
+                if (q64 > 0xfffffffful)\r
+                {\r
+                    q = 0xffffffff;\r
+                }\r
+                else\r
+                {\r
+                    q = (UInt32)q64;\r
+                }\r
+            }\r
+\r
+            BigInt temp = Mul(n2, q);\r
+\r
+            if (GtInt(temp, n1))\r
+            {\r
+                temp.SubInternalBits(n2.digitArray);\r
+                q--;\r
+\r
+                if (GtInt(temp, n1))\r
+                {\r
+                    temp.SubInternalBits(n2.digitArray);\r
+                    q--;\r
+                }\r
+            }\r
+\r
+            Q.Zero();\r
+            Q.digitArray[0] = q;\r
+            R.Assign(n1);\r
+            R.SubInternalBits(temp.digitArray);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Schoolbook division algorithm\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <param name="Q"></param>\r
+        /// <param name="R"></param>\r
+        private static void Div_32(BigInt n1, BigInt n2, BigInt Q, BigInt R)\r
+        {\r
+            int digitsN1 = n1.GetMSD() + 1;\r
+            int digitsN2 = n2.GetMSD() + 1;\r
+\r
+            //n2 is bigger than n1\r
+            if (digitsN1 < digitsN2)\r
+            {\r
+                R.AssignInt(n1);\r
+                Q.Zero();\r
+                return;\r
+            }\r
+\r
+            if (digitsN1 == digitsN2)\r
+            {\r
+                //n2 is bigger than n1\r
+                if (LtInt(n1, n2))\r
+                {\r
+                    R.AssignInt(n1);\r
+                    Q.Zero();\r
+                    return;\r
+                }\r
+\r
+                //n2 >= n1, but less the 2x n1 (initial conditions make this certain)\r
+                Q.Zero();\r
+                Q.digitArray[0] = 1;\r
+                R.Assign(n1);\r
+                R.SubInternalBits(n2.digitArray);\r
+                return;\r
+            }\r
+\r
+            int digits = digitsN1 - (digitsN2 + 1);\r
+\r
+            //Algorithm Div_31 can be used to get the answer in O(n) time.\r
+            if (digits == 0)\r
+            {\r
+                Div_31(n1, n2, Q, R);\r
+                return;\r
+            }\r
+\r
+            BigInt n1New = DigitShiftRight(n1, digits);\r
+            BigInt s = DigitTruncate(n1, digits);\r
+\r
+            BigInt Q2 = new BigInt(n1, n1.pres, true);\r
+            BigInt R2 = new BigInt(n1, n1.pres, true);\r
+\r
+            Div_31(n1New, n2, Q2, R2);\r
+\r
+            R2.DigitShiftSelfLeft(digits);\r
+            R2.Add(s);\r
+\r
+            Div_32(R2, n2, Q, R);\r
+\r
+            Q2.DigitShiftSelfLeft(digits);\r
+            Q.Add(Q2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Sets the n-th bit of the number to 1\r
+        /// </summary>\r
+        /// <param name="bit">the index of the bit to set</param>\r
+        public void SetBit(int bit)\r
+        {\r
+            int digit = (bit >> 5);\r
+            if (digit >= digitArray.Length) return;\r
+            digitArray[digit] = digitArray[digit] | (1u << (bit - (digit << 5)));\r
+        }\r
+\r
+        /// <summary>\r
+        /// Sets the n-th bit of the number to 0\r
+        /// </summary>\r
+        /// <param name="bit">the index of the bit to set</param>\r
+        public void ClearBit(int bit)\r
+        {\r
+            int digit = (bit >> 5);\r
+            if (digit >= digitArray.Length) return;\r
+            digitArray[digit] = digitArray[digit] & (~(1u << (bit - (digit << 5))));\r
+        }\r
+\r
+        /// <summary>\r
+        /// Returns the n-th bit, counting from the MSB to the LSB\r
+        /// </summary>\r
+        /// <param name="bit">the index of the bit to return</param>\r
+        /// <returns>1 if the bit is 1, 0 otherwise</returns>\r
+        public uint GetBitFromTop(int bit)\r
+        {\r
+            if (bit < 0) return 0;\r
+            int wordCount = (bit >> 5);\r
+            int upBit = 31 - (bit & 31);\r
+            if (wordCount >= digitArray.Length) return 0;\r
+\r
+            return ((digitArray[digitArray.Length - (wordCount + 1)] & (1u << upBit)) >> upBit);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Assigns n2 to 'this'\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        public void Assign(BigInt n2)\r
+        {\r
+            if (digitArray.Length != n2.digitArray.Length) MakeSafe(ref n2);\r
+            sign = n2.sign;\r
+            AssignInt(n2);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Assign n2 to 'this', safe only if precision-matched\r
+        /// </summary>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        private void AssignInt(BigInt n2)\r
+        {\r
+            int Length = digitArray.Length;\r
+\r
+            for (int i = 0; i < Length; i++)\r
+            {\r
+                digitArray[i] = n2.digitArray[i];\r
+            }\r
+        }\r
+\r
+        private static BigInt DigitShiftRight(BigInt n1, int digits)\r
+        {\r
+            BigInt res = new BigInt(n1);\r
+\r
+            int Length = res.digitArray.Length;\r
+\r
+            for (int i = 0; i < Length - digits; i++)\r
+            {\r
+                res.digitArray[i] = res.digitArray[i + digits];\r
+            }\r
+\r
+            for (int i = Length - digits; i < Length; i++)\r
+            {\r
+                res.digitArray[i] = 0;\r
+            }\r
+\r
+            return res;\r
+        }\r
+\r
+        private void DigitShiftSelfRight(int digits)\r
+        {\r
+            for (int i = digits; i < digitArray.Length; i++)\r
+            {\r
+                digitArray[i - digits] = digitArray[i];\r
+            }\r
+\r
+            for (int i = digitArray.Length - digits; i < digitArray.Length; i++)\r
+            {\r
+                digitArray[i] = 0;\r
+            }\r
+        }\r
+\r
+        private void DigitShiftSelfLeft(int digits)\r
+        {\r
+            for (int i = digitArray.Length - 1; i >= digits; i--)\r
+            {\r
+                digitArray[i] = digitArray[i - digits];\r
+            }\r
+\r
+            for (int i = digits - 1; i >= 0; i--)\r
+            {\r
+                digitArray[i] = 0;\r
+            }\r
+        }\r
+\r
+        private static BigInt DigitTruncate(BigInt n1, int digits)\r
+        {\r
+            BigInt res = new BigInt(n1);\r
+\r
+            for (int i = res.digitArray.Length - 1; i >= digits; i--)\r
+            {\r
+                res.digitArray[i] = 0;\r
+            }\r
+\r
+            return res;\r
+        }\r
+\r
+        private void Add2Pow32Self()\r
+        {\r
+            int Length = digitArray.Length;\r
+\r
+            uint carry = 1;\r
+\r
+            for (int i = 1; i < Length; i++)\r
+            {\r
+                uint temp = digitArray[i];\r
+                digitArray[i] += carry;\r
+                if (digitArray[i] > temp) return;\r
+            }\r
+\r
+            return;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Sets the number of digits without changing the precision\r
+        /// This method is made public only to facilitate fixed-point operations\r
+        /// It should under no circumstances be used for anything else, because\r
+        /// it breaks the BigNum(PrecisionSpec precision) constructor in dangerous\r
+        /// and unpredictable ways.\r
+        /// </summary>\r
+        /// <param name="digits"></param>\r
+        public void SetNumDigits(int digits)\r
+        {\r
+            if (digits == digitArray.Length) return;\r
+\r
+            UInt32[] newDigitArray = new UInt32[digits];\r
+            workingSet = new UInt32[digits];\r
+\r
+            int numCopy = (digits < digitArray.Length) ? digits : digitArray.Length;\r
+\r
+            for (int i = 0; i < numCopy; i++)\r
+            {\r
+                newDigitArray[i] = digitArray[i];\r
+            }\r
+\r
+            digitArray = newDigitArray;\r
+        }\r
+\r
+        //********************** Explicit casts ***********************\r
+\r
+        /// <summary>\r
+        /// Cast to int\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <returns></returns>\r
+        public static explicit operator Int32(BigInt value)\r
+        {\r
+            if (value.digitArray[0] == 0x80000000 && value.sign) return Int32.MinValue;\r
+            int res = (int)(value.digitArray[0] & 0x7fffffff);\r
+            if (value.sign) res = -res;\r
+            return res;\r
+        }\r
+\r
+        /// <summary>\r
+        /// explicit cast to unsigned int.\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <returns></returns>\r
+        public static explicit operator UInt32(BigInt value)\r
+        {\r
+            if (value.sign) return (UInt32)((Int32)(value));\r
+            return (UInt32)value.digitArray[0];\r
+        }\r
+\r
+        /// <summary>\r
+        /// explicit cast to 64-bit signed integer.\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <returns></returns>\r
+        public static explicit operator Int64(BigInt value)\r
+        {\r
+            if (value.digitArray.Length < 2) return (value.sign ? -((Int64)value.digitArray[0]): ((Int64)value.digitArray[0]));\r
+            UInt64 ret = (((UInt64)value.digitArray[1]) << 32) + (UInt64)value.digitArray[0];\r
+            if (ret == 0x8000000000000000L && value.sign) return Int64.MinValue;\r
+            Int64 signedRet = (Int64)(ret & 0x7fffffffffffffffL);\r
+            if (value.sign) signedRet = -signedRet;\r
+            return signedRet;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Explicit cast to UInt64\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <returns></returns>\r
+        public static explicit operator UInt64(BigInt value)\r
+        {\r
+            if (value.sign) return (UInt64)((Int64)(value));\r
+            if (value.digitArray.Length < 2) return (UInt64)value.digitArray[0];\r
+            return ((((UInt64)value.digitArray[1]) << 32) + (UInt64)value.digitArray[0]);\r
+        }\r
+\r
+        /// <summary>\r
+        /// Cast to string\r
+        /// </summary>\r
+        /// <param name="value"></param>\r
+        /// <returns></returns>\r
+        public static explicit operator string(BigInt value)\r
+        {\r
+            return value.ToString();\r
+        }\r
+\r
+        /// <summary>\r
+        /// Cast from string - this is not wholly safe, because precision is not\r
+        /// specified. You should try to construct a BigInt with the appropriate\r
+        /// constructor instead.\r
+        /// </summary>\r
+        /// <param name="value">The decimal string to convert to a BigInt</param>\r
+        /// <returns>A BigInt of the precision required to encompass the string</returns>\r
+        public static explicit operator BigInt(string value)\r
+        {\r
+            return new BigInt(value);\r
+        }\r
+\r
+        //********************* ToString members **********************\r
+\r
+        /// <summary>\r
+        /// Converts this to a string, in the specified base\r
+        /// </summary>\r
+        /// <param name="numberBase">the base to use (min 2, max 16)</param>\r
+        /// <returns>a string representation of the number</returns>\r
+        public string ToString(int numberBase)\r
+        {\r
+            char[] digitChars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };\r
+\r
+            string output = "";\r
+\r
+            BigInt clone = new BigInt(this);\r
+            clone.sign = false;\r
+\r
+            int numDigits = 0;\r
+            while (!clone.IsZero())\r
+            {\r
+                if (numberBase == 10 && (numDigits % 3) == 0 && numDigits != 0)\r
+                {\r
+                    output = String.Format(",{0}", output);\r
+                }\r
+                else if (numberBase != 10 && (numDigits % 8) == 0 && numDigits != 0)\r
+                {\r
+                    output = String.Format(" {0}", output);\r
+                }\r
+\r
+                BigInt div, mod;\r
+                DivMod(clone, (uint)numberBase, out div, out mod);\r
+                int iMod = (int)mod;\r
+                output = String.Format("{0}{1}", digitChars[(int)mod], output);\r
+\r
+                numDigits++;\r
+\r
+                clone = div;\r
+            }\r
+\r
+            if (output.Length == 0) output = String.Format("0");\r
+\r
+            if (sign) output = String.Format("-{0}", output);\r
+\r
+            return output;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Converts the number to a string, in base 10\r
+        /// </summary>\r
+        /// <returns>a string representation of the number in base 10</returns>\r
+        public override string ToString()\r
+        {\r
+            return ToString(10);\r
+        }\r
+\r
+        //***************** Internal helper functions *****************\r
+\r
+        private void FromStringInt(string init, int numberBase)\r
+        {\r
+            char [] digitChars = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};\r
+\r
+            string formattedInput = init.Trim().ToUpper();\r
+\r
+            for (int i = 0; i < formattedInput.Length; i++)\r
+            {\r
+                int digitIndex = Array.IndexOf(digitChars, formattedInput[i]);\r
+\r
+                //Skip fractional part altogether\r
+                if (formattedInput[i] == '.') break;\r
+\r
+                //skip non-digit characters.\r
+                if (digitIndex < 0) continue;\r
+\r
+                //Multiply\r
+                MulInternal((uint)numberBase);\r
+              \r
+                //Add\r
+                AddInternal(digitIndex);\r
+            }\r
+\r
+            if (init.Length > 0 && init[0] == '-') sign = true;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Sign-insensitive less than comparison. \r
+        /// unsafe if n1 and n2 disagree in precision\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        private static bool LtInt(BigInt n1, BigInt n2)\r
+        {\r
+            //MakeSafe(ref n1, ref n2);\r
+\r
+            for (int i = n1.digitArray.Length - 1; i >= 0; i--)\r
+            {\r
+                if (n1.digitArray[i] < n2.digitArray[i]) return true;\r
+                if (n1.digitArray[i] > n2.digitArray[i]) return false;\r
+            }\r
+\r
+            //equal\r
+            return false;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Sign-insensitive greater than comparison. \r
+        /// unsafe if n1 and n2 disagree in precision\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        /// <returns></returns>\r
+        private static bool GtInt(BigInt n1, BigInt n2)\r
+        {\r
+            //MakeSafe(ref n1, ref n2);\r
+\r
+            for (int i = n1.digitArray.Length - 1; i >= 0; i--)\r
+            {\r
+                if (n1.digitArray[i] > n2.digitArray[i]) return true;\r
+                if (n1.digitArray[i] < n2.digitArray[i]) return false;\r
+            }\r
+\r
+            //equal\r
+            return false;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Makes sure the numbers have matching precisions\r
+        /// </summary>\r
+        /// <param name="n1"></param>\r
+        /// <param name="n2"></param>\r
+        private static void MakeSafe(ref BigInt n1, ref BigInt n2)\r
+        {\r
+            if (n1.digitArray.Length == n2.digitArray.Length)\r
+            {\r
+                return;\r
+            }\r
+            else if (n1.digitArray.Length > n2.digitArray.Length)\r
+            {\r
+                n2 = new BigInt(n2, n1.pres);\r
+            }\r
+            else\r
+            {\r
+                n1 = new BigInt(n1, n2.pres);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Makes sure the numbers have matching precisions\r
+        /// </summary>\r
+        /// <param name="n2">the number to match to this</param>\r
+        private void MakeSafe(ref BigInt n2)\r
+        {\r
+            n2 = new BigInt(n2, pres);\r
+            n2.SetNumDigits(digitArray.Length);\r
+        }\r
+\r
+\r
+        private PrecisionSpec pres;\r
+        private bool sign;\r
+        private uint[] digitArray;\r
+        private uint[] workingSet;\r
+    }\r
+\r
+}
\ No newline at end of file
diff --git a/dev5/psychlops/extension/math/solver.cs b/dev5/psychlops/extension/math/solver.cs
new file mode 100644 (file)
index 0000000..8ff2b38
--- /dev/null
@@ -0,0 +1,411 @@
+using System.Threading;\r
+using System;\r
+using BigNum;\r
+\r
+namespace Psychlops\r
+{\r
+\r
+       namespace Solver\r
+       {\r
+               internal static class CONST\r
+               {\r
+                       public static readonly uint MAX_ARG = 5;\r
+               }\r
+\r
+               \r
+               static public class Constants\r
+               {\r
+                       public static readonly int LIMIT = 5;\r
+                       public delegate double Func0(double x);\r
+                       public delegate double Func1(double x, double a);\r
+                       public delegate double Func2(double x, double a, double b);\r
+                       public delegate double Func3(double x, double a, double b, double c);\r
+                       public delegate double Func4(double x, double a, double b, double c, double d);\r
+                       public delegate double Func5(double x, double a, double b, double c, double d, double e);\r
+               }\r
+\r
+\r
+               static public class Binomial\r
+               {\r
+                       public static double factorial(int fact)\r
+                       {\r
+                               double x = 1;\r
+                               for (int i = 1; i <= fact; i++)\r
+                               {\r
+                                       x *= i;\r
+                               }\r
+                               return x;\r
+                       }\r
+                       public static double combination(int nn, int kk)\r
+                       {\r
+                               return (double)(Int64)(factorial(nn) / (factorial(kk) * factorial(nn - kk)));\r
+                               /*\r
+                               BigInt n = new BigInt((Int64)nn, new PrecisionSpec());\r
+                               BigInt k = new BigInt((Int64)kk, new PrecisionSpec());\r
+                               BigInt n_k = n - k;\r
+                               n.Factorial();\r
+                               k.Factorial();\r
+                               n_k.Factorial();\r
+                               return (double)(Int64)(n / (k * n_k) );\r
+                                * */\r
+                       }\r
+                       public static double likelihood(double pp, int yes, int no)\r
+                       {\r
+                               double p;\r
+                               if (pp < 0) p = 0; else if (pp > 1) p = 1; else p = pp;\r
+                               return combination(yes + no, yes) * System.Math.Pow(p, yes) * System.Math.Pow(1 - p, no);\r
+                       }\r
+\r
+                       public static double likelihood(double pp, int yes, int no, double comb)\r
+                       {\r
+                               double p;\r
+                               if (pp < 0) p = 0; else if (pp > 1) p = 1; else p = pp;\r
+                               return comb * System.Math.Pow(p, yes) * System.Math.Pow(1 - p, no);\r
+                       }\r
+\r
+               }\r
+\r
+\r
+               public class BernoulliProcess\r
+               {\r
+                       public struct Data\r
+                       {\r
+                               public double x;\r
+                               public int pos, neg, comb;\r
+                               public void set(double cond, int posit, int negat)\r
+                               {\r
+                                       x = cond;\r
+                                       pos = posit;\r
+                                       neg = negat;\r
+                               }\r
+\r
+                       };\r
+                       public Data[] elems;\r
+                       public int length;\r
+                       public void set(double[][] num)\r
+                       {\r
+                               elems = new Data[num.GetLength(0)];\r
+                               for (int i = 0; i < elems.GetLength(0); i++)\r
+                               {\r
+                                       elems[i].set(num[i][0], (int)num[i][1], (int)num[i][2]);\r
+                               }\r
+                       }\r
+               };\r
+\r
+\r
+\r
+               class BinomialLikelihoodThread\r
+               {\r
+                       public bool finished;\r
+                       public static bool started;\r
+                       internal Thread th;\r
+                       public static BinomialLikelihoodThread current;\r
+\r
+                       public Interval[] itvl;\r
+                       public double[] step;\r
+                       public double[] champ;\r
+                       public double champ_like;\r
+                       public BernoulliProcess data;\r
+\r
+\r
+                       public Constants.Func0 func0;\r
+                       public Constants.Func1 func1;\r
+                       public Constants.Func2 func2;\r
+                       public Constants.Func3 func3;\r
+                       public Constants.Func4 func4;\r
+                       public Constants.Func5 func5;\r
+\r
+\r
+                       public BinomialLikelihoodThread()\r
+                       {\r
+                               itvl = new Interval[CONST.MAX_ARG];\r
+                               step = new double[CONST.MAX_ARG];\r
+                               champ = new double[CONST.MAX_ARG];\r
+                               data = new BernoulliProcess();\r
+                       }\r
+                       public void waitLoop()\r
+                       {\r
+                               finished = false;\r
+                               for (int i = 0; i < CONST.MAX_ARG; i++)\r
+                               {\r
+                                       champ[i] = 0;\r
+                               }\r
+                               current = this;\r
+                               started = false;\r
+                       }\r
+\r
+                       public void loop1() { waitLoop(); th = new Thread(new ThreadStart(loop1_)); th.Start(); }\r
+                       public void loop2() { waitLoop(); th = new Thread(new ThreadStart(loop2_)); th.Start(); }\r
+                       public void loop3() { waitLoop(); th = new Thread(new ThreadStart(loop3_)); th.Start(); }\r
+                       public void loop4() { waitLoop(); th = new Thread(new ThreadStart(loop4_)); th.Start(); }\r
+                       public void loop5() { waitLoop(); th = new Thread(new ThreadStart(loop5_)); th.Start(); }\r
+                       void loop1_()\r
+                       {\r
+                               started = true;\r
+                               double p;\r
+                               double like = 1.0;\r
+                               champ_like=0.0;\r
+                               int L = data.length;\r
+                               for (double a = itvl[0].begin.value; a < itvl[0].end.value; a += step[0])\r
+                               {\r
+                                       like = 1.0;\r
+                                       for(int i=0; i<L; i++) {\r
+                                               p = func1(data.elems[i].x, a);\r
+                                               like *= Binomial.likelihood(p, data.elems[i].pos, data.elems[i].neg, data.elems[i].comb);\r
+                                       }\r
+                                       if(like > champ_like) {\r
+                                               champ_like = like;\r
+                                               champ[0] = a;\r
+                                       }\r
+                               }\r
+                               finished = true;\r
+                       }\r
+                       void loop2_()\r
+                       {\r
+                               started = true;\r
+                               double p = 0.0;\r
+                               double like = 1.0;\r
+                               champ_like = 0.0;\r
+                               int L = data.length;\r
+                               for (double a = itvl[0].begin.value; a < itvl[0].end.value; a += step[0])\r
+                               {\r
+                                       for (double b = itvl[1].begin.value; b < itvl[1].end.value; b += step[1])\r
+                                       {\r
+                                               like = 1.0;\r
+                                               for (int i = 0; i < L; i++)\r
+                                               {\r
+                                                       p = func2(data.elems[i].x, a, b);\r
+                                                       like *= Binomial.likelihood(p, data.elems[i].pos, data.elems[i].neg, data.elems[i].comb);\r
+                                               }\r
+                                               if (like > champ_like)\r
+                                               {\r
+                                                       champ_like = like;\r
+                                                       champ[0] = a;\r
+                                                       champ[1] = b;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               finished = true;\r
+                       }\r
+                       void loop3_()\r
+                       {\r
+                               started = true;\r
+                               double p;\r
+                               double like = 1.0;\r
+                               champ_like = 0.0;\r
+                               int L = data.length;\r
+                               for (double a = itvl[0].begin.value; a < itvl[0].end.value; a += step[0])\r
+                               {\r
+                                       for (double b = itvl[1].begin.value; b < itvl[1].end.value; b += step[1])\r
+                                       {\r
+                                               for (double c = itvl[2].begin.value; c < itvl[2].end.value; c += step[2])\r
+                                               {\r
+                                                       like = 1.0;\r
+                                                       for (int i = 0; i < L; i++)\r
+                                                       {\r
+                                                               p = func3(data.elems[i].x, a, b, c);\r
+                                                               like *= Binomial.likelihood(p, data.elems[i].pos, data.elems[i].neg, data.elems[i].comb);\r
+                                                       }\r
+                                                       if (like > champ_like)\r
+                                                       {\r
+                                                               champ_like = like;\r
+                                                               champ[0] = a;\r
+                                                               champ[1] = b;\r
+                                                               champ[1] = c;\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }\r
+                               finished = true;\r
+                       }\r
+                       void loop4_()\r
+                       {\r
+                               started = true;\r
+                               finished = true;\r
+                       }\r
+                       void loop5_()\r
+                       {\r
+                               started = true;\r
+                               finished = true;\r
+                       }\r
+               };\r
+\r
+\r
+\r
+               public class BinomialLikelihood\r
+               {\r
+                       /*\r
+                       public static void showWindow(Constants.Func1 f)\r
+                       {\r
+                               Main.canvas.api_canvas.Dispatcher.BeginInvoke(new Action<Constants.Func1>(showWindow_), f);\r
+                       }\r
+                       internal static void showWindow_(Constants.Func1 f)\r
+                       {\r
+                               System.Windows.Controls.ChildWindow page = new PsychlopsSilverlight4.Pages.BinomialSolver(f);\r
+                               page.Show();\r
+                       }\r
+                       public static void showWindow(Constants.Func2 f)\r
+                       {\r
+                               Main.canvas.api_canvas.Dispatcher.BeginInvoke(new Action<Constants.Func2>(showWindow_), f);\r
+                       }\r
+                       internal static void showWindow_(Constants.Func2 f)\r
+                       {\r
+                               System.Windows.Controls.ChildWindow page = new PsychlopsSilverlight4.Pages.BinomialSolver(f);\r
+                               page.Show();\r
+                       }\r
+                       public static void showWindow(Constants.Func3 f)\r
+                       {\r
+                               Main.canvas.api_canvas.Dispatcher.BeginInvoke(new Action<Constants.Func3>(showWindow_), f);\r
+                       }\r
+                       internal static void showWindow_(Constants.Func3 f)\r
+                       {\r
+                               System.Windows.Controls.ChildWindow page = new PsychlopsSilverlight4.Pages.BinomialSolver(f);\r
+                               page.Show();\r
+                       }\r
+                       */\r
+\r
+                       public int iteration;\r
+\r
+                       public Interval[] itvl;\r
+                       public double[] step;\r
+                       public double[] champ;\r
+                       public double champ_like;\r
+                       public BernoulliProcess data;\r
+\r
+                       public Constants.Func0 func0;\r
+                       public Constants.Func1 func1;\r
+                       public Constants.Func2 func2;\r
+                       public Constants.Func3 func3;\r
+                       public Constants.Func4 func4;\r
+                       public Constants.Func5 func5;\r
+\r
+                       public BinomialLikelihood()\r
+                       {\r
+                               itvl = new Interval[CONST.MAX_ARG];\r
+                               step = new double[CONST.MAX_ARG];\r
+                               champ = new double[CONST.MAX_ARG];\r
+                               iteration = 2;\r
+                       }\r
+\r
+                       public void begin(Constants.Func0 d_func)\r
+                       { }\r
+                       public void begin(Constants.Func1 d_func)\r
+                       {\r
+                               func1 = d_func;\r
+\r
+                               BinomialLikelihoodThread[] l = new BinomialLikelihoodThread[4];\r
+                               for (int i = 0; i < 4; i++) { l[i] = new BinomialLikelihoodThread(); }\r
+\r
+                               for (int k = 0; k < iteration; k++)\r
+                               {\r
+                                       begin_base(l);\r
+                                       for (int i = 0; i < 4; i++)\r
+                                       {\r
+                                               l[i].data = data;\r
+                                               l[i].func1 = d_func;\r
+                                               l[i].loop1();\r
+                                       }\r
+                                       end_base(l);\r
+                               }\r
+                       }\r
+                       public void begin(Constants.Func2 d_func)\r
+                       {\r
+                               func2 = d_func;\r
+\r
+                               BinomialLikelihoodThread[] l = new BinomialLikelihoodThread[4];\r
+                               for (int i = 0; i < 4; i++) { l[i] = new BinomialLikelihoodThread(); }\r
+\r
+                               for (int k = 0; k < iteration; k++)\r
+                               {\r
+                                       begin_base(l);\r
+                                       for (int i = 0; i < 4; i++)\r
+                                       {\r
+                                               l[i].data = data;\r
+                                               l[i].func2 = d_func;\r
+                                               l[i].loop2();\r
+                                       }\r
+                                       end_base(l);\r
+                               }\r
+                       }\r
+                       public void begin(Constants.Func3 d_func)\r
+                       {\r
+                               func3 = d_func;\r
+\r
+                               BinomialLikelihoodThread[] l = new BinomialLikelihoodThread[4];\r
+                               for (int i = 0; i < 4; i++) { l[i] = new BinomialLikelihoodThread(); }\r
+\r
+                               for (int k = 0; k < iteration; k++)\r
+                               {\r
+                                       begin_base(l);\r
+                                       for(int i=0; i<4; i++) {\r
+                                               l[i].data = data;\r
+                                               l[i].func3 = d_func;\r
+                                               l[i].loop3();\r
+                                       }\r
+                                       end_base(l);\r
+                               }\r
+                       }\r
+\r
+                       public void begin(Constants.Func4 d_func)\r
+                       {\r
+                       }\r
+                       public void begin(Constants.Func5 d_func)\r
+                       {\r
+                       }\r
+\r
+                       void begin_base(BinomialLikelihoodThread[] l)\r
+                       {\r
+                               champ_like = 0;\r
+\r
+                               data.length = data.elems.GetLength(0);\r
+                               for (int i = 0; i < data.elems.GetLength(0); i++)\r
+                               {\r
+                                       data.elems[i].comb = (int)Binomial.combination(data.elems[i].pos + data.elems[i].neg, data.elems[i].pos);\r
+                               }\r
+\r
+                               for (int j = 0; j < Constants.LIMIT; j++) { step[j] = (itvl[j].end.value - itvl[j].begin.value) / 256.0; }\r
+                               for (int i = 0; i < 4; i++)\r
+                               {\r
+                                       l[i].itvl[0] = new Interval((itvl[0].begin.value) + (i * step[0] * 64), (itvl[0].begin.value) + ((i + 1) * step[0] * 64));\r
+                                       l[i].step[0] = step[0];\r
+                                       for (int j = 1; j < Constants.LIMIT; j++)\r
+                                       {\r
+                                               l[i].itvl[j] = itvl[j];\r
+                                               l[i].step[j] = step[j];\r
+                                       }\r
+                                       l[i].data = data;\r
+                               }\r
+                       }\r
+\r
+                       void end_base(BinomialLikelihoodThread[] l)\r
+                       {\r
+                               //for (int i = 0; i < 4; i++) { l[i].th.Join(); }\r
+                               while (!l[0].finished || !l[1].finished || !l[2].finished || !l[3].finished) { Thread.Sleep(100);  } \r
+\r
+                               for(int j=0; j<Constants.LIMIT; j++) { champ[j] = 0; }\r
+                               champ_like = 0.0;\r
+                               for(int i=0; i<4; i++) {\r
+                                       if(champ_like < l[i].champ_like) {\r
+                                               champ_like = l[i].champ_like;\r
+                                               for(int j=0; j<Constants.LIMIT; j++) { champ[j] = l[i].champ[j]; }\r
+                                       }\r
+                               }\r
+\r
+                               double r, low, high;\r
+                               for (int j = 0; j < Constants.LIMIT; j++)\r
+                               {\r
+                                       r = itvl[j].end.value - itvl[j].begin.value;\r
+                                       low = champ[j] - r / 8.0 < itvl[j].begin.value ? itvl[j].begin.value : champ[j] - r / 8.0;\r
+                                       high = champ[j] + r / 8.0 > itvl[j].end.value ? itvl[j].end.value : champ[j] + r / 8.0;\r
+                                       itvl[j] = new Interval(low, high);\r
+                               }\r
+\r
+                       }\r
+\r
+\r
+               }\r
+\r
+\r
+       }\r
+\r
+}
\ No newline at end of file
diff --git a/dev5/psychlops/extension/media/dom.cs b/dev5/psychlops/extension/media/dom.cs
new file mode 100644 (file)
index 0000000..a733682
--- /dev/null
@@ -0,0 +1,6 @@
+\r
+namespace Psychlops\r
+{\r
+\r
+\r
+}
\ No newline at end of file
diff --git a/dev5/psychlops/extension/media/svg.cs b/dev5/psychlops/extension/media/svg.cs
new file mode 100644 (file)
index 0000000..b2558b7
--- /dev/null
@@ -0,0 +1,8 @@
+\r
+namespace Psychlops\r
+{\r
+\r
+\r
+\r
+\r
+}
\ No newline at end of file
diff --git a/dev5/psychlops/extension/standard/CIEColor.cs b/dev5/psychlops/extension/standard/CIEColor.cs
new file mode 100644 (file)
index 0000000..50df53c
--- /dev/null
@@ -0,0 +1,108 @@
+using System;\r
+\r
+namespace Psychlops\r
+{\r
+       namespace ColorSpaces\r
+       {\r
+               /*\r
+                * CIE 1931\r
+                * R: 700 nm\r
+                * G: 546.1 nm\r
+                * B: 435.8 nm\r
+                * White Point: Illuminant E\r
+                */\r
+               public struct CIERGB\r
+               {\r
+                       public double R, G, B;\r
+\r
+                       public CIEXYZ convertToCIEXYZ()\r
+                       {\r
+                               double[,] b =\r
+                       { \r
+                               { 0.49, 0.31, 0.20 },\r
+                               { 0.17697, 0.81240, 0.01063 },\r
+                               { 0.00, 0.01, 0.99 }\r
+                       };\r
+\r
+                               CIEXYZ v;\r
+\r
+                               v.X = b[0, 0] * R + b[0, 1] * G + b[0, 2] * B;\r
+                               v.Y = b[1, 0] * R + b[1, 1] * G + b[1, 2] * B;\r
+                               v.Z = b[2, 0] * R + b[2, 1] * G + b[2, 2] * B;\r
+\r
+                               return v;\r
+                       }\r
+               }\r
+\r
+               /*\r
+                * CIE 1931\r
+                */\r
+               public struct CIEXYZ\r
+               {\r
+                       public double X, Y, Z;\r
+\r
+                       public CIExyY convertToCIExyY()\r
+                       {\r
+                               CIExyY v;\r
+\r
+                               double denominator = X + Y + Z;\r
+                               v.x = X / denominator;\r
+                               v.y = Y / denominator;\r
+                               v.Y = Y;\r
+\r
+                               return v;\r
+                       }\r
+               }\r
+\r
+               public struct CIExyY\r
+               {\r
+                       public double x, y, Y;\r
+\r
+                       public CIEXYZ convertToCIEXYZ()\r
+                       {\r
+                               CIEXYZ v;\r
+\r
+                               v.X = Y / y * x;\r
+                               v.Y = Y;\r
+                               v.Z = Y / y * (1 - x - y);\r
+\r
+                               return v;\r
+                       }\r
+\r
+                       // Yn = 1.0 when RGB of white point is { 1, 1, 1 }\r
+                       public CIELuv convertToCIELuv(double Yn = 1.0)\r
+                       {\r
+\r
+                               CIELuv v;\r
+\r
+                               double denominator = (-2 * x + 12 * y + 3);\r
+                               double up = 4 * x / denominator;\r
+                               double vp = 9 * y / denominator;\r
+\r
+                               double Yd = Y / Yn;\r
+                               v.L = Yd > System.Math.Pow(6 / 29, 3) ? 116 * System.Math.Pow(Yd, 3) : System.Math.Pow(29 / 3, 3) * Yd;\r
+                               v.u = 13 * v.L * (up - 0.2009);\r
+                               v.v = 13 * v.L * (vp - 0.4610);\r
+\r
+                               return v;\r
+                       }\r
+               }\r
+\r
+               /* L*u*v*\r
+                * CIE 1976\r
+                * standard illuminant C\r
+                */\r
+               public struct CIELuv\r
+               {\r
+                       public double L, u, v;\r
+\r
+               }\r
+\r
+               public struct CIELab\r
+               {\r
+                       public double L, a, b;\r
+\r
+               }\r
+\r
+       }\r
+}
\ No newline at end of file
diff --git a/dev5/psychlops/extension/standard/figures.cs b/dev5/psychlops/extension/standard/figures.cs
new file mode 100644 (file)
index 0000000..948aecc
--- /dev/null
@@ -0,0 +1,43 @@
+\r
+using System.Windows.Media.Imaging;\r
+namespace Psychlops\r
+{\r
+\r
+    public static partial class Figures\r
+    {\r
+\r
+               public static void drawGrating(ref Image img, int width, int height, double wavelength, double contrast, double orientation, double phase)\r
+           {\r
+                       double width_half = width / 2.0, height_half = height / 2.0;\r
+            if (img==null || img.width != width || img.height != height)\r
+                img = new Image(width, height);\r
+            double freq = 2 * Math.PI / wavelength;\r
+                       img.field(\r
+                               (x, y) => new Color(.5 + contrast * .5 * Math.sin(phase + (Math.sin(orientation)*x-Math.cos(orientation)*y) * freq))\r
+                       );\r
+           }\r
+               public static void drawGaussian(ref Image img, double sigma, double factor)\r
+               {\r
+                       int width = (int)(sigma * 8), height = (int)(sigma * 8);\r
+                       double width_half = width / 2.0, height_half = height / 2.0;\r
+                       if (img == null || img.width != width || img.height != height)\r
+                               img = new Image(width, height);\r
+                       img.field(\r
+                               (x, y) => new Color(factor * Math.gaussian(Math.radius(x - width_half, y - height_half), width / 8.0))\r
+                       );\r
+               }\r
+\r
+               public static void drawGabor(ref Image img, double sigma, double frequency, double contrast, double orientation, double phase)\r
+           {\r
+            int width = (int)(sigma * 8), height = (int)(sigma * 8);\r
+                       double width_half = width / 2.0, height_half = height / 2.0;\r
+            if (img==null || img.width != width || img.height != height)\r
+                img = new Image(width, height);\r
+            double freq = 2 * Math.PI * frequency;\r
+                       img.field(\r
+                               (x, y) => new Color(.5 + contrast * Math.gaussian(Math.radius(x - width_half, y - height_half), width / 8.0) * .5 * Math.sin(phase + (Math.sin(orientation) * x - Math.cos(orientation) * y) * freq))\r
+                       );\r
+           }\r
+\r
+    }\r
+}\r
diff --git a/dev5/psychlops/extension/standard/shader.cs b/dev5/psychlops/extension/standard/shader.cs
new file mode 100644 (file)
index 0000000..7d5387a
--- /dev/null
@@ -0,0 +1,845 @@
+//------------------------------------------------------------------------------\r
+// <auto-generated>\r
+//     このコードはツールによって生成されました。\r
+//     ランタイム バージョン:4.0.30319.1\r
+//\r
+//     このファイルへの変更は、以下の状況下で不正な動作の原因になったり、\r
+//     コードが再生成されるときに損失したりします。\r
+// </auto-generated>\r
+//------------------------------------------------------------------------------\r
+\r
+using System;\r
+using System.Windows;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Effects;\r
+using System.Windows.Media.Media3D;\r
+\r
+\r
+namespace Psychlops\r
+{\r
+\r
+\r
+       public static partial class Figures\r
+       {\r
+\r
+               public class ShaderGrating : ShaderField\r
+               {\r
+                       protected Shader.GratingProgram ps = null;\r
+                       public ShaderGrating()\r
+                       {\r
+                               initialize__ = initialize___;\r
+                               setParameters = setParameters__;\r
+                       }\r
+                       internal void initialize()\r
+                       {\r
+                               if (!initialized)\r
+                               {\r
+                                       Main.canvas.beginInvoke(initialize___);\r
+                                       initialized = true;\r
+                               }\r
+                       }\r
+                       internal void initialize___()\r
+                       {\r
+                               if (!initialized)\r
+                               {\r
+                                       if (ps == null)\r
+                                       {\r
+                                               ps = new Shader.GratingProgram();\r
+                                               initializeShader();\r
+                                       }\r
+                                       shader = ps;\r
+                                       initialized = true;\r
+                               }\r
+                       }\r
+\r
+                       public double contrast = 1.0, wavelength = 20.0, phase = 0.0, orientation = 0.0;\r
+                       public ShaderGrating setSize(double s) { set(s, s); return this; }\r
+                       public ShaderGrating setSize(double h, double v) { set(h, v); return this; }\r
+\r
+                       public void setParameters__()\r
+                       {\r
+                               ps.Contrast = contrast;\r
+                               ps.WaveLength = wavelength;\r
+                               ps.Phase = phase;\r
+                               ps.Orientation = orientation;\r
+                               ps.SizeH = width;\r
+                               ps.SizeV = height;\r
+                               ps.Update();\r
+                       }\r
+\r
+\r
+               }\r
+\r
+\r
+               public class ShaderPlaid : ShaderField\r
+               {\r
+                       protected Shader.PlaidProgram ps = null;\r
+                       public ShaderPlaid()\r
+                       {\r
+                               initialize__ = initialize___;\r
+                               setParameters = setParameters__;\r
+                       }\r
+                       internal void initialize()\r
+                       {\r
+                               if (!initialized)\r
+                               {\r
+                                       Main.canvas.beginInvoke(initialize___);\r
+                                       initialized = true;\r
+                               }\r
+                       }\r
+                       internal void initialize___()\r
+                       {\r
+                               if (!initialized)\r
+                               {\r
+                                       if (ps == null)\r
+                                       {\r
+                                               ps = new Shader.PlaidProgram();\r
+                                               initializeShader();\r
+                                       }\r
+                                       shader = ps;\r
+                                       initialized = true;\r
+                               }\r
+                       }\r
+\r
+                       public double contrast = 0.5, wavelength = 20.0, phase = 0.0, orientation = 0.0;\r
+                       public double contrast2 = 0.5, wavelength2 = 20.0, phase2 = 0.0, orientation2 = Math.PI / 4;\r
+                       public ShaderPlaid setSize(double s) { set(s, s); return this; }\r
+                       public ShaderPlaid setSize(double h, double v) { set(h, v); return this; }\r
+\r
+                       public void setParameters__()\r
+                       {\r
+                               ps.Contrast = contrast;\r
+                               ps.WaveLength = wavelength;\r
+                               ps.Phase = phase;\r
+                               ps.Orientation = orientation;\r
+                               ps.Size = width;\r
+                               ps.Contrast2 = contrast;\r
+                               ps.WaveLength2 = wavelength;\r
+                               ps.Phase2 = phase;\r
+                               ps.Orientation2 = orientation;\r
+                               ps.SizeH = width;\r
+                               ps.SizeV = height;\r
+                               ps.Update();\r
+                       }\r
+\r
+\r
+               }\r
+\r
+\r
+               public class ShaderGabor : ShaderField\r
+               {\r
+                       protected Shader.GaborProgram ps = null;\r
+                       public ShaderGabor()\r
+                       {\r
+                               initialize__ = initialize___;\r
+                               setParameters = setParameters__;\r
+                       }\r
+                       internal void initialize()\r
+                       {\r
+                               if (!initialized)\r
+                               {\r
+                                       Main.canvas.beginInvoke(initialize___);\r
+                                       initialized = true;\r
+                               }\r
+                       }\r
+                       internal void initialize___()\r
+                       {\r
+                               if (!initialized)\r
+                               {\r
+                                       if (ps == null)\r
+                                       {\r
+                                               ps = new Shader.GaborProgram();\r
+                                               initializeShader();\r
+                                       }\r
+                                       shader = ps;\r
+                                       initialized = true;\r
+                               }\r
+                       }\r
+\r
+                       //public double contrast { get; set; }\r
+                       //public double frequency { get; set; }\r
+                       //public double phase { get; set; }\r
+                       //public double orientation { get; set; }\r
+                       public double contrast = 1.0, wavelength = 20.0, phase = 0.0, orientation = 0.0, alpha = 1.0;\r
+                       public ShaderGabor setSigma(double s)\r
+                       {\r
+                               set(s*8, s*8);\r
+                               return this;\r
+                       }\r
+                       \r
+                       public void setParameters__()\r
+                       {\r
+                               ps.Contrast = contrast;\r
+                               ps.WaveLength = wavelength;\r
+                               ps.Phase = phase;\r
+                               ps.Orientation = orientation;\r
+                               ps.Sigma = 4.0;\r
+                               ps.Size = width;\r
+                               ps.Alpha = alpha;\r
+                               ps.Update();\r
+                       }\r
+\r
+\r
+               }\r
+\r
+\r
+               public class ShaderGaborAlpha : ShaderField\r
+               {\r
+                       protected Shader.GaborAlphaProgram ps = null;\r
+                       public ShaderGaborAlpha()\r
+                       {\r
+                               initialize__ = initialize___;\r
+                               setParameters = setParameters__;\r
+                       }\r
+                       internal void initialize()\r
+                       {\r
+                               if (!initialized)\r
+                               {\r
+                                       Main.canvas.beginInvoke(initialize___);\r
+                                       initialized = true;\r
+                               }\r
+                       }\r
+                       internal void initialize___()\r
+                       {\r
+                               if (!initialized)\r
+                               {\r
+                                       if (ps == null)\r
+                                       {\r
+                                               ps = new Shader.GaborAlphaProgram();\r
+                                               initializeShader();\r
+                                       }\r
+                                       shader = ps;\r
+                                       initialized = true;\r
+                               }\r
+                       }\r
+\r
+                       //public double contrast { get; set; }\r
+                       //public double frequency { get; set; }\r
+                       //public double phase { get; set; }\r
+                       //public double orientation { get; set; }\r
+                       public double contrast = 1.0, wavelength = 20.0, phase = 0.0, orientation = 0.0, alpha = 1.0;\r
+                       public ShaderGaborAlpha setSigma(double s)\r
+                       {\r
+                               set(s * 8, s * 8);\r
+                               return this;\r
+                       }\r
+\r
+                       public void setParameters__()\r
+                       {\r
+                               ps.Contrast = contrast;\r
+                               ps.WaveLength = wavelength;\r
+                               ps.Phase = phase;\r
+                               ps.Orientation = orientation;\r
+                               ps.Sigma = 4.0;\r
+                               ps.Size = width;\r
+                               ps.Alpha = alpha;\r
+                               ps.Update();\r
+                       }\r
+\r
+\r
+               }\r
+       }\r
+\r
+\r
+       namespace Shader\r
+       {\r
+               internal static partial class Connector\r
+               {\r
+                       internal delegate void PixelShaderConnector(ShaderEffect q, Uri s);\r
+               }\r
+\r
+\r
+               public abstract class ShaderProgram : ShaderEffect\r
+               {\r
+               }\r
+\r
+               #region GratingProgram\r
+               public class GratingProgram : ShaderProgram\r
+               {\r
+                       public static readonly Uri ps = new Uri(@"/PsychlopsSilverlight5;component/Shader/Grating.ps", UriKind.Relative);\r
+\r
+                       public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GratingProgram), 0);\r
+                       public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(1D)), PixelShaderConstantCallback(1)));\r
+                       public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(100D)), PixelShaderConstantCallback(2)));\r
+                       public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(3)));\r
+                       public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(4)));\r
+                       public static readonly DependencyProperty SizeHProperty = DependencyProperty.Register("SizeH", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(32D)), PixelShaderConstantCallback(5)));\r
+                       public static readonly DependencyProperty SizeVProperty = DependencyProperty.Register("SizeV", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(32D)), PixelShaderConstantCallback(6)));\r
+                       public GratingProgram()\r
+                       {\r
+                               PixelShader pixelShader = new PixelShader();\r
+                               pixelShader.UriSource = ps;\r
+                               this.PixelShader = pixelShader;\r
+\r
+                               this.UpdateShaderValue(InputProperty);\r
+                               this.UpdateShaderValue(ContrastProperty);\r
+                               this.UpdateShaderValue(FrequencyProperty);\r
+                               this.UpdateShaderValue(PhaseProperty);\r
+                               this.UpdateShaderValue(OrientationProperty);\r
+                               this.UpdateShaderValue(SizeHProperty);\r
+                               this.UpdateShaderValue(SizeVProperty);\r
+\r
+                               Size = 200;\r
+                               Contrast = 1.0;\r
+                               WaveLength = 100.0;\r
+                               Orientation = 0.0;\r
+                               SizeH = 32.0;\r
+                               SizeV = 32.0;\r
+                       }\r
+\r
+                       public void Update()\r
+                       {\r
+                               this.UpdateShaderValue(InputProperty);\r
+                               this.UpdateShaderValue(ContrastProperty);\r
+                               this.UpdateShaderValue(FrequencyProperty);\r
+                               this.UpdateShaderValue(PhaseProperty);\r
+                               this.UpdateShaderValue(OrientationProperty);\r
+                               this.UpdateShaderValue(SizeHProperty);\r
+                               this.UpdateShaderValue(SizeVProperty);\r
+                       }\r
+\r
+\r
+                       private double size__, wavelength__;\r
+                       public double Size { get { return size__; } set { size__ = value; setFrequency(); } }\r
+                       private void setFrequency()\r
+                       {\r
+                               double freq = size__ * 2.0 * Math.PI / (wavelength__);\r
+                               this.SetValue(FrequencyProperty, freq);\r
+                       }\r
+\r
+                       /// <summary>Amplitude of Grating</summary>\r
+                       public double Contrast\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(ContrastProperty))) * 2.0;\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(ContrastProperty, value / 2.0);\r
+                               }\r
+                       }\r
+                       /// <summary>Phase of Grating</summary>\r
+                       public double WaveLength\r
+                       {\r
+                               get\r
+                               {\r
+                                       return wavelength__;\r
+                               }\r
+                               set\r
+                               {\r
+                                       wavelength__ = value;\r
+                                       setFrequency();\r
+                               }\r
+                       }\r
+                       /// <summary>Phase of Grating</summary>\r
+                       public double Phase\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(PhaseProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(PhaseProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Orientation of Grating</summary>\r
+                       public double Orientation\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(OrientationProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(OrientationProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Width of envelope</summary>\r
+                       public double SizeH\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(SizeHProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(SizeHProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Height of Figure</summary>\r
+                       public double SizeV\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(SizeVProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(SizeVProperty, value);\r
+                               }\r
+                       }\r
+               }\r
+               #endregion\r
+\r
+               #region PlaidProgram\r
+               public class PlaidProgram : ShaderProgram\r
+               {\r
+                       public static readonly Uri ps = new Uri(@"/PsychlopsSilverlight5;component/Shader/Plaid.ps", UriKind.Relative);\r
+\r
+                       public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(PlaidProgram), 0);\r
+                       public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0.5D)), PixelShaderConstantCallback(1)));\r
+                       public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(100D)), PixelShaderConstantCallback(2)));\r
+                       public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(3)));\r
+                       public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(4)));\r
+                       public static readonly DependencyProperty Contrast2Property = DependencyProperty.Register("Contrast2", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0.5D)), PixelShaderConstantCallback(5)));\r
+                       public static readonly DependencyProperty Frequency2Property = DependencyProperty.Register("Frequency2", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(100D)), PixelShaderConstantCallback(6)));\r
+                       public static readonly DependencyProperty Phase2Property = DependencyProperty.Register("Phase2", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(7)));\r
+                       public static readonly DependencyProperty Orientation2Property = DependencyProperty.Register("Orientation2", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0.785398D)), PixelShaderConstantCallback(8)));\r
+                       public static readonly DependencyProperty SizeHProperty = DependencyProperty.Register("SizeH", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(32D)), PixelShaderConstantCallback(9)));\r
+                       public static readonly DependencyProperty SizeVProperty = DependencyProperty.Register("SizeV", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(32D)), PixelShaderConstantCallback(10)));\r
+                       public PlaidProgram()\r
+                       {\r
+                               PixelShader pixelShader = new PixelShader();\r
+                               pixelShader.UriSource = ps;\r
+                               this.PixelShader = pixelShader;\r
+\r
+                               this.UpdateShaderValue(InputProperty);\r
+                               this.UpdateShaderValue(ContrastProperty);\r
+                               this.UpdateShaderValue(FrequencyProperty);\r
+                               this.UpdateShaderValue(PhaseProperty);\r
+                               this.UpdateShaderValue(OrientationProperty);\r
+                               this.UpdateShaderValue(Contrast2Property);\r
+                               this.UpdateShaderValue(Frequency2Property);\r
+                               this.UpdateShaderValue(Phase2Property);\r
+                               this.UpdateShaderValue(Orientation2Property);\r
+                               this.UpdateShaderValue(SizeHProperty);\r
+                               this.UpdateShaderValue(SizeVProperty);\r
+\r
+                               Size = 200;\r
+                               Contrast = 0.5;\r
+                               WaveLength = 100.0;\r
+                               Phase = 0.0;\r
+                               Orientation = 0.0;\r
+                               Contrast2 = 0.5;\r
+                               WaveLength2 = 100.0;\r
+                               Phase2 = 0.0;\r
+                               Orientation2 = Math.PI/4;\r
+                               SizeH = 32.0;\r
+                               SizeV = 32.0;\r
+                       }\r
+\r
+                       public void Update()\r
+                       {\r
+                               this.UpdateShaderValue(InputProperty);\r
+                               this.UpdateShaderValue(ContrastProperty);\r
+                               this.UpdateShaderValue(FrequencyProperty);\r
+                               this.UpdateShaderValue(PhaseProperty);\r
+                               this.UpdateShaderValue(OrientationProperty);\r
+                               this.UpdateShaderValue(Contrast2Property);\r
+                               this.UpdateShaderValue(Frequency2Property);\r
+                               this.UpdateShaderValue(Phase2Property);\r
+                               this.UpdateShaderValue(Orientation2Property);\r
+                               this.UpdateShaderValue(SizeHProperty);\r
+                               this.UpdateShaderValue(SizeVProperty);\r
+                       }\r
+\r
+\r
+                       private double size__, wavelength__, wavelength2__;\r
+                       public double Size { get { return size__; } set { size__ = value; setFrequency(); } }\r
+                       private void setFrequency()\r
+                       {\r
+                               double freq = size__ * 2.0 * Math.PI / (wavelength__);\r
+                               this.SetValue(FrequencyProperty, freq);\r
+                               double freq2 = size__ * 2.0 * Math.PI / (wavelength2__);\r
+                               this.SetValue(Frequency2Property, freq);\r
+                       }\r
+\r
+                       /// <summary>Amplitude of Grating</summary>\r
+                       public double Contrast\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(ContrastProperty))) * 2.0;\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(ContrastProperty, value / 2.0);\r
+                               }\r
+                       }\r
+                       /// <summary>Phase of Grating</summary>\r
+                       public double WaveLength\r
+                       {\r
+                               get\r
+                               {\r
+                                       return wavelength__;\r
+                               }\r
+                               set\r
+                               {\r
+                                       wavelength__ = value;\r
+                                       setFrequency();\r
+                               }\r
+                       }\r
+                       /// <summary>Phase of Grating</summary>\r
+                       public double Phase\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(PhaseProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(PhaseProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Orientation of Grating</summary>\r
+                       public double Orientation\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(OrientationProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(OrientationProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Amplitude of Grating</summary>\r
+                       public double Contrast2\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(Contrast2Property))) * 2.0;\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(Contrast2Property, value / 2.0);\r
+                               }\r
+                       }\r
+                       /// <summary>Phase of Grating</summary>\r
+                       public double WaveLength2\r
+                       {\r
+                               get\r
+                               {\r
+                                       return wavelength2__;\r
+                               }\r
+                               set\r
+                               {\r
+                                       wavelength2__ = value;\r
+                                       setFrequency();\r
+                               }\r
+                       }\r
+                       /// <summary>Phase2 of Grating</summary>\r
+                       public double Phase2\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(Phase2Property)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(Phase2Property, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Orientation2 of Grating</summary>\r
+                       public double Orientation2\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(Orientation2Property)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(Orientation2Property, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Width of envelope</summary>\r
+                       public double SizeH\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(SizeHProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(SizeHProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Height of Figure</summary>\r
+                       public double SizeV\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(SizeVProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(SizeVProperty, value);\r
+                               }\r
+                       }\r
+               }\r
+               #endregion\r
+\r
+               #region GaborProgram\r
+               public class GaborProgram : ShaderProgram\r
+               {\r
+                       public static readonly Uri ps = new Uri(@"/PsychlopsSilverlight5;component/Shader/Gabor.ps", UriKind.Relative);\r
+\r
+                       public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GaborProgram), 0);\r
+                       public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(GaborProgram), new PropertyMetadata(((double)(1D)), PixelShaderConstantCallback(1)));\r
+                       public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(GaborProgram), new PropertyMetadata(((double)(100D)), PixelShaderConstantCallback(2)));\r
+                       public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(GaborProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(3)));\r
+                       public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(double), typeof(GaborProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(4)));\r
+                       public static readonly DependencyProperty SigmaProperty = DependencyProperty.Register("Sigma", typeof(double), typeof(GaborProgram), new PropertyMetadata(((double)(4D)), PixelShaderConstantCallback(5)));\r
+                       public static readonly DependencyProperty AlphaProperty = DependencyProperty.Register("Alpha", typeof(double), typeof(GaborProgram), new PropertyMetadata(((double)(1D)), PixelShaderConstantCallback(6)));\r
+                       public GaborProgram()\r
+                       {\r
+                               PixelShader pixelShader = new PixelShader();\r
+                               pixelShader.UriSource = ps;\r
+                               this.PixelShader = pixelShader;\r
+\r
+                               this.UpdateShaderValue(InputProperty);\r
+                               this.UpdateShaderValue(ContrastProperty);\r
+                               this.UpdateShaderValue(FrequencyProperty);\r
+                               this.UpdateShaderValue(PhaseProperty);\r
+                               this.UpdateShaderValue(OrientationProperty);\r
+                               this.UpdateShaderValue(SigmaProperty);\r
+                               this.UpdateShaderValue(AlphaProperty);\r
+\r
+                               Size = 200;\r
+                               Contrast = 1.0;\r
+                               WaveLength = 100.0;\r
+                               Orientation = 0.0;\r
+                               Sigma = 4.0;\r
+                               Alpha = 1.0;\r
+                       }\r
+\r
+                       public void Update()\r
+                       {\r
+                               this.UpdateShaderValue(InputProperty);\r
+                               this.UpdateShaderValue(ContrastProperty);\r
+                               this.UpdateShaderValue(FrequencyProperty);\r
+                               this.UpdateShaderValue(PhaseProperty);\r
+                               this.UpdateShaderValue(OrientationProperty);\r
+                               this.UpdateShaderValue(SigmaProperty);\r
+                               this.UpdateShaderValue(AlphaProperty);\r
+                       }\r
+\r
+\r
+                       private double size__, wavelength__;\r
+                       public double Size { get { return size__; } set { size__ = value; setFrequency(); } }\r
+                       private void setFrequency()\r
+                       {\r
+                               double freq = size__ * 2.0 * Math.PI / (wavelength__);\r
+                               this.SetValue(FrequencyProperty, freq);\r
+                       }\r
+\r
+                       /// <summary>Amplitude of Grating</summary>\r
+                       public double Contrast\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(ContrastProperty))) * 2.0;\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(ContrastProperty, value / 2.0);\r
+                               }\r
+                       }\r
+                       /// <summary>Phase of Grating</summary>\r
+                       public double WaveLength\r
+                       {\r
+                               get\r
+                               {\r
+                                       return wavelength__;\r
+                               }\r
+                               set\r
+                               {\r
+                                       wavelength__ = value;\r
+                                       setFrequency();\r
+                               }\r
+                       }\r
+                       /// <summary>Phase of Grating</summary>\r
+                       public double Phase\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(PhaseProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(PhaseProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Orientation of Grating</summary>\r
+                       public double Orientation\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(OrientationProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(OrientationProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Half bandwidth of envelope</summary>\r
+                       public double Sigma\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(SigmaProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(SigmaProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Transparency of Figure</summary>\r
+                       public double Alpha\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(AlphaProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(AlphaProperty, value);\r
+                               }\r
+                       }\r
+               }\r
+               #endregion\r
+\r
+               #region GaborAlphaProgram\r
+               public class GaborAlphaProgram : ShaderProgram\r
+               {\r
+                       public static readonly Uri ps = new Uri(@"/PsychlopsSilverlight5;component/Shader/GaborAlpha.ps", UriKind.Relative);\r
+\r
+                       public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GaborAlphaProgram), 0);\r
+                       public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(1D)), PixelShaderConstantCallback(1)));\r
+                       public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(100D)), PixelShaderConstantCallback(2)));\r
+                       public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(3)));\r
+                       public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(4)));\r
+                       public static readonly DependencyProperty SigmaProperty = DependencyProperty.Register("Sigma", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(4D)), PixelShaderConstantCallback(5)));\r
+                       public static readonly DependencyProperty AlphaProperty = DependencyProperty.Register("Alpha", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(1D)), PixelShaderConstantCallback(6)));\r
+                       public GaborAlphaProgram()\r
+                       {\r
+                               PixelShader pixelShader = new PixelShader();\r
+                               pixelShader.UriSource = ps;\r
+                               this.PixelShader = pixelShader;\r
+\r
+                               this.UpdateShaderValue(InputProperty);\r
+                               this.UpdateShaderValue(ContrastProperty);\r
+                               this.UpdateShaderValue(FrequencyProperty);\r
+                               this.UpdateShaderValue(PhaseProperty);\r
+                               this.UpdateShaderValue(OrientationProperty);\r
+                               this.UpdateShaderValue(SigmaProperty);\r
+                               this.UpdateShaderValue(AlphaProperty);\r
+\r
+                               Size = 200;\r
+                               Contrast = 1.0;\r
+                               WaveLength = 100.0;\r
+                               Orientation = 0.0;\r
+                               Sigma = 4.0;\r
+                               Alpha = 1.0;\r
+                       }\r
+\r
+                       public void Update()\r
+                       {\r
+                               this.UpdateShaderValue(InputProperty);\r
+                               this.UpdateShaderValue(ContrastProperty);\r
+                               this.UpdateShaderValue(FrequencyProperty);\r
+                               this.UpdateShaderValue(PhaseProperty);\r
+                               this.UpdateShaderValue(OrientationProperty);\r
+                               this.UpdateShaderValue(SigmaProperty);\r
+                               this.UpdateShaderValue(AlphaProperty);\r
+                       }\r
+\r
+\r
+                       private double size__, wavelength__;\r
+                       public double Size { get { return size__; } set { size__ = value; setFrequency(); } }\r
+                       private void setFrequency()\r
+                       {\r
+                               double freq = size__ * 2.0 * Math.PI / (wavelength__);\r
+                               this.SetValue(FrequencyProperty, freq);\r
+                       }\r
+\r
+                       /// <summary>Amplitude of Grating</summary>\r
+                       public double Contrast\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(ContrastProperty))) * 2.0;\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(ContrastProperty, value / 2.0);\r
+                               }\r
+                       }\r
+                       /// <summary>Phase of Grating</summary>\r
+                       public double WaveLength\r
+                       {\r
+                               get\r
+                               {\r
+                                       return wavelength__;\r
+                               }\r
+                               set\r
+                               {\r
+                                       wavelength__ = value;\r
+                                       setFrequency();\r
+                               }\r
+                       }\r
+                       /// <summary>Phase of Grating</summary>\r
+                       public double Phase\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(PhaseProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(PhaseProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Orientation of Grating</summary>\r
+                       public double Orientation\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(OrientationProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(OrientationProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Half bandwidth of envelope</summary>\r
+                       public double Sigma\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(SigmaProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(SigmaProperty, value);\r
+                               }\r
+                       }\r
+                       /// <summary>Transparency of Figure</summary>\r
+                       public double Alpha\r
+                       {\r
+                               get\r
+                               {\r
+                                       return ((double)(this.GetValue(AlphaProperty)));\r
+                               }\r
+                               set\r
+                               {\r
+                                       this.SetValue(AlphaProperty, value);\r
+                               }\r
+                       }\r
+               }\r
+               #endregion\r
+       \r
+       }\r
+}
\ No newline at end of file
diff --git a/dev5/psychlops/extension/standard/widget.cs b/dev5/psychlops/extension/standard/widget.cs
new file mode 100644 (file)
index 0000000..51d6087
--- /dev/null
@@ -0,0 +1,386 @@
+using System;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Animation;\r
+using System.Windows.Media.Imaging;\r
+using System.Windows.Shapes;\r
+using System.Windows.Browser;\r
+using System.Windows.Data;\r
+\r
+\r
+\r
+\r
+namespace Psychlops\r
+{\r
+\r
+       /*\r
+       class Widget : public Figure {\r
+       public:\r
+               class Event {\r
+               public:\r
+               };\r
+       };\r
+        * */\r
+\r
+       namespace Widgets\r
+       {\r
+               /*\r
+               struct Theme {\r
+                       static bool initialized__;\r
+                       static Image default_button, default_horiz_grad;\r
+                       enum TYPE_TAG { NORMAL, ALERT };\r
+                       public:\r
+                       Color normal_foreground[2], active_foreground[2];\r
+                       Color normal_background[2], active_background[2], over_background[2];\r
+                       Stroke normal_stroke[2], active_stroke[2];\r
+                       Image button_back, *horiz_grad;\r
+\r
+                       static Theme current;\r
+                       static void initialize();\r
+               };\r
+                * */\r
+\r
+               /*\r
+               class WidgetRect : Widget\r
+               {\r
+                       protected:\r
+                       HumanInterfaceDevice::ButtonStateHolder mleft;\r
+                       bool pushed_;\r
+\r
+                       public:\r
+                       //Theme *theme;\r
+                       //Theme::TYPE_TAG theme_type;\r
+                       public Rectangle area;\r
+                       public Letters label;\r
+\r
+                       public abstract WidgetRect();\r
+                       public virtual const Point getDatum() const;\r
+                       public virtual WidgetRect& setDatum(const Point&);\r
+                       public virtual WidgetRect& centering(const Point&);\r
+                       public double getWidth() const;\r
+                       public double getHeight() const;\r
+                       public double getLeft() const;\r
+                       public double getTop() const;\r
+                       public double getRight() const;\r
+                       public double getBottom() const;\r
+                       public WidgetRect& alignLeft(const double lef);\r
+                       public WidgetRect& alignTop(const double to_);\r
+                       public WidgetRect& alignRight(const double rig);\r
+                       public WidgetRect& alignBottom(const double bot);\r
+\r
+                       public virtual WidgetRect& set(double wid, double hei);\r
+                       public virtual WidgetRect& set(std::wstring name);\r
+                       public virtual WidgetRect& set(std::wstring name, double hei);\r
+                       public virtual WidgetRect& setLabel(std::wstring s);\r
+                       public virtual WidgetRect& draw(Drawable &target = *Drawable::prime);\r
+                       public bool pushed();\r
+                       public WidgetRect& pushThis();\r
+               };\r
+               */\r
+               \r
+               /*\r
+               public class Slider\r
+               {\r
+                       public string label;\r
+                       public Rectangle outer;\r
+                       public Rectangle inner;\r
+                       public Stroke outer_strk;\r
+\r
+                       public Slider()\r
+                       {\r
+                               set(0, 0);\r
+                       }\r
+                       public Slider(double width, double height)\r
+                       {\r
+                               set(width, height);\r
+                       }\r
+                       public Slider set(double width, double height)\r
+                       {\r
+                               outer = new Rectangle(width, height);\r
+                               outer.fill = Color.gray;\r
+                               inner = new Rectangle();\r
+                               inner.fill = Color.blue;\r
+                               outer_strk = new Stroke();\r
+                               outer_strk.color = Color.white;\r
+                               outer_strk.thick = 1;\r
+                               return this;\r
+                       }\r
+                       public void checkClick()\r
+                       {\r
+                               if (outer.include(Mouse.position))\r
+                               {\r
+                                       outer.stroke = outer_strk;\r
+                               }\r
+                       }\r
+               }\r
+                */\r
+\r
+               public class Button\r
+               {\r
+                       public static Color bgcolor;\r
+\r
+                       internal System.Windows.Controls.Button uibutton;\r
+\r
+                       public Button(string l)\r
+                       {\r
+                               uibutton = new System.Windows.Controls.Button();\r
+                               uibutton.Content = l;\r
+                       }\r
+                       public void str(string l) { }\r
+               }\r
+\r
+               public class Slider\r
+               {\r
+                       public static Color bgcolor;\r
+\r
+                       internal System.Windows.UIElement instance;\r
+                       internal System.Windows.Controls.Slider uislider;\r
+                       internal System.Windows.Controls.TextBlock uilabel;\r
+                       internal System.Windows.Controls.TextBox uibox;\r
+                       internal string label;\r
+                       internal Interval range;\r
+                       internal SelfDelegate get_;\r
+                       internal SelfDelegate set_;\r
+                       internal double retval, small_step, large_step;\r
+                       internal bool setted_;\r
+\r
+                       static Slider()\r
+                       {\r
+                               bgcolor.set(.5,.5, .5, .3);\r
+                       }\r
+\r
+                       public Slider(string l, Interval r, double initialvalue)\r
+                       {\r
+                               retval = initialvalue;\r
+                               range = r;\r
+                               label = l;\r
+                               large_step = Double.NaN;\r
+                               small_step = Double.NaN;\r
+                               setted_ = false;\r
+                               Psychlops.Widgets.Connector.stackSlider(this);\r
+                               get_ = new SelfDelegate(get__);\r
+                               set_ = new SelfDelegate(set__);\r
+                               while (!setted_) { System.Threading.Thread.Sleep(10); }\r
+                       }\r
+                       public Slider(string l, Interval r, double step1, double step2)\r
+                       {\r
+                               retval = r.begin.value;\r
+                               range = r;\r
+                               label = l;\r
+                               large_step = Math.max(step1, step2);\r
+                               small_step = Math.min(step1, step2);\r
+                               setted_ = false;\r
+                               Psychlops.Widgets.Connector.stackSlider(this);\r
+                               get_ = new SelfDelegate(get__);\r
+                               set_ = new SelfDelegate(set__);\r
+                               while (!setted_) { System.Threading.Thread.Sleep(10); }\r
+                       }\r
+                       public static implicit operator double(Slider s)\r
+                       {\r
+                               return s.value;\r
+                       }\r
+\r
+                       public delegate void SelfDelegate(System.Windows.Controls.Slider s);\r
+                       public void get__(System.Windows.Controls.Slider s) { retval = s.Value; }\r
+                       public void set__(System.Windows.Controls.Slider s) { s.Value = retval; }\r
+\r
+                       public double getValue()\r
+                       {\r
+                               if (uislider != null) {\r
+                                       uislider.Dispatcher.BeginInvoke(get_, uislider);\r
+                                       return retval;\r
+                               } else {\r
+                                       return 0;\r
+                               }\r
+                       }\r
+                       public void setValue(double v)\r
+                       {\r
+                               if (uislider != null)\r
+                               {\r
+                                       retval = v;\r
+                                       uislider.Dispatcher.BeginInvoke(set_, uislider);\r
+                               }\r
+                       }\r
+\r
+                       public double value\r
+                       {\r
+                               get { return getValue(); }\r
+                               set { setValue(value); }\r
+                       }\r
+                       public bool changed { get; set; }\r
+               }\r
+\r
+\r
+               public class Browser\r
+               {\r
+                       public class Element\r
+                       {\r
+                               HtmlElement elem;\r
+                               System.Object retval;\r
+\r
+                               public Element()\r
+                               {\r
+                                       retval = 0;\r
+                               }\r
+\r
+                               public static Element byID(string id_tag)\r
+                               {\r
+                                       return getElementById(id_tag);\r
+                               }\r
+                               public static Element getElementById(string id_tag)\r
+                               {\r
+                                       Element tmp = new Element();\r
+                                       Internal.Main.widgetStack.Dispatcher.BeginInvoke(new Connector.VoidString(tmp.getElementById__), id_tag);\r
+                                       return tmp;\r
+                               }\r
+                               void getElementById__(string id_tag)\r
+                               {\r
+                                       elem = HtmlPage.Document.GetElementById(id_tag);\r
+                               }\r
+\r
+                               public void setProperty(string name, System.Object value)\r
+                               {\r
+                                       Internal.Main.widgetStack.Dispatcher.BeginInvoke(new Connector.VoidStringObject(setProperty__), name, value);\r
+                               }\r
+                               public void setProperty__(string name, System.Object value)\r
+                               {\r
+                                       elem.SetProperty(name, value);\r
+                               }\r
+\r
+\r
+                               public static implicit operator double(Element i) { return i.getValueAsDouble(); }\r
+                               public double getValueAsDouble()\r
+                               {\r
+                                       double v = 0;\r
+                                       getProperty("value");\r
+                                       try\r
+                                       {\r
+                                               v = double.Parse(retval.ToString());\r
+                                       }\r
+                                       catch (FormatException e)\r
+                                       {\r
+                                               v = 0;\r
+                                       }\r
+                                       return v;\r
+                               }\r
+\r
+                               public static implicit operator string(Element i) { return i.getProperty("value").ToString(); }\r
+                               public System.Object getProperty(string name)\r
+                               {\r
+                                       Internal.Main.widgetStack.Dispatcher.BeginInvoke(new Connector.VoidString(getProperty__), name);\r
+                                       return retval;\r
+                               }\r
+                               public void getProperty__(string name)\r
+                               {\r
+                                       retval = elem.GetProperty(name);\r
+                               }\r
+                       }\r
+               }\r
+\r
+\r
+               internal static partial class Connector\r
+               {\r
+                       internal delegate void VoidString(string s);\r
+                       internal delegate void VoidStringObject(String s, System.Object o);\r
+\r
+                       public class Double02fFormatter : IValueConverter\r
+                       {\r
+                               public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)\r
+                               {\r
+                                       string formatString = parameter as string;\r
+                                       if (!string.IsNullOrEmpty(formatString))\r
+                                       {\r
+                                               return string.Format(culture, formatString, value);\r
+                                       }\r
+                                       return string.Format("{0, -8:F}", value);\r
+                               }\r
+                               public object ConvertBack(object val, Type targetType, object parameter, System.Globalization.CultureInfo culture)\r
+                               {\r
+                                       string str = val.ToString();\r
+                                       double result;\r
+                                       var objCultureInfo = new System.Globalization.CultureInfo("en-US");\r
+                                       if (Double.TryParse(str, System.Globalization.NumberStyles.Number, objCultureInfo, out result))\r
+                                       {\r
+                                               return result;\r
+                                       }\r
+                                       return val;\r
+                               }\r
+                       }\r
+\r
+                       delegate void StackSlider_(Slider s);\r
+                       internal static void stackSlider(Slider s)\r
+                       {\r
+                               Internal.Main.widgetStack.Dispatcher.BeginInvoke(new StackSlider_(stackSlider__), s);\r
+                       }\r
+                       static void stackSlider__(Slider ss)\r
+                       {\r
+                               var label = new System.Windows.Controls.TextBlock { Text = ss.label };\r
+                               label.Foreground = Color.white;\r
+                               System.Windows.Controls.Canvas.SetLeft(label, 3);\r
+                               System.Windows.Controls.Canvas.SetTop(label, 3);\r
+                               ss.uilabel = label;\r
+\r
+                               var holder = new System.Windows.Controls.Canvas { Width = 200, Height = 50 };\r
+                               var val = new System.Windows.Controls.TextBox { Width = 100 };\r
+                               System.Windows.Controls.Canvas.SetLeft(val, 100);\r
+                               var slide = new System.Windows.Controls.Slider {\r
+                                               Minimum = ss.range.begin.value, Maximum = ss.range.end.value,\r
+                                               Name = ss.label,\r
+                                               Value = ss.retval,\r
+                                               Tag = ss, Width = 200,\r
+                               };\r
+                               if (!Double.IsNaN(ss.large_step))\r
+                               {\r
+                                       slide.LargeChange = ss.large_step;\r
+                               }\r
+                               if (!Double.IsNaN(ss.small_step))\r
+                               {\r
+                                       slide.SmallChange = ss.small_step;\r
+                               }\r
+                               slide.ValueChanged += slider_ValueChanged;\r
+                               System.Windows.Controls.Canvas.SetTop(slide, label.ActualHeight - 3);\r
+                               var b = new System.Windows.Data.Binding {\r
+                                               Path = new PropertyPath("Value"),\r
+                                               Mode = System.Windows.Data.BindingMode.TwoWay,\r
+                                               Source = slide,\r
+                                               Converter = new Double02fFormatter()\r
+                               };\r
+                               val.SetBinding(TextBox.TextProperty, b);\r
+                               ss.uislider = slide;\r
+                               ss.uibox = val;\r
+                               val.Background = Color.null_color;\r
+                               val.BorderBrush = Color.null_color;\r
+                               val.Foreground = Color.white;\r
+                               val.TextAlignment = TextAlignment.Right;\r
+\r
+                               holder.Background = Slider.bgcolor;\r
+\r
+                               holder.Children.Add(label);\r
+                               holder.Children.Add(val);\r
+                               holder.Children.Add(slide);\r
+                               holder.Height = label.ActualHeight + slide.ActualHeight + val.ActualHeight + 15;\r
+                               ss.instance = holder;\r
+                               Internal.Main.widgetStack.Children.Add(ss.instance);\r
+                               ss.setted_ = true;\r
+                       }\r
+                       private static void slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)\r
+                       {\r
+                               System.Windows.Controls.Slider sl = sender as System.Windows.Controls.Slider;\r
+                               if (sl != null)\r
+                               {\r
+                                       double rounded = Math.round((sl.Value - sl.Minimum) / sl.SmallChange) * sl.SmallChange;\r
+                                       if ((sl.Value - sl.Minimum) * sl.SmallChange != rounded)\r
+                                       {\r
+                                               sl.Value = rounded;\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+\r
+       }\r
+\r
+}\r
+\r
diff --git a/test4/App.xaml b/test4/App.xaml
new file mode 100644 (file)
index 0000000..f82402d
--- /dev/null
@@ -0,0 +1,8 @@
+<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\r
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" \r
+             x:Class="PsychlopsSilverlight4test.App"\r
+             >\r
+    <Application.Resources>\r
+        \r
+    </Application.Resources>\r
+</Application>\r
diff --git a/test4/App.xaml.cs b/test4/App.xaml.cs
new file mode 100644 (file)
index 0000000..e091cde
--- /dev/null
@@ -0,0 +1,66 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Net;\r
+using System.Windows;\r
+using System.Windows.Controls;\r
+using System.Windows.Documents;\r
+using System.Windows.Input;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Animation;\r
+using System.Windows.Shapes;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+       public partial class App : Application\r
+       {\r
+\r
+               public App()\r
+               {\r
+                       this.Startup += this.Application_Startup;\r
+                       this.Exit += this.Application_Exit;\r
+                       this.UnhandledException += this.Application_UnhandledException;\r
+\r
+                       InitializeComponent();\r
+               }\r
+\r
+               private void Application_Startup(object sender, StartupEventArgs e)\r
+               {\r
+                       this.RootVisual = new MainPage();\r
+               }\r
+\r
+               private void Application_Exit(object sender, EventArgs e)\r
+               {\r
+\r
+               }\r
+               private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)\r
+               {\r
+                       // アプリケーションがデバッガーの外側で実行されている場合、ブラウザーの\r
+                       // 例外メカニズムによって例外が報告されます。これにより、IE ではステータス バーに\r
+                       // 黄色の通知アイコンが表示され、Firefox にはスクリプト エラーが表示されます。\r
+                       if (!System.Diagnostics.Debugger.IsAttached)\r
+                       {\r
+\r
+                               // メモ : これにより、アプリケーションは例外がスローされた後も実行され続け、例外は\r
+                               // ハンドルされません。 \r
+                               // 実稼動アプリケーションでは、このエラー処理は、Web サイトにエラーを報告し、\r
+                               // アプリケーションを停止させるものに置換される必要があります。\r
+                               e.Handled = true;\r
+                               Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });\r
+                       }\r
+               }\r
+               private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)\r
+               {\r
+                       try\r
+                       {\r
+                               string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;\r
+                               errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");\r
+\r
+                               System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");\r
+                       }\r
+                       catch (Exception)\r
+                       {\r
+                       }\r
+               }\r
+       }\r
+}\r
diff --git a/test4/MainPage.xaml b/test4/MainPage.xaml
new file mode 100644 (file)
index 0000000..6487be3
--- /dev/null
@@ -0,0 +1,22 @@
+<UserControl x:Class="PsychlopsSilverlight4test.MainPage"\r
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" \r
+    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\r
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" \r
+    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">\r
+       <StackPanel x:Name="TotalRoot">\r
+               <Grid>\r
+                       <Grid.ColumnDefinitions>\r
+                               <ColumnDefinition Width="0" />\r
+                               <ColumnDefinition Width="*" />\r
+                       </Grid.ColumnDefinitions>\r
+\r
+\r
+                       <StackPanel x:Name="Controller" Grid.Column="0">\r
+                       </StackPanel>\r
+                       \r
+                       <Canvas x:Name="LayoutRoot" Grid.Column="1"></Canvas>\r
+\r
+               </Grid>\r
+               <TextBlock x:Name="AppStatusBar" Height="20">Loading...</TextBlock>\r
+       </StackPanel>\r
+</UserControl>\r
diff --git a/test4/MainPage.xaml.cs b/test4/MainPage.xaml.cs
new file mode 100644 (file)
index 0000000..a125451
--- /dev/null
@@ -0,0 +1,84 @@
+using Psychlops;\r
+using System;\r
+using System.Windows;\r
+using System.Windows.Media;\r
+using System.Windows.Media.Effects;\r
+using System.Windows.Media.Media3D;\r
+\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+       public partial class MainPage : System.Windows.Controls.UserControl\r
+       {\r
+               //System.Collections.Generic.IEnumerator<int> main_routine;\r
+               public System.Windows.Controls.Image master;\r
+               public PsychlopsSilverlightApp.PsychlopsMain main;\r
+#if DEBUG\r
+               public System.Windows.Controls.TextBlock DebugConsole;\r
+#endif\r
+               System.Windows.Controls.Image img;\r
+               public MainPage()\r
+               {\r
+                       InitializeComponent();\r
+                       // Show fps counter\r
+\r
+                       Canvas.default_api_canvas = LayoutRoot;\r
+                       Canvas.default_panel = this;\r
+                       this.IsTabStop = true;\r
+                       this.IsEnabled = true;\r
+                       this.MouseEnter += getFocusMouseEnter;\r
+                       System.Windows.Application.Current.Host.Settings.MaxFrameRate = 60;\r
+                       System.Windows.Application.Current.Host.Settings.EnableFrameRateCounter = true;\r
+                       System.Windows.Application.Current.Host.Settings.EnableCacheVisualization = false;\r
+                       //System.Windows.Application.Current.Host.Settings.EnableGPUAcceleration = false;\r
+                       //<param name="enableGPUAcceleration" value="true"/>\r
+                       System.Windows.Media.CompositionTarget.Rendering += new System.EventHandler(CompositionTarget_Rendering);\r
+                       //main_routine =  new System.ComponentModel.BackgroundWorker();\r
+                       //main_routine.DoWork += new System.ComponentModel.DoWorkEventHandler(psychlops_main);\r
+                       //main_routine.RunWorkerAsync();\r
+\r
+                       main = new PsychlopsSilverlightApp.PsychlopsMain();\r
+//                     Psychlops.AppState.statusBar.\r
+                       Psychlops.Internal.Main.routine = new System.Threading.Thread(main.psychlops_main);\r
+                       Psychlops.Internal.Main.routine.Start();\r
+                       //main.initialize();\r
+                       //main_routine = main.psychlops_main();\r
+\r
+                       Psychlops.Internal.Main.statusBar = AppStatusBar;\r
+                       Psychlops.Internal.Main.layoutRoot = LayoutRoot;\r
+                       //Psychlops.Internal.Main.widgetStack = Controller;\r
+                       AppStatusBar.Text = "Now starting Psychlops environment... please wait a minute";\r
+\r
+\r
+//eff__ = new Psychlops.Shader.GaborProgram();\r
+//rect__ = new System.Windows.Shapes.Rectangle();\r
+//rect__.Width = 200;\r
+//rect__.Height = 200;\r
+//rect__.Effect = eff__;\r
+//rect__.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue);\r
+               }\r
+               protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e) {\r
+                       this.Focus();\r
+//if(!b) { LayoutRoot.Children.Add(rect__); b = true; }\r
+               }\r
+//System.Windows.Shapes.Rectangle rect__;\r
+//Psychlops.Shader.GaborProgram eff__;\r
+//bool b = false;\r
+\r
+               private void CompositionTarget_Rendering(object sender, System.EventArgs e)\r
+               {\r
+                       //Controller.Children.Clear();\r
+                       if (Main.canvas != null) Main.canvas.executeFlip();\r
+                       //if (nextIntervalFrame-- <= 0)\r
+                       //{\r
+                       //      main_routine.MoveNext();\r
+                       //      nextIntervalFrame = main_routine.Current;\r
+                       //}\r
+               }\r
+\r
+       }\r
+\r
+\r
+\r
+}\r
+\r
diff --git a/test4/Properties/AppManifest.xml b/test4/Properties/AppManifest.xml
new file mode 100644 (file)
index 0000000..151cfa5
--- /dev/null
@@ -0,0 +1,7 @@
+<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"\r
+        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\r
+>\r
+    <Deployment.Parts>\r
+    </Deployment.Parts>\r
+    \r
+</Deployment>\r
diff --git a/test4/Properties/AssemblyInfo.cs b/test4/Properties/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..82192e3
--- /dev/null
@@ -0,0 +1,35 @@
+using System.Reflection;\r
+using System.Runtime.CompilerServices;\r
+using System.Runtime.InteropServices;\r
+\r
+// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。\r
+// アセンブリに関連付けられている情報を変更するには、\r
+// これらの属性値を変更してください。\r
+[assembly: AssemblyTitle("PsychlopsSilverlight4test")]\r
+[assembly: AssemblyDescription("")]\r
+[assembly: AssemblyConfiguration("")]\r
+[assembly: AssemblyCompany("")]\r
+[assembly: AssemblyProduct("PsychlopsSilverlight4test")]\r
+[assembly: AssemblyCopyright("Copyright ©  2010")]\r
+[assembly: AssemblyTrademark("")]\r
+[assembly: AssemblyCulture("")]\r
+\r
+// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから\r
+// 見えなくなります。このアセンブリ内で COM から型にアクセスする必要がある場合は、\r
+// その型の ComVisible 属性を true に設定してください。\r
+[assembly: ComVisible(false)]\r
+\r
+// このプロジェクトが COM に公開される場合、次の GUID がタイプ ライブラリの ID になります。\r
+[assembly: Guid("631fa262-58de-42ab-ba9d-79cb7cf7e289")]\r
+\r
+// アセンブリのバージョン情報は、以下の 4 つの値で構成されています。\r
+//\r
+//      Major Version\r
+//      Minor Version \r
+//      Build Number\r
+//      Revision\r
+//\r
+// すべての値を指定するか、下のように '*' を使ってリビジョンおよびビルド番号を\r
+// 既定値にすることができます。\r
+[assembly: AssemblyVersion("1.0.0.0")]\r
+[assembly: AssemblyFileVersion("1.0.0.0")]\r
diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs
new file mode 100644 (file)
index 0000000..e69a680
--- /dev/null
@@ -0,0 +1,756 @@
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+\r
+\r
+               public void psychlops_main() {\r
+\r
+       Canvas display = new Canvas(768,768);\r
+\r
+       double rect_size = 100;\r
+       double rect_lum  = 0.5;\r
+       double bg_lum    = 0.5;\r
+       double size = 250.0;\r
+   double sigma;\r
+   sigma = size/6.0;\r
+   double lambda;\r
+   lambda = 6*sigma;\r
+   int envelopemode = 0;\r
+   double refresh = display.getRefreshRate();\r
+   double[] SF=new double[2];\r
+\r
+   SF[0]=4.0;\r
+   SF[1]=4.0;\r
+\r
+   double phase=0;\r
+\r
+   double[] initphase = new double[2];\r
+   double _i, _j, _x, _y, _x2, _y2, col;\r
+   double amplitude = 1.0;\r
+\r
+       Rectangle fixation1 = new Rectangle(3,9);\r
+   Rectangle fixation2 = new Rectangle(9,3);\r
+       fixation1.centering();\r
+       fixation2.centering();\r
+   Rectangle contrastrect = new Rectangle();\r
+   contrastrect.set(760,760);\r
+\r
+   Image envelope = new Image();\r
+   Psychlops.Color bglum= new Color(0.5,0.5,0.5);\r
+   Psychlops.Color masklum = new Color(0.5,0.5,0.5,0.5);\r
+\r
+       Interval rng = new Interval();\r
+\r
+\r
+       Psychlops.Widgets.Slider TF;\r
+       TF = new Psychlops.Widgets.Slider("TF", 0.25<=rng<=2.0 , 0.1);\r
+   TF.value=0.75;\r
+\r
+\r
+\r
+       Psychlops.Widgets.Slider SFs;\r
+       SFs = new Psychlops.Widgets.Slider("SF", 4.0<=rng<=16.0 ,  4.0);\r
+       SFs.value = 4.0;\r
+\r
+   Psychlops.Widgets.Slider contrast;\r
+       contrast= new Psychlops.Widgets.Slider("Contrast", 0.0<=rng<=1.0 ,  0.1);\r
+       contrast.value = 0.1;\r
+\r
+\r
+       var element =  StaticFunctions.NewArray<Figures.ShaderGabor>(2);\r
+    for (int i = 0; i < element.Length; i++){\r
+           element[i].setSigma(sigma); // set a size of patch as a halfwidth of Gaussian\r
+           element[i].orientation = Math.PI/4.0+Math.PI/2.0*(1-i);//Math.PI/2*(rand()%2);// //set orientations\r
+           initphase[i]=0;\r
+  }\r
+\r
+\r
+\r
+      envelope.set(size, size);\r
+      envelope.clear(bglum);\r
+\r
+   for(int i=0; i<size; i++){\r
+       for(int j=0; j<size; j++){\r
+           _i=i-size*0.5;\r
+           _j=j-size*0.5;\r
+           _x=_i*Math.cos(-Math.PI/4.0)+_j*Math.sin(-Math.PI/4.0);\r
+           _y=-_i*Math.sin(-Math.PI/4.0)+_j*Math.cos(-Math.PI/4.0);\r
+           col=Math.exp(-(_x*_x)/(2*Math.pow(sigma*2/6.0,2.0))-(_y*_y)/(2*Math.pow(sigma*2,2.0)));\r
+           envelope.alpha(i,j,1.0-col);\r
+\r
+           }\r
+       }\r
+\r
+\r
+       while(!Keyboard.esc.pushed()) {\r
+           if(Keyboard.spc.pushed())envelopemode++; envelopemode%=2;\r
+       Display.clear(bglum);\r
+       phase ++;\r
+       //phase = fmod(phase,60);\r
+\r
+       for(int i=0; i<2; i++) {\r
+           element[i].phase =(SF[i]/SF[0])*amplitude*\r
+Math.PI*Math.sin(Math.PI/2*i+2*Math.PI*phase*TF/refresh);\r
+           element[i].wavelength = lambda/SF[i];\r
+           element[i].contrast = contrast;\r
+       }\r
+\r
+\r
+       element[0].centering().shift(-size * 0.6, -size * 0.6);\r
+       element[0].draw();\r
+       element[1].centering().shift(size*0.6,-size*0.6);\r
+       element[1].draw();\r
+               element[1].centering().shift(-size*0.6,size*0.6);\r
+       element[1].draw();\r
+               element[0].centering().shift(size*0.6,size*0.6);\r
+       element[0].draw();\r
+\r
+\r
+               if(envelopemode>0){\r
+                   envelope.centering().shift(size*0.6,-size*0.6).draw();\r
+                   envelope.centering().shift(-size*0.6,size*0.6).draw();\r
+                   }\r
+       masklum.set(bg_lum, bg_lum, bg_lum, 1-contrast);\r
+       contrastrect.centering();\r
+       contrastrect.draw(masklum);\r
+       fixation1.centering().shift(size*2,0.0);\r
+       fixation1.draw(Color.red);\r
+       fixation2.centering().shift(size*2,0.0);\r
+       fixation2.draw(Color.red);\r
+\r
+          Display.var(Mouse.x, 300, 300);\r
+          Display.var(Mouse.y, 300, 320);\r
+\r
+               Display.flip();\r
+\r
+\r
+       }\r
+\r
+}\r
+\r
+\r
+\r
+       }\r
+\r
+}\r
+/*\r
+\r
+using Psychlops;\r
+//Position Bias Program\r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+               Canvas cnvs;\r
+               Image img, img2, img3;\r
+               int isize = 40;\r
+               int frames;\r
+               Psychlops.Widgets.Slider tfreq;\r
+               Psychlops.Widgets.Slider contrast;\r
+               Psychlops.Widgets.Slider lambda;\r
+\r
+\r
+\r
+               public void psychlops_main()\r
+               {\r
+                       cnvs = new Canvas(300, 600);\r
+                       Interval rng = new Interval();\r
+                       tfreq = new Psychlops.Widgets.Slider("Temporal Frequency(Hz)", -5 <= rng <= 5, 3.0);\r
+                       contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.25);\r
+                       lambda = new Psychlops.Widgets.Slider("Wave Length", 10.0 <= rng <= 120.0, 30);\r
+\r
+                       img = new Image(isize * 2, isize * 2);\r
+                       img2 = new Image(isize * 2, isize * 2);\r
+                       img3 = new Image(isize * 2, isize * 2);\r
+\r
+                       var gabor1 = StaticFunctions.NewArray<Figures.ShaderGabor>(100);\r
+                       foreach (var g in gabor1)\r
+                       {\r
+                               g.setSigma(isize/8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);\r
+                               //g.setSize(isize).centering().shift(Math.random(300) - 150, Math.random(600) - 300);\r
+                               g.orientation = Math.random(2 * Math.PI);\r
+                               //g.orientation2 = Math.random(2 * Math.PI);\r
+                       }\r
+\r
+                       while (true)\r
+                       {\r
+                               cnvs.clear(new Color(0.5));\r
+\r
+                               Figures.drawGabor(ref img, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
+                               Figures.drawGabor(ref img2, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * -tfreq / 60);\r
+                               Figures.drawGabor(ref img3, isize / 8, 1 / lambda, contrast, 0.5 * Math.PI, (double)frames * 2.0 * Math.PI * tfreq / 60);\r
+\r
+\r
+                               //img.centering().shift(0, -isize * 1.5).draw();\r
+                               //img2.centering().draw();\r
+                               //img3.centering().shift(0, isize * 1.5).draw();\r
+\r
+\r
+                               //foreach (var g in gabor1)\r
+                               for (int i = 0; i < gabor1.Length; i++)\r
+                               {\r
+                                       gabor1[i].wavelength = lambda;\r
+                                       gabor1[i].phase = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
+                                       gabor1[i].contrast = contrast;\r
+                                       //g.wavelength2 = lambda * 2;\r
+                                       //g.phase2 = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
+                                       //g.contrast2 = contrast / 2;\r
+                                       gabor1[i].draw();\r
+                               }\r
+\r
+                               if (!Mouse.left.pressed()) frames++;\r
+\r
+                               cnvs.flip();\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+\r
+/*\r
+///+ Prefix linkto BasicCode1\r
+//// Lines for set up Psychlops environment\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+               ///- Prefix linkto BasicCode1\r
+\r
+\r
+               ///+ Main Routine\r
+               //// Psychlops runs at the first line of this function psychlops_main().\r
+               public void psychlops_main()\r
+               {\r
+\r
+                       ///+ 0 SetGlobal\r
+                       ////Prepare global parameters\r
+                       Rectangle p1 = new Rectangle(1,1);\r
+                       Color col1 = new Color();\r
+                       double width=50;\r
+                       double height=10;\r
+                       double lambda=60;\r
+                       double lmean=0.25, contrast = 0.5;\r
+                       double x0 = 0;\r
+                       double y0 = 0;\r
+                   double pitch = 1;\r
+                       Canvas disp = new Canvas(Canvas.window, Display.secondary);\r
+                       \r
+                       var fieldW_ = Psychlops.Widgets.Browser.Element.byID("fieldW");\r
+                       var fieldH_ = Psychlops.Widgets.Browser.Element.byID("fieldH");\r
+                       var wL_     = Psychlops.Widgets.Browser.Element.byID("wL");\r
+                       var Cont_   = Psychlops.Widgets.Browser.Element.byID("Cont");\r
+                       var ix_     = Psychlops.Widgets.Browser.Element.byID("ix");\r
+                       var iy_     = Psychlops.Widgets.Browser.Element.byID("iy");\r
+                       var gap_    = Psychlops.Widgets.Browser.Element.byID("gap");\r
+                       ///- 0 SetGlobal\r
+\r
+                       ///+ 1 Initialize\r
+                       ////initialize\r
+                       p1.centering().shift(-width*0.5 + x0, -height*0.5 + y0); //Move a point to the initial position.\r
+                       ///- 1 Initialize\r
+\r
+                       ///+ 2 Drawing\r
+                        ////drawing objects\r
+                       for(int i=0; i < width; i++)\r
+                       {\r
+                               col1.set(lmean*((contrast*Math.sin((2*Math.PI*i/lambda)))+1)); //Set a color.\r
+\r
+                               ///+ 2.1 Drawing a column\r
+                               ////drawing a column\r
+                               for(int j=0;j < height; j++)\r
+                               {\r
+                                       p1.draw(col1);\r
+                                       p1.shift(0, pitch);\r
+                               }\r
+                               ///- 2.1 Drawing a column\r
+\r
+                               p1.shift(1, -height * pitch); //back to vertical intitial point after drawing one column.\r
+                       }\r
+                       disp.flip();\r
+                       ///- 2 Drawing\r
+\r
+                       while (!Keyboard.spc.pushed()) { }; //Wait until space key is pressed.\r
+               }\r
+\r
+\r
+       }\r
+\r
+}\r
+ * */\r
+\r
+\r
+/*\r
+///+ Prefix\r
+//// Lines for set up Psychlops environment\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {///- Prefix\r
+\r
+\r
+\r
+               ///+ Main Routine\r
+               //// Psychlops runs at the first line of this function psychlops_main().\r
+               public void psychlops_main()\r
+               {\r
+                       Canvas window = new Canvas(300, 300); //Create a window. Here, window variables are preset mode.\r
+\r
+                       var FIGURE = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
+                       var SIZE_X_ = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
+                       var SIZE_Y_ = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
+                       var COLOR_R = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
+                       var COLOR_G = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
+                       var COLOR_B = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
+                       var COLOR_BG = Psychlops.Widgets.Browser.Element.byID("COLOR_BG");\r
+                       var Period_Size = Psychlops.Widgets.Browser.Element.byID("Period_Size");\r
+                       var Period_Position = Psychlops.Widgets.Browser.Element.byID("Period_Position");\r
+                       var Speed_HSize_ = Psychlops.Widgets.Browser.Element.byID("Speed_HSize");\r
+                       var Speed_VSize = Psychlops.Widgets.Browser.Element.byID("Speed_VSize");\r
+                       var Speed_VMotion = Psychlops.Widgets.Browser.Element.byID("Speed_VMotion");\r
+                       double SIZE_X = SIZE_X_, SIZE_Y = SIZE_Y_;\r
+\r
+                       ///+ 2\r
+                       ////  Set a figure size, position and color.\r
+                       Rectangle figure = new Rectangle();\r
+                       Ellipse figure2 = new Ellipse();\r
+                       figure.set(SIZE_X_, SIZE_Y_); // Set the size of figure.\r
+                       figure2.set(SIZE_X_, SIZE_Y_); // Set the size of figure.\r
+                       figure.centering().shift(0, 0); // Move the figure to the starting point.\r
+                       figure2.centering().shift(0, 0); // Move the figure to the starting point.\r
+                       ///- 2\r
+\r
+                       int frame = 0;\r
+                       int looming_direction = 1, motion_dir = 1;\r
+                       double direction = 1.0;\r
+                       //looming_direction is a variable for size change.\r
+                       //motion_dir is a variable for motion direction.\r
+                       ///+ 3 Drawing loop\r
+                       //// Draw each frames in a "while loop".\r
+                       while (!Keyboard.esc.pushed())\r
+                       { //exit a program when the escape key is pressed down.\r
+                               window.clear(COLOR_BG); // Clear the window with a designated gray-scale level.\r
+\r
+                               ///+ 3.1\r
+                               //// Calculate object's position and size for each frame.\r
+\r
+                               if (frame % Period_Size == 0)\r
+                               { // a direction of size change will reverse at designated frames.\r
+                                       looming_direction = looming_direction * -1;\r
+                               }\r
+\r
+                               if (frame % Period_Position == 0)\r
+                               { // motion direction will reverse at designated frames.\r
+                                       motion_dir *= -1;\r
+                               }\r
+\r
+                               ///- 3.1\r
+\r
+                               ///+ 3.2 \r
+                               //// Settting figure's properties\r
+                               figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
+                                                                figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".\r
+                               figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
+                               figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
+                                                               figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".\r
+                               figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
+                               /*\r
+                               figure.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
+                                                        figure.getHeight() + looming_direction * 1);// Scaling the figure in a direction given by "looming_direction".\r
+                               figure.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
+                               figure2.resize(figure.getWidth() + looming_direction * 1, // Scaling the figure in a direction given by "looming_direction".\r
+                                                               figure.getHeight() + direction * Speed_VSize);// Scaling the figure in a direction given by "looming_direction".\r
+                               figure2.shift(motion_dir * 1.0, motion_dir * Speed_VMotion);// Move the figure for 1 pixel in direction given by "motion_dir". \r
+                                * * /\r
+                               ///- 3.2\r
+\r
+                               ///+ 3.3 \r
+                               ////Drawing\r
+                               if ("Rectangle".Equals(FIGURE))\r
+                               {\r
+                                       figure.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.\r
+                               }\r
+                               else\r
+                               {\r
+                                       figure2.draw(new Color(COLOR_R, COLOR_G, COLOR_B)); // Drawing the figure with a designated color at designated position.\r
+                               }\r
+                               window.flip(); // Reflect the drawing for the display by flipping frame buffers.\r
+                               ///- 3.3\r
+\r
+                               ///+ 3.4\r
+                               ////make a step for next frames \r
+                               frame++;\r
+                               ///- 3.4\r
+                       }\r
+                       ///- 3 Drawing loop\r
+\r
+               }\r
+               ///- Main Routine\r
+\r
+\r
+       }\r
+\r
+}\r
+\r
+\r
+\r
+/*\r
+//The reversed-phi motion.\r
+//Anstis (1970)\r
+//Phi movement as a subtraction process. Vision Res 10:1411?1430\r
+\r
+///+ Prefix\r
+//// Include Psychlops Package\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+\r
+               ///- Prefix\r
+\r
+               ///+ Stimulus drawing function\r
+               //// A function for stimulus drawing (main body)\r
+               void RectLuminance()\r
+               {\r
+\r
+                       ///+ Preperation\r
+                       //// Declare and initialize local variables\r
+                       double rect_size = 20;\r
+\r
+                       double bg_lum = 0.5;\r
+                       double radii = 200;\r
+                       double rect_lum;\r
+                       int element_number = 25;\r
+                       int radial_row = 5;\r
+\r
+                       double rotation_tf = 0.2;\r
+                       double polarity = 1;\r
+                       double rotation;\r
+\r
+                       double contrastflag = 1;\r
+                       int period = 3;\r
+                       double refresh;\r
+\r
+                       Canvas display = new Canvas(Canvas.window); //Prepare drawing window\r
+                       refresh = Display.getRefreshRate();\r
+\r
+                       Ellipse rect = new Ellipse();\r
+                       rect.set(rect_size, rect_size);\r
+\r
+                       Ellipse fixation = new Ellipse(5, 5);\r
+                       fixation.centering();\r
+\r
+                       Letters let1 = new Letters("Press Space key to change stimulus type");\r
+                       let1.centering().shift(-180, 220);\r
+                       Letters let2 = new Letters("Phi");\r
+                       let2.centering().shift(-10, 200);\r
+                       Letters let3 = new Letters("Reversed-Phi");\r
+                       let3.centering().shift(-60, 200);\r
+\r
+                       rotation = Math.random(2 * Math.PI);\r
+\r
+                       ///+ user interface\r
+                       ////register variables to demo circumstances\r
+                       Interval rng = new Interval();\r
+\r
+                       Psychlops.Widgets.Slider rect_contrast;\r
+                       rect_contrast = new Psychlops.Widgets.Slider("Contrast", 0.1 <= rng <= 1.0, 0.1);\r
+                       rect_contrast.value = 0.5;\r
+                       ///- user interface\r
+                       ///- Preperation\r
+\r
+                       ///+ Main loop\r
+                       ////Main loop\r
+                       int frame = 0;\r
+                       //AppState::setThreadPriority(AppState::HIGH);\r
+                       while (true)\r
+                       {\r
+                               frame++;\r
+                               if (Keyboard.spc.pushed()) contrastflag = -contrastflag;\r
+                               if (contrastflag < 0) polarity = -polarity;\r
+                               rotation = 2 * Math.PI * rotation_tf * frame * period / refresh;\r
+\r
+                               for (int frame_now = 0; frame_now < period; frame_now++)\r
+                               {\r
+                                       Display.clear(new Color(bg_lum));\r
+                                       for (int j = 0; j < radial_row; j++)\r
+                                       {\r
+                                               rect.resize(rect_size * (j + radial_row) / 10.0, rect_size * (j + radial_row) / 10.0);\r
+                                               for (double i = 0; i < element_number; i++)\r
+                                               {\r
+                                                       rect_lum = bg_lum * (1.0 + polarity * rect_contrast);\r
+                                                       rect.centering().shift(radii * (j + radial_row) / 10.0 * Math.cos(rotation + i * 2 * Math.PI / element_number), radii * (j + radial_row) / 10.0 * Math.sin(rotation + i * 2 * Math.PI / element_number));\r
+                                                       rect.draw(rect_lum);\r
+                                               }\r
+                                       }\r
+                                       fixation.draw(Color.red);\r
+                                       let1.draw();\r
+                                       if (contrastflag > 0) let2.draw();\r
+                                       else let3.draw();\r
+                                       Display.flip();\r
+                               }\r
+                       }\r
+                       ///- Main loop\r
+                       //AppState::setThreadPriority(AppState::NORMAL);\r
+               }\r
+               ///- Stimulus drawing function\r
+\r
+               ///+ Main function for demo circumstances\r
+               //// Psychlops Main function\r
+               public void psychlops_main()\r
+               {\r
+                       ///+ Demo circumstances\r
+                       //// Spells for run demonstration circumstances\r
+                       Procedure p = new Procedure();\r
+                       //p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
+                       p.setProcedure(RectLuminance);  //The argument name is a name of drawing function.\r
+                       p.run();\r
+                       ///- Demo circumstances\r
+               }\r
+               ///- Main function for demo circumstances\r
+\r
+       }\r
+\r
+}\r
+\r
+\r
+\r
+/*\r
+//Two types of plaid motion\r
+//E. H. Adelson and J. A. Movshon (1982).\r
+//Phenomenal coherence of moving visual patterns. Nature 300, 523-525\r
+\r
+///+ Prefix\r
+//// Include Psychlops Package\r
+using Psychlops;\r
+\r
+       namespace PsychlopsSilverlightApp\r
+       {\r
+\r
+               public class PsychlopsMain\r
+               {\r
+                       ///- Prefix\r
+\r
+                       ///+ Global\r
+                       // Struct for component paremeters\r
+                       struct component\r
+                       {\r
+                               public double contrast;\r
+                               public double orientation;\r
+                               public double lambda;\r
+                               public double tf;\r
+                       }\r
+                       ///- Global\r
+\r
+                       ///+ Stimulus drawing function\r
+                       //// A function for stimulus drawing (main body)\r
+                       void drawgratingmovie(Image[] img, component c1, component c2, double contrast, int start, int maxframe, double bg_lum, double alpha)\r
+                       {\r
+                               double _xp, _xp2, col1, col2;\r
+                               double contrast1, contrast2;\r
+                               double imageheight, imagewidth;\r
+\r
+                               contrast1 = contrast*c1.contrast/(c1.contrast+c2.contrast);\r
+                               contrast2 = contrast*c2.contrast/(c1.contrast+c2.contrast);\r
+\r
+                               imageheight = img[0].getHeight();\r
+                               imagewidth = img[0].getWidth();\r
+\r
+                               for(int frame=start; frame<start+maxframe+1; frame++){\r
+                                       //Display.progressbar(frame, maxframe+1);\r
+                                       //img[frame].convert(Image::RGBA);\r
+                                       for(int i=0; i<imagewidth; i++){\r
+                                               for(int j=0; j<imageheight; j++){\r
+                                                       _xp = Math.sin(c1.orientation)*(i-imagewidth*0.5) + Math.cos(c1.orientation) * (j-imageheight *0.5);\r
+                                                       _xp2 = Math.sin(c2.orientation)*(i-imagewidth*0.5) + Math.cos(c2.orientation) * (j-imageheight *0.5);\r
+                                                       col1 = bg_lum*contrast1*Math.sin(2*Math.PI*_xp/c1.lambda + 2*Math.PI*c1.tf*frame/(double)refresh);\r
+                                                       col2 = bg_lum*contrast2*Math.sin(2*Math.PI*_xp2/c2.lambda + 2*Math.PI*c2.tf*frame/(double)refresh);\r
+                                                       img[frame].pix(i,j,new Color(col1+col2+bg_lum));\r
+                                                       img[frame].alpha(i,j,alpha);\r
+                                               }\r
+                                       }\r
+                                       //img[frame].cache();\r
+                               }\r
+                       }\r
+\r
+                       ///+ Stimulus drawing function\r
+                       //// A function for stimulus drawing (main body)\r
+                       void drawplaid() {\r
+                               Canvas display = new Canvas(Canvas.window);\r
+                               ///+ Preperation\r
+                               //// Declare and initialize local variables\r
+                               int rect_size = 150;\r
+                               double rect_lum  = 0.5;\r
+                               double bg_lum    = 0.2;\r
+                               double duration = 400;\r
+\r
+                               double[] lambda = new double[2], contrast = new double[2], tf = new double[2];\r
+                               double center_orientation = 0.0;\r
+                               Image[,] movie = StaticFunctions.NewArray<Image>(2, 120);\r
+                               Image[,] component_movie = StaticFunctions.NewArray<Image>(4, 120);\r
+                               Image envelope = new Image(), envelope_small = new Image();\r
+\r
+                               for(int i=0; i<120; i++)\r
+                               {\r
+                                       movie[0, i].set(rect_size, rect_size);\r
+                                       movie[1, i].set(rect_size, rect_size);\r
+                                       component_movie[0, i].set(rect_size/2, rect_size/2);\r
+                                       component_movie[1, i].set(rect_size/2, rect_size/2);\r
+                                       component_movie[2, i].set(rect_size/2, rect_size/2);\r
+                                       component_movie[3, i].set(rect_size/2, rect_size/2);\r
+                               }\r
+                               envelope.set(rect_size, rect_size);\r
+                               envelope_small.set(rect_size/2, rect_size/2);\r
+\r
+                               Letters let1 = new Letters(), let2 = new Letters(), let3 = new Letters();\r
+                               let1.str = "Component1";\r
+                               let2.str = "Component2";\r
+                               let3.str = "Superposition";\r
+                               let1.centering().shift(-rect_size*1.25, -rect_size);\r
+                               //let1.cache();\r
+                               let2.centering().shift(rect_size*1.25, -rect_size);\r
+                               //let2.cache();\r
+                               let3.centering().shift(0.0, rect_size*0.75);\r
+                               //let3.cache();\r
+\r
+                               component c1, c2, c0;\r
+                               c0 = new component{ 0.0,0.0,1.0,1.0 }; //dummy for component movie\r
+                               ///+ type-I\r
+                               // Prepare Type-I plaid movie\r
+                               center_orientation = 0.0;\r
+                               orientation_offset = Math.PI/6;\r
+                               contrast[0] = 1.0, contrast[1] = 1.0;\r
+                               lambda[0] = 30.0, lambda[1] = 30.0;\r
+                               tf[0] = 1.0; tf[1] = 1.0;\r
+\r
+                               c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
+                               c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
+\r
+                       drawgratingmovie(movie[0],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       drawgratingmovie(component_movie[0],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       drawgratingmovie(component_movie[1],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       ///- type-I\r
+\r
+                       ///+ type-II\r
+                       // Prepare Type-II plaid movie\r
+                       center_orientation = -0.0, orientation_offset = Math.PI/12;\r
+                       contrast[0] = 1.0, contrast[1] = 1.0;\r
+                       lambda[0] = 30.0, lambda[1] = 30.0;\r
+                       tf[0] = 1.0; tf[1] = 4.0;\r
+\r
+                       c1 = {contrast[0], center_orientation-orientation_offset, lambda[0], tf[0]};\r
+                       c2 = {contrast[1], center_orientation+orientation_offset, lambda[1], tf[1]};\r
+\r
+                       drawgratingmovie(movie[1],c1, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       drawgratingmovie(component_movie[2],c0, c2, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       drawgratingmovie(component_movie[3],c1, c0, 0.5, 0, refresh_int, bg_lum, 1.0);\r
+                       ///- type-II\r
+\r
+                       ///+ gaussian\r
+                       //draw Gaussian envelopes\r
+                       envelope.clear(new Color(bg_lum)); //clear offscreen image\r
+                       double _x, _y;\r
+                       for(int i=0; i<rect_size; i++){\r
+                       _x=i-0.5*rect_size;\r
+                       for(int j=0; j<rect_size; j++){\r
+                       _y=j-0.5*rect_size;\r
+                       envelope.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/6.0, 2.0) ))));\r
+                       }\r
+                       }\r
+\r
+                       envelope_small.clear(new Color(bg_lum)); //clear offscreen image\r
+                       for(int i=0; i<rect_size*0.5; i++){\r
+                       _x=i-0.25*rect_size;\r
+                       for(int j=0; j<rect_size*0.5; j++){\r
+                       _y=j-0.25*rect_size;\r
+                       envelope_small.alpha(i,j,1.0-Math.exp(-((_x*_x+_y*_y)/ (2.0*pow(rect_size/12.0, 2.0) ))));\r
+                       }\r
+                       }\r
+                       envelope.cache(); //send offscreen image from main memory to GPU\r
+                       envelope_small.cache(); //send offscreen image from main memory to GPU\r
+                       ///- gaussian\r
+\r
+                       ///+ user interface\r
+                       // Draw user interface\r
+                       Widgets::SelectBox stimulus_type;\r
+                       stimulus_type.area.set(120, 20);\r
+                       stimulus_type.append(L"TypeI");\r
+                       stimulus_type.append(L"TypeII");\r
+                       stimulus_type.centering().shift(-120.0,250.0);\r
+\r
+                       Psychlops::Widgets::SelectBox stimulus_type2;\r
+                       stimulus_type2.area.set(120, 20);\r
+                       stimulus_type2.append(L"Continuous");\r
+                       stimulus_type2.append(L"Periodic");\r
+                       stimulus_type2.centering().shift(120.0,250.0);\r
+\r
+                       Psychlops::Widgets::Slider duration_slider;\r
+                       duration_slider.area.set(100,20);\r
+                       duration_slider.centering().shift(120,280.0);\r
+                       Interval rng = new Interval();\r
+                       duration_slider.link(duration, 50<=rng<=950, 50.0, 50.0);\r
+                       ///- user interface\r
+                       ///- Preperation\r
+\r
+                       ///+ Main loop\r
+                       int frame = 0;\r
+                       int period = refresh_int;\r
+                       int movienum;\r
+                       while(!Keyboard.esc.pushed()) {\r
+                       Display.clear(new Color(bg_lum));\r
+                       movienum = stimulus_type.getSelected(); //if "Type-I" is selected, 0, else frame refresh per sec\r
+\r
+                       in;\r
+                       else period = refresh_int;\r
+\r
+                       if(frame>0){\r
+                       movie[movienum, frame].centering().draw();\r
+                       envelope.centering().draw();\r
+                       component_movie[movienum*2, frame].centering().shift(-rect_size*0.5, -rect_size).draw();\r
+                       envelope_small.centering().shift(-rect_size*0.5, -rect_size).draw();\r
+                       component_movie[movienum*2+1, frame].centering().shift(rect_size*0.5, -rect_size).draw();\r
+                       envelope_small.centering().shift(rect_size*0.5, -rect_size).draw();\r
+                       }\r
+\r
+                       ///+ draw user interface\r
+                       let1.draw(0.75);\r
+                       let2.draw(0.75);\r
+                       let3.draw(0.75);\r
+                       stimulus_type.draw();\r
+                       stimulus_type2.draw();\r
+                       if(stimulus_type2.getSelected())duration_slider.draw();\r
+                       ///- draw user interface\r
+                       Display.flip();\r
+                       if(frame++ >= period) frame -= refresh_int;\r
+                       }\r
+                       ///- Main loop\r
+\r
+                       }\r
+                       ///- Stimulus drawing function\r
+\r
+               ///+ Main function for demo circumstances\r
+               public void psychlops_main() {\r
+                       ///+ Demo circumstances\r
+                       //// Spells for run demonstration circumstances\r
+                       Procedure p = new Procedure();\r
+                       //p.setDesign(Procedure::DEMO); //Designate that this is a demo.\r
+                       p.setProcedure(drawplaid);  //The argument name is a name of drawing function.\r
+                       p.run();\r
+                       ///- Demo circumstances\r
+               }\r
+       }\r
+}\r
+*/\r
diff --git a/test4/Store.cs b/test4/Store.cs
new file mode 100644 (file)
index 0000000..d77d038
--- /dev/null
@@ -0,0 +1,883 @@
+\r
+/*\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+               void RectLuminance()\r
+               {\r
+                       Canvas display = new Canvas(Canvas.window);\r
+                       Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
+                       Letters le = new Letters("Reload to restart");\r
+                       le.fill = Color.black;\r
+                       le.align = Letters.HorizontalAlign.center;\r
+\r
+                       while (!Keyboard.esc.pushed())\r
+                       {\r
+                               Display.clear(Color.white);\r
+                               le.centering().shift(-200,-10).draw();\r
+                               Display.flip();\r
+                       }\r
+\r
+               }\r
+\r
+\r
+               public void psychlops_main()\r
+               {\r
+                       RectLuminance();\r
+               }\r
+\r
+\r
+       }\r
+\r
+}\r
+\r
+*/\r
+\r
+\r
+\r
+/*\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+\r
+               Psychlops.Widgets.Slider rect_size, freq, contrast;\r
+\r
+               void PositionalBiasisInMovingGabor()\r
+               {\r
+                       double vel = 30.0;\r
+                       double StimWidth = 120;\r
+\r
+                       Interval rng = new Interval();\r
+                       Psychlops.Widgets.Slider rect_size, freq, contrast;\r
+                       rect_size = new Psychlops.Widgets.Slider("Rect Size", 1 < rng < 500, 120.0);\r
+                       freq = new Psychlops.Widgets.Slider("Sptial Frequency", 0.0 <= rng <= 1.0, 0.125);\r
+                       contrast = new Psychlops.Widgets.Slider("Contrast", 0.0 <= rng <= 1.0, 0.1);\r
+\r
+                       int IMAGES = (int)vel;\r
+\r
+                       Image[] GaborIMG = new Image[200];\r
+                       for (int i = 0; i < 200; i++) GaborIMG[i] = new Image();\r
+\r
+                       Color clrcol = new Color(), clrFP = new Color();\r
+                       Display.clear(0.5);\r
+                       clrcol.set(128.0 / 255.0);\r
+                       clrFP.set(128.0 / 255.0, 0.0, 0.0);\r
+\r
+                       int phase = 0;\r
+                       double distance = rect_size;\r
+                       bool changed = true, stop = false;\r
+                       double prev_contrast = 0.0, prev_freq = 0.0, prev_size = 0.0;\r
+\r
+                       while (!Keyboard.esc.pushed())\r
+                       {\r
+                               Display.clear();\r
+\r
+                               if (prev_contrast != contrast || prev_freq != freq || prev_size != rect_size) changed = true;\r
+                               prev_contrast = contrast;\r
+                               prev_freq = freq;\r
+                               prev_size = rect_size;\r
+                               if (changed)\r
+                               {\r
+                                       for (int i = 0; i < 2; i++)\r
+                                       {\r
+                                               for (int j = 0; j < IMAGES; j++)\r
+                                               {\r
+                                                       Figures.drawGabor(ref GaborIMG[i * IMAGES + j], rect_size / 8.0, freq, contrast, Math.PI * 0.5, 2.0 * Math.PI * j / IMAGES);\r
+                                                       distance = rect_size;\r
+                                               }\r
+                                       }\r
+                                       changed = false;\r
+                               }\r
+\r
+                               if (!stop)\r
+                               {\r
+                                       Display.clear(127.0 / 255.0);\r
+                                       for (int i = 0; i < 3; i++)\r
+                                       {\r
+                                               switch (i)\r
+                                               {\r
+                                                       case 0:\r
+                                                               GaborIMG[IMAGES - phase - 1].centering().shift(0, -distance);\r
+                                                               GaborIMG[IMAGES - phase - 1].draw(); break;\r
+                                                       case 1:\r
+                                                               GaborIMG[phase].centering().shift(0, 0);\r
+                                                               GaborIMG[phase].draw(); break;\r
+                                                       case 2:\r
+                                                               GaborIMG[IMAGES - phase - 1].centering().shift(0, +distance);\r
+                                                               GaborIMG[IMAGES - phase - 1].draw(); break;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               if (Keyboard.spc.pushed()) stop = !stop;\r
+                               //GaborIMG[0].draw();\r
+\r
+                               phase++;\r
+                               phase %= IMAGES;\r
+                               //if (!stop) Display.flip();\r
+                               Display.flip();\r
+\r
+                       }\r
+\r
+               }\r
+\r
+\r
+               public void psychlops_main()\r
+               {\r
+\r
+                       Canvas display = new Canvas(Canvas.window);\r
+\r
+                       PositionalBiasisInMovingGabor();\r
+\r
+               }\r
+\r
+\r
+\r
+       }\r
+\r
+}\r
+ */\r
+/*\r
+ * \r
+ * using Psychlops;\r
+\r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+\r
+               Psychlops.Canvas cnvs;\r
+               int i;\r
+               double x, y, z, t, p, temp, xx, yy;\r
+\r
+               //Set Target Initial Value\r
+               double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;\r
+\r
+               //Set Background Initial Value\r
+               double Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
+               Psychlops.Widgets.Slider thetaSpeed, DotNumber;\r
+               Image img;\r
+\r
+\r
+\r
+               public void psychlops_main()\r
+               {\r
+\r
+                       cnvs = new Canvas(500, 500);\r
+\r
+//                     Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
+//                     img = new Image("Resources/logo.png");\r
+\r
+                       Interval rng = new Interval();\r
+                       thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);\r
+                       DotNumber  = new Psychlops.Widgets.Slider("DotNum",   0 <= rng <= 100, 50.0);\r
+\r
+                       //Declare background dots and target\r
+                       Rectangle[] BGDot = new Rectangle[2048];\r
+                       for (int i = 0; i < 2048; i++)\r
+                       {\r
+                               BGDot[i]=new Rectangle();\r
+                       }\r
+                       Rectangle[] Target= new Rectangle[10];\r
+                       for(int i=0; i<10; i++){\r
+                               Target[i]=new Rectangle();\r
+                       }\r
+\r
+\r
+\r
+                       //Declare Matrix to keep back ground dots' coordinate value\r
+                       double[] DotX=new double[2048];\r
+                       double[] DotY = new double[2048];\r
+\r
+                       AppState.statusBar = "dvcscxz";\r
+                                               //Set Independent variables to manipulate\r
+\r
+\r
+                                               //Initialize positions of background dots\r
+                                               for(int i=0; i<2048; i++){\r
+                                                       t=2.0*Math.PI*Math.random(1.0);\r
+                                                       p=2.0*Math.PI*Math.random(1.0);\r
+                                                       DotX[i]=t;\r
+                                                       DotY[i]=p;\r
+\r
+                                                       x=BGRadii*Math.cos(t)*Math.cos(p);\r
+                                                       y=BGRadii*Math.sin(t)*Math.cos(p);\r
+                                                       BGDot[i].set(BGSize, BGSize);\r
+                                                       BGDot[i].centering().shift(x,y);\r
+                                               }\r
+\r
+                                               //Initialize positions of targets\r
+                                               for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);\r
+\r
+                                               double COS, SIN;\r
+                                               //DotNumber = 200;\r
+                                               //Main stimulus loop\r
+                                               while(true){\r
+                                                       //Clear the main window\r
+                                                       cnvs.clear();\r
+\r
+\r
+                                                       temp=Axis/360*2*Math.PI;\r
+                                                       COS=Math.cos(temp);\r
+                                                       SIN=Math.sin(temp);\r
+\r
+                                                       //Calculate positions of background dots and set them\r
+                                                       for(int i=0; i<DotNumber; i++){\r
+                                                               //Calculate in polar coordinate\r
+                                                               t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;\r
+                                                               p=DotY[i];\r
+\r
+                                                               //Save current position\r
+                                                               DotX[i]=t;\r
+\r
+                                                               //Convert to Decartes coordinate\r
+                                                               x=BGRadii*Math.cos(t)*Math.cos(p);\r
+                                                               y=BGRadii*Math.sin(t)*Math.cos(p);\r
+                                                               z=BGRadii*Math.sin(p);\r
+                                                               xx=x;\r
+                                                               yy=SIN*y+COS*z;\r
+\r
+                                                               //Set Dotsize and Draw them\r
+                                                               BGDot[i].set(BGSize, BGSize);\r
+                                                               BGDot[i].centering().shift(xx,yy);\r
+                                                               BGDot[i].draw( Color.blue );\r
+                                                       }\r
+\r
+                                                       //Calculate positions of targets and set them\r
+                                                       temp=Rotate*2*Math.PI/360.0;\r
+                                                       for (int i = 0; i < 5; i++)\r
+                                                       {\r
+                                                               t = 2.0 * Math.PI/TargetNumber;\r
+                                                               x = TargetEcce*Math.cos(i*t+temp);\r
+                                                               y = TargetEcce*Math.sin(i*t+temp);\r
+                                                               Target[i].centering().shift(x,y);\r
+                                                               Target[i].fill = Color.yellow;\r
+                                                               Target[i].draw();\r
+                                                       }\r
+\r
+                       //                              img.centering(Mouse.position).draw();\r
+\r
+                                                       cnvs.var(Mouse.position.x, 100, 100);\r
+                                                       cnvs.var(Mouse.position.y, 100, 140);\r
+\r
+                                                       //Reflect drawing at the next frame;\r
+                                                       cnvs.flip();\r
+                                               }\r
+               }\r
+       }\r
+\r
+}\r
+ * */\r
+\r
+\r
+\r
+\r
+\r
+\r
+/*\r
+ using Psychlops;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+\r
+               Psychlops.Canvas cnvs;\r
+               int i;\r
+               double x, y, z, t, p, temp, xx, yy;\r
+\r
+               //Set Target Initial Value\r
+               double TargetEcce = 100.0, TargetSize = 5.0, TargetNumber = 5, Rotate = 0.0;\r
+\r
+               //Set Background Initial Value\r
+               double Axis = 0.0, BGRadii = 150, BGSize = 5.0;\r
+               Psychlops.Widgets.Slider thetaSpeed, DotNumber;\r
+               Image img;\r
+\r
+\r
+\r
+               public void psychlops_main()\r
+               {\r
+                       cnvs = new Canvas(500, 500);\r
+\r
+                       Psychlops.Solver.BinomialLikelihood.showWindow(Math.cumulativeNormalDistibution);\r
+\r
+\r
+                       img = new Image("Resources/logo.png");\r
+\r
+                       Interval rng = new Interval();\r
+                       thetaSpeed = new Psychlops.Widgets.Slider("Label", -10 <= rng <= 10, 3.0);\r
+                       DotNumber  = new Psychlops.Widgets.Slider("DotNum",   0 <= rng <= 100, 50.0);\r
+\r
+                       //Declare background dots and target\r
+                       Rectangle[] BGDot = new Rectangle[2048];\r
+                       for(int i=0; i<2048; i++){\r
+                               BGDot[i]=new Rectangle();\r
+                       }\r
+                       Rectangle[] Target= new Rectangle[10];\r
+                       for(int i=0; i<10; i++){\r
+                               Target[i]=new Rectangle();\r
+                       }\r
+\r
+\r
+                       //Declare Matrix to keep back ground dots' coordinate value\r
+                       double[] DotX=new double[2048];\r
+                       double[] DotY = new double[2048];\r
+\r
+\r
+                       //Set Independent variables to manipulate\r
+\r
+\r
+                       //Initialize positions of background dots\r
+                       for(int i=0; i<2048; i++){\r
+                               t=2.0*Math.PI*Math.random(1.0);\r
+                               p=2.0*Math.PI*Math.random(1.0);\r
+                               DotX[i]=t;\r
+                               DotY[i]=p;\r
+\r
+                               x=BGRadii*Math.cos(t)*Math.cos(p);\r
+                               y=BGRadii*Math.sin(t)*Math.cos(p);\r
+                               BGDot[i].set(BGSize, BGSize);\r
+                               BGDot[i].centering().shift(x,y);\r
+                       }\r
+\r
+                       //Initialize positions of targets\r
+                       for(int i=0; i<10; i++)Target[i].set(TargetSize, TargetSize);\r
+\r
+                       double COS, SIN;\r
+                       //DotNumber = 200;\r
+                       //Main stimulus loop\r
+                       while(true){\r
+                               //Clear the main window\r
+                               cnvs.clear();\r
+\r
+\r
+                               temp=Axis/360*2*Math.PI;\r
+                               COS=Math.cos(temp);\r
+                               SIN=Math.sin(temp);\r
+\r
+                               //Calculate positions of background dots and set them\r
+                               for(int i=0; i<DotNumber; i++){\r
+                                       //Calculate in polar coordinate\r
+                                       t=DotX[i]+2.0*Math.PI*thetaSpeed/360.0;\r
+                                       p=DotY[i];\r
+\r
+                                       //Save current position\r
+                                       DotX[i]=t;\r
+\r
+                                       //Convert to Decartes coordinate\r
+                                       x=BGRadii*Math.cos(t)*Math.cos(p);\r
+                                       y=BGRadii*Math.sin(t)*Math.cos(p);\r
+                                       z=BGRadii*Math.sin(p);\r
+                                       xx=x;\r
+                                       yy=SIN*y+COS*z;\r
+\r
+                                       //Set Dotsize and Draw them\r
+                                       BGDot[i].set(BGSize, BGSize);\r
+                                       BGDot[i].centering().shift(xx,yy);\r
+                                       BGDot[i].draw( Color.blue );\r
+                               }\r
+\r
+                               //Calculate positions of targets and set them\r
+                               temp=Rotate*2*Math.PI/360.0;\r
+                               for (int i = 0; i < 5; i++)\r
+                               {\r
+                                       t = 2.0 * Math.PI/TargetNumber;\r
+                                       x = TargetEcce*Math.cos(i*t+temp);\r
+                                       y = TargetEcce*Math.sin(i*t+temp);\r
+                                       Target[i].centering().shift(x,y);\r
+                                       Target[i].fill = Color.yellow;\r
+                                       Target[i].draw();\r
+                               }\r
+\r
+                               img.centering(Mouse.position).draw();\r
+\r
+                               cnvs.var(Mouse.position.x, 100, 100);\r
+                               cnvs.var(Mouse.position.y, 100, 140);\r
+\r
+                               //Reflect drawing at the next frame;\r
+                               cnvs.flip();\r
+                       }\r
+               }\r
+       }\r
+\r
+}\r
+*/\r
+\r
+\r
+/*using Psychlops;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+       public class PsychlopsMain\r
+       {\r
+               public void psychlops_main()\r
+               {\r
+                       var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
+                       var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
+                       var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
+                       var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");\r
+                       var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");\r
+                       var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
+                       var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
+                       var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
+\r
+                       Canvas window = new Canvas(300, 300);\r
+\r
+                       var figure_r = new Rectangle();\r
+                       var figure_e = new Ellipse();\r
+                       Shape figure = figure_r;\r
+                       \r
+                       while (!Keyboard.esc.pushed())\r
+                       {\r
+                               if (System.String.Compare(figure_type, "Rectangle") == 0)\r
+                               {\r
+                                       figure_r.set(size_x, size_y);\r
+                                       figure = figure_r;\r
+                               }\r
+                               else\r
+                               {\r
+                                       figure_e.set(size_x, size_y);\r
+                                       figure = figure_e;\r
+                               }\r
+                               figure.fill = new Color(color_r, color_g, color_b);\r
+\r
+                               window.clear(Color.black);\r
+                               figure.centering().shift(shift_x, shift_y).draw();\r
+                               window.flip();\r
+                       }\r
+               }\r
+       }\r
+\r
+}\r
+\r
+\r
+\r
+\r
+/*\r
+using Psychlops;\r
+\r
+namespace Psychlops\r
+{\r
+\r
+       public class RandomDots\r
+       {\r
+               Rectangle dot;\r
+               public Point[] cood;\r
+               public RandomDots()\r
+               {\r
+                       cood = new Point[250];\r
+                       dot = new Rectangle(5, 5);\r
+               }\r
+               public void draw()\r
+               {\r
+                       dot.fill = Color.white;\r
+                       foreach (Point p in cood)\r
+                       {\r
+                               dot.centering(p).draw();\r
+                       }\r
+               }\r
+       }\r
+\r
+}\r
+\r
+\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+               Canvas cnvs;\r
+               Image img;\r
+               Ellipse fixation;\r
+               Shape shape;\r
+               Color col;\r
+               int isize = 100;\r
+               double tfreq = 1;\r
+               int frames;\r
+               RandomDots dots;\r
+               Group g;\r
+\r
+               public void psychlops_main()\r
+               {\r
+                       cnvs = new Canvas(500, 500);\r
+                       g = new Group();\r
+                       img = new Image(isize * 2, isize * 2);\r
+                       Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
+                       g.append(img);\r
+                       g.rotation = 50;\r
+                       fixation = new Ellipse(10, 10);\r
+                       fixation.fill = Color.red;\r
+                       //var poly = new Rectangle(100, 100);\r
+                       var poly = new Letters("日本語");\r
+                       //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);\r
+                       //var poly = new Ellipse(100, 100);\r
+                       //var poly = new Line(0,0,100, 0);\r
+                       poly.fill = Color.red;\r
+                       poly.stroke = new Stroke { color = Color.yellow, thick = 1 };\r
+                       shape = poly;\r
+\r
+                       var rng = new Interval();\r
+                       var slider = new Psychlops.Widgets.Slider("tesrt", -100 <= rng <= 100);\r
+\r
+                       dots = new RandomDots();\r
+\r
+\r
+                       while (true)\r
+                       {\r
+                               frames++;\r
+\r
+\r
+                               cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));\r
+                               col.set(Math.random(1.0));\r
+\r
+                               /*if (frames % 2 == 0)\r
+                               {\r
+                                       fixation.centering().shift(100, 100);\r
+                                       fixation.draw(new Stroke(Color.blue, 3));\r
+                               }* /\r
+\r
+                               fixation.centering().shift(slider, 0);\r
+                               fixation.draw(Color.red);\r
+\r
+                               //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);\r
+                               //Figures.drawGaussian(ref img, 20, 1);\r
+                               //Figures.drawGrating(ref img, 200, 200, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
+                               //img.centering(Mouse.position);\r
+                               //img.draw();\r
+                               g.centering(Mouse.position).draw();\r
+                               g.rotation += 1;\r
+\r
+                               shape.centering(Mouse.position).shift(100, 0);\r
+                               shape.draw();\r
+                               if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
+\r
+                               cnvs.var(frames, 0, 20);\r
+                               //slider.value = frames / 100.0;\r
+\r
+                               /*if (frames % 2 != 0)\r
+                               {\r
+                                       fixation.shift(100, 100);\r
+                                       fixation.draw(new Stroke(Color.green, 3));\r
+                               }* /\r
+\r
+                               for (int i = 0; i < dots.cood.Length; i++)\r
+                               {\r
+                                       dots.cood[i].set(Math.random(500), Math.random(500));\r
+                               }\r
+                               cnvs.var((double)slider, 200, 200);\r
+                               dots.draw();\r
+\r
+                               cnvs.flip();\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+**/\r
+\r
+\r
+/*\r
+\r
+using Psychlops;\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+               Canvas cnvs;\r
+               Rectangle[] rect;\r
+               int n;\r
+\r
+               public void psychlops_main()\r
+               {\r
+                       n = 1;\r
+                       cnvs = new Canvas(500, 500);\r
+                       rect = new Rectangle[n];\r
+                       for (int i = 0; i < n; i++)\r
+                       {\r
+                               rect[i] = new Rectangle(10, 10);\r
+                               rect[i].fill = Color.red;\r
+                       }\r
+                       Interval rng = new Interval();\r
+                       var slider = new Psychlops.Widgets.Slider("Label", -100 <= rng <= 100);\r
+\r
+                       while (true)\r
+                       {\r
+                               cnvs.clear();\r
+                               for (int i = 0; i < n; i++)\r
+                               {\r
+                                       rect[i].centering().shift(slider * i*3, i*3).draw();\r
+                               }\r
+                               cnvs.flip();\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+*/\r
+\r
+/*\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+       public class PsychlopsMain\r
+       {\r
+               public void psychlops_main()\r
+               {\r
+                       Canvas window = new Canvas(300, 300);\r
+\r
+                       var figure_r = new Rectangle();\r
+                       var figure_e = new Ellipse();\r
+                       figure_r.set(100,100).centering().shift(0, 0);\r
+                       figure_e.set(100,100).centering().shift(0, 0);\r
+\r
+                       while (!Keyboard.esc.pushed())\r
+                       {\r
+                               figure_r.fill = new Color(0, 0, 1);\r
+                               figure_r.centering(new Point(100,100)).draw();\r
+                               figure_e.fill = new Color(1, 0, 0);\r
+                               figure_e.centering(new Point(100, 100)).draw();\r
+                               window.flip();\r
+                       }\r
+               }\r
+       }\r
+\r
+}\r
+\r
+/*\r
+\r
+\r
+\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+       public class PsychlopsMain\r
+       {\r
+               public void psychlops_main()\r
+               {\r
+                       var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
+                       var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
+                       var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
+                       var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
+                       var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
+                       var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
+\r
+                       Canvas window = new Canvas(300, 300);\r
+\r
+                       var figure_r = new Rectangle();\r
+                       var figure_e = new Ellipse();\r
+                       figure_r.centering().shift(0, 0);\r
+                       figure_e.centering().shift(0, 0);\r
+\r
+                       int frame = 0;\r
+                       int direction = 1, motion_dir = 1;\r
+\r
+                       while (!Keyboard.esc.pushed())\r
+                       {\r
+                               window.clear();\r
+\r
+                               if (frame % 30 == 0)\r
+                               {\r
+                                       direction = direction * -1;\r
+\r
+                               }\r
+\r
+                               if (frame % 90 == 0)\r
+                               {\r
+                                       motion_dir *= -1;\r
+                               }\r
+\r
+                               figure_r.resize(figure_r.getWidth() + direction * 1, figure_r.getHeight() + direction * 1);\r
+                               figure_r.shift(motion_dir * 1, 0);\r
+                               figure_r.fill = new Color(color_r, color_g, color_b);\r
+\r
+                               figure_e.resize(figure_e.getWidth() + direction * 1, figure_e.getHeight() + direction * 1);\r
+                               figure_e.shift(motion_dir * 1, 0);\r
+                               figure_e.fill = new Color(color_r, color_g, color_b);\r
+\r
+                               if (System.String.Compare(figure_type, "Rectangle") == 0)\r
+                               {\r
+                                       figure_r.draw();\r
+                               }\r
+                               else\r
+                               {\r
+                                       figure_e.draw();\r
+                               }\r
+\r
+\r
+                               frame++;\r
+\r
+\r
+                               window.flip();\r
+                       }\r
+               }\r
+       }\r
+\r
+}\r
+ * */\r
+\r
+\r
+/*\r
+using Psychlops;\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+       public class PsychlopsMain\r
+       {\r
+               public void psychlops_main()\r
+               {\r
+                       var figure_type = Psychlops.Widgets.Browser.Element.byID("FIGURE");\r
+                       var size_x = Psychlops.Widgets.Browser.Element.byID("SIZE_X");\r
+                       var size_y = Psychlops.Widgets.Browser.Element.byID("SIZE_Y");\r
+                       var shift_x = Psychlops.Widgets.Browser.Element.byID("SHIFT_X");\r
+                       var shift_y = Psychlops.Widgets.Browser.Element.byID("SHIFT_Y");\r
+                       var color_r = Psychlops.Widgets.Browser.Element.byID("COLOR_R");\r
+                       var color_g = Psychlops.Widgets.Browser.Element.byID("COLOR_G");\r
+                       var color_b = Psychlops.Widgets.Browser.Element.byID("COLOR_B");\r
+\r
+                       Canvas window = new Canvas(300, 300);\r
+\r
+                       var figure_r = new Rectangle();\r
+                       var figure_e = new Ellipse();\r
+                       Shape figure = figure_r;\r
+                       \r
+                       while (!Keyboard.esc.pushed())\r
+                       {\r
+                               if (System.String.Compare(figure_type, "Rectangle") == 0)\r
+                               {\r
+                                       figure_r.set(size_x, size_y);\r
+                                       figure = figure_r;\r
+                               }\r
+                               else\r
+                               {\r
+                                       figure_e.set(size_x, size_y);\r
+                                       figure = figure_e;\r
+                               }\r
+                               figure.fill = new Color(color_r, color_g, color_b);\r
+\r
+                               window.clear(Color.black);\r
+                               figure.centering().shift(shift_x, shift_y).draw();\r
+                               window.flip();\r
+                       }\r
+               }\r
+       }\r
+\r
+}\r
+*/\r
+\r
+\r
+/*\r
+using Psychlops;\r
+\r
+namespace Psychlops\r
+{\r
+\r
+       public class RandomDots\r
+       {\r
+               Rectangle dot;\r
+               public Point[] cood;\r
+               public RandomDots()\r
+               {\r
+                       cood = new Point[250];\r
+                       dot = new Rectangle(5, 5);\r
+               }\r
+               public void draw()\r
+               {\r
+                       dot.fill = Color.white;\r
+                       foreach (Point p in cood)\r
+                       {\r
+                               dot.centering(p).draw();\r
+                       }\r
+               }\r
+       }\r
+\r
+}\r
+\r
+\r
+namespace PsychlopsSilverlight4test\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+               Canvas cnvs;\r
+               Image img;\r
+               Rectangle fixation;\r
+               Shape shape;\r
+               Color col;\r
+               int isize = 100;\r
+               double tfreq = 1;\r
+               int frames;\r
+               RandomDots dots;\r
+\r
+               public void psychlops_main()\r
+               {\r
+                       cnvs = new Canvas(500, 500);\r
+                       img = new Image(isize * 2, isize * 2);\r
+                       fixation = new Rectangle(10, 10);\r
+                       fixation.fill = Color.red;\r
+                       //var poly = new Rectangle(100, 100);\r
+                       var poly = new Letters("日本語");\r
+                       //var poly = new Polygon(); poly.append(0, 100); poly.append(-100, 0); poly.append(0, -100); poly.append(100, 0);\r
+                       //var poly = new Ellipse(100, 100);\r
+                       //var poly = new Line(0,0,100, 0);\r
+                       poly.fill = Color.red;\r
+                       poly.stroke = new Stroke { color = Color.yellow, thick = 1 };\r
+                       shape = poly;\r
+\r
+                       var rng = new Interval();\r
+                       var slider = new Psychlops.Widgets.Slider("tesrt", 0 <= rng <= 5);\r
+\r
+                       dots = new RandomDots();\r
+\r
+\r
+                       while(true) {\r
+                               frames++;\r
+                               \r
+                               cnvs.clear(new Color(Mouse.left.pressed() ? 0.75 : 0.5));\r
+                               col.set(Math.random(1.0));\r
+\r
+                               fixation.centering();\r
+                               fixation.draw(Color.red);\r
+\r
+                               //Figures.drawGabor(ref img, 20, 100, 1, 0, frames * 2.0 * Math.PI / tfreq / 60);\r
+                               //Figures.drawGaussian(ref img, 20, 1);\r
+                               Figures.drawGrating(ref img, 30, 30, 20, 1, 2, frames * 2.0 * Math.PI / tfreq / 60);\r
+                               img.centering(Mouse.position);\r
+                               img.draw();\r
+\r
+                               shape.centering(Mouse.position).shift(100,0);\r
+                               shape.draw();\r
+                               if (Keyboard.spc.pressed()) cnvs.var(Mouse.x, 100, 100);\r
+\r
+                               cnvs.var(frames, 20, 20);\r
+                               slider.value = frames/100.0;\r
+\r
+                               fixation.shift(100,100);\r
+                               fixation.draw(new Stroke(Color.blue, 3));\r
+\r
+                               for (int i=0; i<dots.cood.Length; i++)\r
+                               {\r
+                                       dots.cood[i].set(Math.random(500), Math.random(500));\r
+                               }\r
+                               dots.draw();\r
+\r
+                               cnvs.flip();\r
+                       }\r
+               }\r
+       }\r
+\r
+}\r
+*/
\ No newline at end of file
diff --git a/test4/TestPage.html b/test4/TestPage.html
new file mode 100644 (file)
index 0000000..8912261
--- /dev/null
@@ -0,0 +1,305 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> \r
+<html> \r
+       <head> \r
+       \r
+               <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r
+               <meta http-equiv="Content-Style-Type" content="text/css" />\r
+\r
+               <link rel="stylesheet" href="./css/import.css" type="text/css" media="screen,print" />\r
+               <link rel="stylesheet" href="./css/jquery.lightbox-0.5.css" type="text/css" media="screen" />\r
+<link rel="stylesheet" href="./css/tipTip.css" type="text/css" /> \r
+\r
+               <script type="text/javascript" src="./js/raphael-min.js"></script> \r
+               <script type="text/javascript" src="./js/jquery-1.4.2.min.js"></script>\r
+\r
+       <script type="text/javascript" src="./js_basic/jquery-ui-1.8.2.custom.min.js"></script>\r
+\r
+\r
+               <script type="text/javascript" src="./js/loadJSON.js"></script>\r
+\r
+               <script type="text/javascript" src="./js/buttonFunction.js"></script>\r
+               <script type="text/javascript" src="./js/jquery.rollover.js"></script>\r
+\r
+               <script type="text/javascript" src="./js/jquery.tipTip.js"></script> \r
+\r
+               <script type="text/javascript" src="./js/setPos.js"></script>\r
+               <script type="text/javascript" src="./js/createNode.js"></script>\r
+               <script type="text/javascript" src="./js/createVoronoi.js"></script>\r
+\r
+               <script type="text/javascript" src="./js/voronoi.js"></script>\r
+\r
+<script type="text/javascript" src="./js/jquery.tipTip.js"></script> \r
+\r
+\r
+       <script type="text/javascript" src="./js/jquery.cookie.js"></script> \r
+\r
+\r
+\r
+\r
+       <link type="text/css" href="./css_basic/south-street/jquery-ui-1.8.2.custom.css" rel="stylesheet" />\r
+       <script type="text/javascript" src="./js_basic/fg.menu.js"></script>\r
+       <link type="text/css" href="./css_basic/fg.menu.css" rel="stylesheet" />\r
+       <script type="text/javascript" src="./js_basic/jQuery.spinTheWheel.js"></script>\r
+       <script type="text/javascript" src="./js_basic/jquery.highlight-3.js"></script>\r
+\r
+       <script type="text/javascript" src="./js_basic/prettify/prettify.js"></script>\r
+\r
+       <script type="text/javascript" src="./js_basic/silverlight_host.js"></script>\r
+       <link rel="stylesheet" type="text/css" href="./css_basic/silverlight_host.css" media="all">\r
+\r
+       <script type="text/javascript" src="./js_basic/basiccode.js"></script>\r
+       <script type="text/javascript" src="./js_basic/basiccode_function_highlighter.js"></script>\r
+       <link rel="stylesheet" type="text/css" href="./css_basic/basiccode.css" media="all">\r
+\r
+\r
+\r
+\r
+               <script type="text/javascript">\r
+<!--\r
+                       var naviwidth = 200;\r
+                       var naviheight = 800;\r
+\r
+\r
+                       //professionalにリンクするかどうかの判断するため、jsonのデータから情報を得るためのID\r
+                       var currentselectedID = "basiccode_step1";\r
+\r
+                       //JSONからデータを利用するためindex\r
+                       var currentselectedIndex;\r
+\r
+                       //このデモとかかわりのあるlibrarys.jsonのインデックスを格納する配列\r
+                       var professionalIndexs = new Array();\r
+\r
+                       //library.jsonから読み込んだデータを格納する配列\r
+                       var librarys;\r
+\r
+                       //JSONデータをひとまとめにした配列\r
+                       var nodedatas;\r
+\r
+                       //現在開いているページのカテゴリのJSONデータを格納する配列\r
+                       var currentselectedCategory;\r
+\r
+\r
+                       var lang = "jp";\r
+\r
+                       if (window.location.search.length != 0) {\r
+                               var temppath = window.location.search.substring(1);\r
+\r
+                               //lang取得\r
+                               if (temppath != null) {\r
+                                       var templang = temppath.split('=');\r
+                                       if (templang[0] == "lang" && templang[1] == "en") {\r
+                                               lang = "en";\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+\r
+\r
+\r
+                       //JSONを読み込み、処理を開始\r
+                       window.onload = function () {\r
+                               loadParams('./json/library.json', callbackFunc);\r
+                       }\r
+\r
+                       function callbackFunc(params) {\r
+                               librarys = params.library;\r
+                               loadParams('./json/datas.json', callbackFunc1);\r
+                       }\r
+\r
+\r
+\r
+                       function callbackFunc1(params) {\r
+\r
+                               currentselectedCategory = params.articles;\r
+\r
+                               //現在開いているページのIDから、data.jsonの配列インデックスを取得\r
+                               for (i = 0; i < currentselectedCategory.length; i++) {\r
+                                       if (currentselectedCategory[i].id == currentselectedID) currentselectedIndex = i;\r
+                               }\r
+\r
+\r
+                               var paper = Raphael("navi", naviwidth, naviheight);\r
+\r
+                               //カテゴリ別に分けられたJSONのデータをひとまとめにする\r
+                               var nodedatas = new Array();\r
+                               for (i = 0; i < params.visiondemo.length; i++) { nodedatas.push(params.visiondemo[i]); }\r
+                               for (i = 0; i < params.blogparts.length; i++) { nodedatas.push(params.blogparts[i]); }\r
+                               for (i = 0; i < params.articles.length; i++) { nodedatas.push(params.articles[i]); }\r
+\r
+\r
+                               //位置を生成\r
+                               var posdatas = setPos(nodedatas.length, naviwidth - 100, naviheight - 200, 50, 160);\r
+\r
+\r
+                               //母点を生成\r
+                               var generatrices_data = createNode(nodedatas, posdatas, naviwidth, naviheight, paper, lang);\r
+\r
+                               //ボロノイを生成\r
+                               var lines = setVoronoi(posdatas, naviwidth, naviheight);\r
+                               for (n = 0; n < lines.length; n++) {\r
+                                       pa = paper.path("M" + lines[n].sx + " " + lines[n].sy + " L" + lines[n].ex + " " + lines[n].ey);\r
+\r
+                                       pa.attr({ "stroke-width": "0.8" });\r
+                                       pa.attr({ "stroke": "#9D95A4" });\r
+                                       pa.attr({ "opacity": "0.8" });\r
+                               }\r
+\r
+\r
+                               var flgx = 88;\r
+                               var flgy = 54;\r
+                               flg = paper.image("./img/currentpos.png", flgx, 0, 25, 77);\r
+\r
+\r
+\r
+                               //言語を切り替える時に使う\r
+                               url = currentselectedCategory[currentselectedIndex].url;\r
+\r
+\r
+                               $('#header').html(\r
+                               '<span class="highlight"><a href="./index.html"><img id="smalllogo" src="./img/logo_small.png" /></a></span>'\r
+\r
+                               + '<div style="text-align:right; float:right;" >'\r
+                               + '<img id="japanese" src="./img/japanese.png" onclick="buttonJP(url,0)" />'\r
+                               + '<img id="english" src="./img/english.png"  onclick="buttonEN(url,0)"/>'\r
+                               + '</div>'\r
+                               + '<div class="space30px"></div>'\r
+                               + '<h1>Library</h1>'\r
+                       );\r
+\r
+                               $('#tutoriallink1').html(\r
+                               "<a href='./basiccode_step1.html?lang=" + lang + "'>"\r
+                               + "<img src='./img/articles/basiccode01.jpg' />"\r
+                               + "</a>"\r
+                       );\r
+\r
+                               $('#tutoriallink2').html(\r
+                               "<a href='./basiccode_step2.html?lang=" + lang + "'>"\r
+                               + "<img src='./img/articles/basiccode02.jpg' />"\r
+                               + "</a>"\r
+                       );\r
+\r
+\r
+                               setButton(lang);\r
+\r
+                               $('.highlight a img').rollover();\r
+\r
+                               if (lang == "en") {\r
+                                       $("#japanese").hover(function () {\r
+                                               $(this).css("cursor", "pointer");\r
+                                       }, function () {\r
+                                               $(this).css("cursor", "default");\r
+                                       });\r
+                               }\r
+\r
+                               if (lang == "jp") {\r
+                                       $("#english").hover(function () {\r
+                                               $(this).css("cursor", "pointer");\r
+                                       }, function () {\r
+                                               $(this).css("cursor", "default");\r
+                                       });\r
+                               }\r
+                       }\r
+\r
+\r
+                       $(document).ready(function () {\r
+                               $(".tooltip").tipTip({\r
+                                       maxWidth: "auto",\r
+                                       edgeOffset: 0,\r
+                                       fadeIn: 0,\r
+                                       activation: "hover", //click\r
+                                       defaultPosition: "top"\r
+                               });\r
+                       });\r
+\r
+//-->\r
+               </script>\r
+\r
+       </head>\r
+\r
+<body>\r
+<div id="wrapper">\r
+\r
+       <div id="navi">\r
+       <!-- #navi --></div>\r
+       \r
+       <div id="contents">\r
+\r
+               <div id="header"></div>\r
+\r
+\r
+               <div id="title"><h2>Basic Code Step1 </h2></div>\r
+\r
+               <div class="space30px"></div>\r
+\r
+               <div id="codecontents">\r
+       \r
+               <div id="code" style="float:left; width:400px;">\r
+\r
+<pre id="main_code" class="main prettyprint cpp">\r
+///+ Prefix\r
+//// Lines for set up Psychlops environment\r
+#include &lt;psychlops.h&gt;\r
+using namespace Psychlops;\r
+///- Prefix\r
\r
+///+ Main Routine\r
+//// Psychlops runs at the first line of this function psychlops_main().\r
+void psychlops_main() {\r
+       ///+ 1\r
+    //// Set a window for drawing stimulus\r
+    Canvas window(Canvas::window); //Create a window. Here, window variables are preset mode.\r
+    // You can write this statement as" Canvas window(Canvas::fullscreen); " for fullscreen mode\r
+    // or as " Canvas window(1024, 768, 32, 60.0); " This statement changes screenmode to 1024 x 768, 32bit color, 60 Hz refresh.\r
+       ///- 1\r
+       \r
+       ///+ 2\r
+       ////  Set a figure size, position and color.\r
+    Psychlops::Rectangle/*ID:FIGURE selector Rectangle Ellipse*/ figure; //Create a figure (Rectangle or Ellipse) variable.\r
+    \r
+    figure.set( 100/*ID:SIZE_X 1 200 10*/, 100/*ID:SIZE_Y 1 200 10*/ ); // Set the size of figure.\r
+    figure.centering();   // Centering the figure in the window\r
+    figure.shift( 10/*ID:SHIFT_X -100 100 10*/, 10/*ID:SHIFT_Y -100 100 10*/ ); // Displacing the figure by designated vector.    \r
+    figure.draw( Color( 1.0/*ID:COLOR_R 0 1.0 0.1*/, 0.0/*ID:COLOR_G 0.0 1.0 0.1*/, 0.0/*ID:COLOR_B 0 1.0 0.1*/) ); // Drawing the rectangle with a designated color.\r
+    \r
+    window.flip(); // Reflect the drawing for the display by flipping frame buffers.\r
+                   // Till this point, you will not see drawn figures.\r
+       ///- 2\r
+    \r
+       ///+ 3 \r
+       //// Detect a Keyboard input\r
+    while(!Keyboard::esc.pushed()) {} //exit a program when the escape key is pressed down.\r
+    ///- 3\r
\r
+}\r
+///- Main Routine\r
+\r
+</pre>\r
+\r
+       <!-- #code --></div>\r
+\r
+\r
+       <div id="window" style="float:left; width:200px; height:300px; ">\r
+       <div class="desc_child"><span id="xap">Bin/Debug/PsychlopsSilverlight4test.xap</span></div>\r
+       </div>\r
+\r
+       <!-- #codecontents --></div>\r
+\r
+       <div class="clearfix"></div>\r
+\r
+\r
+       <div style="text-align:right;">\r
+       <a class="txt" style="margin-right:200px;" href="./basiccode_step2.html">Next Step>></a>\r
+       </div>\r
+\r
+       <div class="space40px"></div>\r
+       \r
+       <div id="comment">\r
+               上記の文字は<b>Psychlopsのコード</b>です。そしてコードの実行結果はコード右のウィンドウに表示されています。<br />\r
+               コード内の<b>太文字をクリック</b>するとマウス操作で値を変えることができ、結果がすぐに反映されます。\r
+               また、コード内の<b>青い文字をロールオーバ</b>すると、ポップアップで説明が現れます。\r
+       <!-- #comment --></div>\r
+\r
+</div>\r
+<!-- #wrapper --></div>\r
+</body>\r
+</html>\r
index f82402d..6795859 100644 (file)
@@ -1,6 +1,6 @@
 <Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\r
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" \r
-             x:Class="PsychlopsSilverlight4test.App"\r
+             x:Class="PsychlopsSilverlight5test.App"\r
              >\r
     <Application.Resources>\r
         \r
index e091cde..eba91ad 100644 (file)
@@ -10,7 +10,7 @@ using System.Windows.Media;
 using System.Windows.Media.Animation;\r
 using System.Windows.Shapes;\r
 \r
-namespace PsychlopsSilverlight4test\r
+namespace PsychlopsSilverlight5test\r
 {\r
        public partial class App : Application\r
        {\r
@@ -33,22 +33,24 @@ namespace PsychlopsSilverlight4test
                {\r
 \r
                }\r
+\r
                private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)\r
                {\r
-                       // アプリケーションがデバッガーの外側で実行されている場合、ブラウザーの\r
-                       // 例外メカニズムによって例外が報告されます。これにより、IE ではステータス バーに\r
-                       // 黄色の通知アイコンが表示され、Firefox にはスクリプト エラーが表示されます。\r
+                       // If the app is running outside of the debugger then report the exception using\r
+                       // the browser's exception mechanism. On IE this will display it a yellow alert \r
+                       // icon in the status bar and Firefox will display a script error.\r
                        if (!System.Diagnostics.Debugger.IsAttached)\r
                        {\r
 \r
-                               // メモ : これにより、アプリケーションは例外がスローされた後も実行され続け、例外は\r
-                               // ハンドルされません。 \r
-                               // 実稼動アプリケーションでは、このエラー処理は、Web サイトにエラーを報告し、\r
-                               // アプリケーションを停止させるものに置換される必要があります。\r
+                               // NOTE: This will allow the application to continue running after an exception has been thrown\r
+                               // but not handled. \r
+                               // For production applications this error handling should be replaced with something that will \r
+                               // report the error to the website and stop the application.\r
                                e.Handled = true;\r
                                Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });\r
                        }\r
                }\r
+\r
                private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)\r
                {\r
                        try\r
index 6487be3..e445449 100644 (file)
@@ -1,7 +1,8 @@
-<UserControl x:Class="PsychlopsSilverlight4test.MainPage"\r
-    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" \r
+<UserControl x:Class="PsychlopsSilverlight5test.MainPage"\r
+    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\r
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"\r
-    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" \r
+    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"\r
+    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"\r
     mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">\r
        <StackPanel x:Name="TotalRoot">\r
                <Grid>\r
@@ -13,7 +14,7 @@
 \r
                        <StackPanel x:Name="Controller" Grid.Column="0">\r
                        </StackPanel>\r
-                       \r
+\r
                        <Canvas x:Name="LayoutRoot" Grid.Column="1"></Canvas>\r
 \r
                </Grid>\r
index a125451..daeca3d 100644 (file)
@@ -1,13 +1,17 @@
-using Psychlops;\r
-using System;\r
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
 using System.Windows;\r
 using System.Windows.Media;\r
 using System.Windows.Media.Effects;\r
 using System.Windows.Media.Media3D;\r
 \r
+using Psychlops;\r
 \r
-namespace PsychlopsSilverlight4test\r
+\r
+namespace PsychlopsSilverlight5test\r
 {\r
+\r
        public partial class MainPage : System.Windows.Controls.UserControl\r
        {\r
                //System.Collections.Generic.IEnumerator<int> main_routine;\r
@@ -38,7 +42,7 @@ namespace PsychlopsSilverlight4test
                        //main_routine.RunWorkerAsync();\r
 \r
                        main = new PsychlopsSilverlightApp.PsychlopsMain();\r
-//                     Psychlops.AppState.statusBar.\r
+                       //                      Psychlops.AppState.statusBar.\r
                        Psychlops.Internal.Main.routine = new System.Threading.Thread(main.psychlops_main);\r
                        Psychlops.Internal.Main.routine.Start();\r
                        //main.initialize();\r
@@ -50,20 +54,21 @@ namespace PsychlopsSilverlight4test
                        AppStatusBar.Text = "Now starting Psychlops environment... please wait a minute";\r
 \r
 \r
-//eff__ = new Psychlops.Shader.GaborProgram();\r
-//rect__ = new System.Windows.Shapes.Rectangle();\r
-//rect__.Width = 200;\r
-//rect__.Height = 200;\r
-//rect__.Effect = eff__;\r
-//rect__.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue);\r
+                       //eff__ = new Psychlops.Shader.GaborProgram();\r
+                       //rect__ = new System.Windows.Shapes.Rectangle();\r
+                       //rect__.Width = 200;\r
+                       //rect__.Height = 200;\r
+                       //rect__.Effect = eff__;\r
+                       //rect__.Fill = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue);\r
                }\r
-               protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e) {\r
+               protected void getFocusMouseEnter(object sender, System.Windows.Input.MouseEventArgs e)\r
+               {\r
                        this.Focus();\r
-//if(!b) { LayoutRoot.Children.Add(rect__); b = true; }\r
+                       //if(!b) { LayoutRoot.Children.Add(rect__); b = true; }\r
                }\r
-//System.Windows.Shapes.Rectangle rect__;\r
-//Psychlops.Shader.GaborProgram eff__;\r
-//bool b = false;\r
+               //System.Windows.Shapes.Rectangle rect__;\r
+               //Psychlops.Shader.GaborProgram eff__;\r
+               //bool b = false;\r
 \r
                private void CompositionTarget_Rendering(object sender, System.EventArgs e)\r
                {\r
@@ -78,7 +83,4 @@ namespace PsychlopsSilverlight4test
 \r
        }\r
 \r
-\r
-\r
 }\r
-\r
index 151cfa5..a955232 100644 (file)
@@ -3,5 +3,4 @@
 >\r
     <Deployment.Parts>\r
     </Deployment.Parts>\r
-    \r
 </Deployment>\r
index 82192e3..d0e5e5d 100644 (file)
@@ -2,34 +2,34 @@
 using System.Runtime.CompilerServices;\r
 using System.Runtime.InteropServices;\r
 \r
-// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。\r
-// アセンブリに関連付けられている情報を変更するには、\r
-// これらの属性値を変更してください。\r
-[assembly: AssemblyTitle("PsychlopsSilverlight4test")]\r
+// General Information about an assembly is controlled through the following \r
+// set of attributes. Change these attribute values to modify the information\r
+// associated with an assembly.\r
+[assembly: AssemblyTitle("PsychlopsSilverlight5test")]\r
 [assembly: AssemblyDescription("")]\r
 [assembly: AssemblyConfiguration("")]\r
 [assembly: AssemblyCompany("")]\r
-[assembly: AssemblyProduct("PsychlopsSilverlight4test")]\r
-[assembly: AssemblyCopyright("Copyright ©  2010")]\r
+[assembly: AssemblyProduct("PsychlopsSilverlight5test")]\r
+[assembly: AssemblyCopyright("Copyright ©  2012")]\r
 [assembly: AssemblyTrademark("")]\r
 [assembly: AssemblyCulture("")]\r
 \r
-// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから\r
-// 見えなくなります。このアセンブリ内で COM から型にアクセスする必要がある場合は、\r
-// その型の ComVisible 属性を true に設定してください。\r
+// Setting ComVisible to false makes the types in this assembly not visible \r
+// to COM components.  If you need to access a type in this assembly from \r
+// COM, set the ComVisible attribute to true on that type.\r
 [assembly: ComVisible(false)]\r
 \r
-// このプロジェクトが COM に公開される場合、次の GUID がタイプ ライブラリの ID になります。\r
-[assembly: Guid("631fa262-58de-42ab-ba9d-79cb7cf7e289")]\r
+// The following GUID is for the ID of the typelib if this project is exposed to COM\r
+[assembly: Guid("e46af21d-13fa-4844-bb31-0b4b5d85935f")]\r
 \r
-// アセンブリのバージョン情報は、以下の 4 つの値で構成されています。\r
+// Version information for an assembly consists of the following four values:\r
 //\r
 //      Major Version\r
 //      Minor Version \r
 //      Build Number\r
 //      Revision\r
 //\r
-// すべての値を指定するか、下のように '*' を使ってリビジョンおよびビルド番号を\r
-// 既定値にすることができます。\r
+// You can specify all the values or you can default the Revision and Build Numbers \r
+// by using the '*' as shown below:\r
 [assembly: AssemblyVersion("1.0.0.0")]\r
 [assembly: AssemblyFileVersion("1.0.0.0")]\r
index e69a680..f1d7bb8 100644 (file)
-using Psychlops;\r
+//Psychlops Code Template\r
+//    Please visit following web site to get sample codes.\r
+//    http://psychlops.sourceforge.jp/ja/?StartCode\r
+//    CodeDresser at following address is also available to view the code.\r
+//    http://visitope.org/Tools/codedresser.html\r
+\r
+///+ 0 Setup Psychlops Circumstances\r
+//// 0 Setup Psychlops Circumstances\r
+using Psychlops;\r
 \r
 namespace PsychlopsSilverlightApp\r
 {\r
 \r
        public class PsychlopsMain\r
        {\r
+               // Psychlops Win32 1.5.5 / 20110927\r
+               ///- 0 Setup Psychlops Circumstances\r
 \r
+               Psychlops.Widgets.Slider SOAFrames, gap, wavelength, contrast;\r
 \r
                public void psychlops_main() {\r
 \r
+                       ///+ 1 Declaration /////////////////////////////////////////////////////////////\r
+                       //// 1 Declaration\r
+                       // declare default window and variables for its parameters\r
+                       Canvas cnvs = new Canvas(900,600, Canvas.window, Display.primary);\r
+                       double CANVAS_FRAMENUM;\r
+                       int CANVAS_REFRESHRATE;\r
+                       Color DEFAULT_BG_COLOR = new Color();\r
+\r
+                       int gratingwidth = 500, gratingheight = 100;\r
+                       double shift=0.0;\r
+                       Color color = new Color(0.0,0.0,0.0);\r
+                       Rectangle grating = new Rectangle();\r
+\r
+\r
+                       Interval rng = new Interval();\r
+\r
+                       //declare local variables around here\r
+\r
+                       ///- 1 Declaration /////////////////////////////////////////////////////////////\r
+\r
+                       ///+ 2 Initialization //////////////////////////////////////////////////////////\r
+                       //// 2 Initialization\r
+\r
+                       // Set initial values for local variables\r
+                       CANVAS_REFRESHRATE = (int)cnvs.getRefreshRate();\r
+                       CANVAS_FRAMENUM = 0;\r
+                       DEFAULT_BG_COLOR.set(127.0/255.0,127.0/255.0,127.0/255.0,1.0); // default background color is 127/255 mid-gray\r
+\r
+\r
+                       SOAFrames = new Psychlops.Widgets.Slider("SOA Frames", 1  <=rng<=20  ,  1   , 1);\r
+                       SOAFrames.value = 5;\r
+                       gap = new Psychlops.Widgets.Slider("Grating gap" , 0  <=rng<=200 ,  1   , 10);\r
+                       gap.value = 20;\r
+                       wavelength = new Psychlops.Widgets.Slider("Wave Length", 1 <= rng <= 50, 1, 10);\r
+                       wavelength.value = 30.0;\r
+                       contrast = new Psychlops.Widgets.Slider("Contrast"    , 0.0<=rng<=1.0 ,  0.1 , 0.01);\r
+                       contrast.value = 0.1;\r
+\r
+                       // Draw Offline images around here\r
+\r
+                       // Offline Movie calculation using Image array around here\r
+\r
+                       ///- 2 Initialization //////////////////////////////////////////////////////////\r
+\r
+                       ///+ 3 Drawing /////////////////////////////////////////////////////////////////\r
+                       //// 3 Drawing\r
+                       while(!Keyboard.esc.pushed()) {\r
+                       cnvs.clear(DEFAULT_BG_COLOR);\r
+\r
+                       //Write draw commands for realtime figure calculation and drawing around here\r
+\r
+\r
+                       if(Math.mod(CANVAS_FRAMENUM,SOAFrames) == 0){shift += 1;}\r
+\r
+                       grating.set(1,gratingheight).centering().shift(-gratingwidth/2, 0);\r
+                       for(int i=0; i<gratingwidth; i++) {\r
+                               color.set(\r
+                                                       + 0.25*contrast*Math.sin(2*Math.PI*(i*2.0/wavelength + 0.50 * shift))\r
+                                                       + 0.25*contrast*Math.sin(2*Math.PI*(i*3.0/wavelength + 0.75 * shift))\r
+                                                       +0.5\r
+                                                       );\r
+                               grating.shift(1, 0);\r
+                               grating.draw(color);\r
+                       }\r
+\r
+                       grating.set(1,gratingheight).centering().shift(-gratingwidth/2, -gratingheight-gap);\r
+                       for(int i=0; i<gratingwidth; i++) {\r
+                               color.set(\r
+                                                       + 0.25*contrast*Math.sin(2.0*Math.PI*(i*2.0/wavelength + 0.50 * shift))\r
+                                                       +0.5\r
+                                                       );\r
+                               grating.shift(1,0);\r
+                               grating.draw(color);\r
+                       }\r
+\r
+                       grating.set(1,gratingheight).centering().shift(-gratingwidth/2, gratingheight+gap);\r
+                       for(int i=0; i<gratingwidth; i++) {\r
+                               color.set(\r
+                                                       + 0.25*contrast*Math.sin(2.0*Math.PI*(i*3.0/wavelength + 0.75 * shift))\r
+                                                       +0.5\r
+                                                       );\r
+                               grating.shift(1,0);\r
+                               grating.draw(color);\r
+                       }\r
+\r
+                       cnvs.flip();\r
+                       CANVAS_FRAMENUM++;\r
+                       }\r
+                       ///- 3 Drawing /////////////////////////////////////////////////////////////////\r
+\r
+               }\r
+\r
+\r
+       }\r
+\r
+}\r
+\r
+/*\r
+               public void psychlops_main() {\r
+\r
        Canvas display = new Canvas(768,768);\r
 \r
        double rect_size = 100;\r
@@ -132,11 +243,12 @@ Math.PI*Math.sin(Math.PI/2*i+2*Math.PI*phase*TF/refresh);
 \r
 }\r
 \r
-\r
-\r
        }\r
 \r
 }\r
+*/\r
+\r
+\r
 /*\r
 \r
 using Psychlops;\r
diff --git a/test5/PsychlopsSilverlight5test.csproj b/test5/PsychlopsSilverlight5test.csproj
new file mode 100644 (file)
index 0000000..24bdd75
--- /dev/null
@@ -0,0 +1,118 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
+    <ProductVersion>8.0.50727</ProductVersion>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectGuid>{23D94AAA-B4EC-47BD-AD7D-EE6BAD0A909C}</ProjectGuid>\r
+    <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>\r
+    <OutputType>Library</OutputType>\r
+    <AppDesignerFolder>Properties</AppDesignerFolder>\r
+    <RootNamespace>PsychlopsSilverlight5test</RootNamespace>\r
+    <AssemblyName>PsychlopsSilverlight5test</AssemblyName>\r
+    <TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>\r
+    <TargetFrameworkVersion>v5.0</TargetFrameworkVersion>\r
+    <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>\r
+    <SilverlightApplication>true</SilverlightApplication>\r
+    <SupportedCultures>ja</SupportedCultures>\r
+    <XapOutputs>true</XapOutputs>\r
+    <GenerateSilverlightManifest>true</GenerateSilverlightManifest>\r
+    <XapFilename>PsychlopsSilverlight5test.xap</XapFilename>\r
+    <SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>\r
+    <SilverlightAppEntry>PsychlopsSilverlight5test.App</SilverlightAppEntry>\r
+    <TestPageFileName>PsychlopsSilverlight5testTestPage.html</TestPageFileName>\r
+    <CreateTestPage>true</CreateTestPage>\r
+    <ValidateXaml>true</ValidateXaml>\r
+    <EnableOutOfBrowser>false</EnableOutOfBrowser>\r
+    <OutOfBrowserSettingsFile>Properties\OutOfBrowserSettings.xml</OutOfBrowserSettingsFile>\r
+    <UsePlatformExtensions>false</UsePlatformExtensions>\r
+    <ThrowErrorsInValidation>true</ThrowErrorsInValidation>\r
+    <LinkedServerProject>\r
+    </LinkedServerProject>\r
+  </PropertyGroup>\r
+  <!-- This property group is only here to support building this project using the \r
+       MSBuild 3.5 toolset. In order to work correctly with this older toolset, it needs \r
+       to set the TargetFrameworkVersion to v3.5 -->\r
+  <PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">\r
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
+    <DebugSymbols>true</DebugSymbols>\r
+    <DebugType>full</DebugType>\r
+    <Optimize>false</Optimize>\r
+    <OutputPath>Bin\Debug</OutputPath>\r
+    <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>\r
+    <NoStdLib>true</NoStdLib>\r
+    <NoConfig>true</NoConfig>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
+    <DebugType>pdbonly</DebugType>\r
+    <Optimize>true</Optimize>\r
+    <OutputPath>Bin\Release</OutputPath>\r
+    <DefineConstants>TRACE;SILVERLIGHT</DefineConstants>\r
+    <NoStdLib>true</NoStdLib>\r
+    <NoConfig>true</NoConfig>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Reference Include="mscorlib" />\r
+    <Reference Include="System.Windows" />\r
+    <Reference Include="system" />\r
+    <Reference Include="System.Core" />\r
+    <Reference Include="System.Net" />\r
+    <Reference Include="System.Xml" />\r
+    <Reference Include="System.Windows.Browser" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <Compile Include="App.xaml.cs">\r
+      <DependentUpon>App.xaml</DependentUpon>\r
+    </Compile>\r
+    <Compile Include="MainPage.xaml.cs">\r
+      <DependentUpon>MainPage.xaml</DependentUpon>\r
+    </Compile>\r
+    <Compile Include="Properties\AssemblyInfo.cs" />\r
+    <Compile Include="PsychlopsMain.cs" />\r
+    <Compile Include="Store.cs" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ApplicationDefinition Include="App.xaml">\r
+      <SubType>Designer</SubType>\r
+      <Generator>MSBuild:Compile</Generator>\r
+    </ApplicationDefinition>\r
+    <Page Include="MainPage.xaml">\r
+      <SubType>Designer</SubType>\r
+      <Generator>MSBuild:Compile</Generator>\r
+    </Page>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <None Include="Properties\AppManifest.xml" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <Content Include="TestPage.html" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\dev5\PsychlopsSilverlight5.csproj">\r
+      <Project>{1A6795E6-DD87-4D31-86F0-59C991EA6A7F}</Project>\r
+      <Name>PsychlopsSilverlight5</Name>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
+  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />\r
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
+       Other similar extension points exist, see Microsoft.Common.targets.\r
+  <Target Name="BeforeBuild">\r
+  </Target>\r
+  <Target Name="AfterBuild">\r
+  </Target>\r
+  -->\r
+  <ProjectExtensions>\r
+    <VisualStudio>\r
+      <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">\r
+        <SilverlightProjectProperties />\r
+      </FlavorProperties>\r
+    </VisualStudio>\r
+  </ProjectExtensions>\r
+</Project>
\ No newline at end of file