diff --git a/src/Triangle.Examples/Examples/Example1.cs b/src/Triangle.Examples/Examples/Example1.cs
index 202dd7a..5419d48 100644
--- a/src/Triangle.Examples/Examples/Example1.cs
+++ b/src/Triangle.Examples/Examples/Example1.cs
@@ -11,7 +11,7 @@ namespace TriangleNet.Examples
///
public class Example1
{
- public static void Run(bool print = false)
+ public static bool Run(bool print = false)
{
// Generate points.
var points = Generate.RandomPoints(50, new Rectangle(0, 0, 100, 100));
@@ -26,6 +26,8 @@ namespace TriangleNet.Examples
var mesh = mesher.Triangulate(points);
if (print) SvgImage.Save(mesh, "example-1.svg", 500);
+
+ return true;
}
}
}
diff --git a/src/Triangle.Examples/Examples/Example10.cs b/src/Triangle.Examples/Examples/Example10.cs
index 9f6dc16..8574478 100644
--- a/src/Triangle.Examples/Examples/Example10.cs
+++ b/src/Triangle.Examples/Examples/Example10.cs
@@ -18,7 +18,7 @@ namespace TriangleNet.Examples
///
/// Reads all .poly files from given directory and processes them in parallel.
///
- public static void Run(string dir)
+ public static bool Run(string dir)
{
var files = Directory.EnumerateFiles(dir, "*.poly", SearchOption.AllDirectories);
@@ -75,6 +75,8 @@ namespace TriangleNet.Examples
{
Console.WriteLine(" Number of invalid triangulations: {0}", invalid);
}
+
+ return true;
}
private static void ProcessMesh(IMesh mesh, MeshResult result)
diff --git a/src/Triangle.Examples/Examples/Example2.cs b/src/Triangle.Examples/Examples/Example2.cs
index b973c03..e3dd6f1 100644
--- a/src/Triangle.Examples/Examples/Example2.cs
+++ b/src/Triangle.Examples/Examples/Example2.cs
@@ -9,7 +9,7 @@
///
public static class Example2
{
- public static void Run(bool print = false)
+ public static bool Run(bool print = false)
{
// Generate the input geometry.
var poly = CreatePolygon();
@@ -21,6 +21,8 @@
var mesh = poly.Triangulate(quality);
if (print) SvgImage.Save(mesh, "example-2.svg", 500);
+
+ return true;
}
public static IPolygon CreatePolygon(double h = 0.2)
diff --git a/src/Triangle.Examples/Examples/Example3.cs b/src/Triangle.Examples/Examples/Example3.cs
index f8520b2..74fd070 100644
--- a/src/Triangle.Examples/Examples/Example3.cs
+++ b/src/Triangle.Examples/Examples/Example3.cs
@@ -12,12 +12,14 @@ namespace TriangleNet.Examples
///
public class Example3
{
- public static void Run(bool print = false)
+ public static bool Run(bool print = false)
{
// Generate mesh.
var mesh = CreateMesh();
if (print) SvgImage.Save(mesh, "example-3.svg", 500);
+
+ return true;
}
public static IMesh CreateMesh()
diff --git a/src/Triangle.Examples/Examples/Example4.cs b/src/Triangle.Examples/Examples/Example4.cs
index c69f09c..cc1fff6 100644
--- a/src/Triangle.Examples/Examples/Example4.cs
+++ b/src/Triangle.Examples/Examples/Example4.cs
@@ -12,7 +12,7 @@ namespace TriangleNet.Examples
///
public class Example4
{
- public static void Run(bool print = false)
+ public static bool Run(bool print = false)
{
// Generate the input geometry.
var poly = CreatePolygon();
@@ -42,6 +42,8 @@ namespace TriangleNet.Examples
smoother.Smooth(mesh, 5);
if (print) SvgImage.Save(mesh, "example-4.svg", 500);
+
+ return true;
}
public static IPolygon CreatePolygon()
diff --git a/src/Triangle.Examples/Examples/Example5.cs b/src/Triangle.Examples/Examples/Example5.cs
index acd8fc1..ac9cbd2 100644
--- a/src/Triangle.Examples/Examples/Example5.cs
+++ b/src/Triangle.Examples/Examples/Example5.cs
@@ -13,7 +13,7 @@ namespace TriangleNet.Examples
///
public static class Example5
{
- public static void Run(bool print = false)
+ public static bool Run(bool print = false)
{
var mesh = Example3.CreateMesh();
@@ -24,6 +24,8 @@ namespace TriangleNet.Examples
FindBoundary2(mesh);
if (print) SvgImage.Save(mesh, "example-5-2.svg", 500, true, false);
+
+ return true;
}
///
diff --git a/src/Triangle.Examples/Examples/Example6.cs b/src/Triangle.Examples/Examples/Example6.cs
index 2d18c47..739fafa 100644
--- a/src/Triangle.Examples/Examples/Example6.cs
+++ b/src/Triangle.Examples/Examples/Example6.cs
@@ -12,14 +12,14 @@
///
public static class Example6
{
- public static void Run()
+ public static bool Run()
{
// Generate the input geometry.
var polygon = new Polygon(8, true);
// Two intersecting rectangles.
- var A = Generate.Rectangle(0.0, 4.0, 4.0, 0.0, 1);
- var B = Generate.Rectangle(1.0, 5.0, 3.0, 1.0, 2);
+ var A = Generate.Rectangle(0.0, 0.0, 4.0, 4.0, 1);
+ var B = Generate.Rectangle(1.0, 1.0, 4.0, 4.0, 2);
polygon.Add(A);
polygon.Add(B);
@@ -46,6 +46,8 @@
// The xor of A and B.
var xor = mesh.Triangles.Where(t => t.Label == 1 || t.Label == 2);
+
+ return true;
}
}
}
\ No newline at end of file
diff --git a/src/Triangle.Examples/Examples/Example7.cs b/src/Triangle.Examples/Examples/Example7.cs
index 5c18841..06bedc6 100644
--- a/src/Triangle.Examples/Examples/Example7.cs
+++ b/src/Triangle.Examples/Examples/Example7.cs
@@ -14,12 +14,12 @@ namespace TriangleNet.Examples
{
const double MAX_EDGE_LENGTH = 0.2;
- public static void Run(bool print = false)
+ public static bool Run(bool print = false)
{
var poly = new Polygon();
// Generate the input geometry.
- poly.Add(Generate.Rectangle(0.0, 1.0, 1.0, 0.0));
+ poly.Add(Generate.Rectangle(0.0, 0.0, 1.0, 1.0));
// Set minimum angle quality option, ignoring holes.
var quality = new QualityOptions()
@@ -42,6 +42,8 @@ namespace TriangleNet.Examples
}
if (print) SvgImage.Save(mesh, "example-7.svg", 500);
+
+ return true;
}
static bool MaxEdgeLength(ITriangle tri, double area)
diff --git a/src/Triangle.Examples/Examples/Example8.cs b/src/Triangle.Examples/Examples/Example8.cs
index 02b6dcf..8d131ba 100644
--- a/src/Triangle.Examples/Examples/Example8.cs
+++ b/src/Triangle.Examples/Examples/Example8.cs
@@ -12,11 +12,13 @@ namespace TriangleNet.Examples
///
public class Example8
{
- public static void Run()
+ public static bool Run()
{
var mesh = (Mesh)Example3.CreateMesh();
FindAdjacencyMatrix(mesh);
+
+ return true;
}
private static void FindAdjacencyMatrix(Mesh mesh)
diff --git a/src/Triangle.Examples/Examples/Example9.cs b/src/Triangle.Examples/Examples/Example9.cs
index 9b24aa7..a02664b 100644
--- a/src/Triangle.Examples/Examples/Example9.cs
+++ b/src/Triangle.Examples/Examples/Example9.cs
@@ -11,7 +11,7 @@ namespace TriangleNet.Examples
///
public class Example9
{
- public static void Run(bool print = false)
+ public static bool Run(bool print = false)
{
var pts = new List
{
@@ -56,6 +56,8 @@ namespace TriangleNet.Examples
// Random rotation.
poly = Rotate(pts, Math.PI * r.NextDouble());
}
+
+ return true;
}
///
diff --git a/src/Triangle.Examples/Generate.cs b/src/Triangle.Examples/Generate.cs
index ccf8c47..e3864af 100644
--- a/src/Triangle.Examples/Generate.cs
+++ b/src/Triangle.Examples/Generate.cs
@@ -7,10 +7,9 @@ namespace TriangleNet
static class Generate
{
- private const int RANDOM_SEED = 63841;
+ private static readonly Random random = new Random(63841);
- public static List RandomPoints(int n, Rectangle bounds,
- int seed = RANDOM_SEED)
+ public static List RandomPoints(int n, Rectangle bounds)
{
var points = new List(n);
@@ -20,8 +19,6 @@ namespace TriangleNet
var width = bounds.Width;
var height = bounds.Height;
- var random = new Random(seed);
-
for (int i = 0; i < n; i++)
{
double x = random.NextDouble();
@@ -32,17 +29,68 @@ namespace TriangleNet
return points;
}
- public static Contour Rectangle(double left, double top,
- double right, double bottom, int mark = 0)
+ ///
+ /// Creates a rectangle contour.
+ ///
+ public static Contour Rectangle(Rectangle rect, double size = 0d, int label = 0)
{
- var points = new List(4);
+ return Rectangle(rect.X, rect.Y, rect.Width, rect.Height, size, label);
+ }
- points.Add(new Vertex(left, top, mark));
- points.Add(new Vertex(right, top, mark));
- points.Add(new Vertex(right, bottom, mark));
- points.Add(new Vertex(left, bottom, mark));
+ ///
+ /// Creates a rectangle contour.
+ ///
+ public static Contour Rectangle(double x, double y, double width, double height,
+ double size = 0d, int label = 0)
+ {
+ // Horizontal and vertical step sizes.
+ double stepH = 0d;
+ double stepV = 0d;
- return new Contour(points, mark, true);
+ int nH = 1;
+ int nV = 1;
+
+ if (size > 0d)
+ {
+ size = Math.Min(size, Math.Min(width, height));
+
+ nH = (int)Math.Ceiling(width / size);
+ nV = (int)Math.Ceiling(height / size);
+
+ stepH = width / nH;
+ stepV = height / nV;
+ }
+
+ var points = new List(2 * nH + 2 * nV);
+
+ double right = x + width;
+ double top = y + height;
+
+ // Left box boundary points
+ for (int i = 0; i < nV; i++)
+ {
+ points.Add(new Vertex(x, y + i * stepV, label));
+ }
+
+ // Top box boundary points
+ for (int i = 0; i < nH; i++)
+ {
+ points.Add(new Vertex(x + i * stepH, top, label));
+ }
+
+ // Right box boundary points
+ for (int i = 0; i < nV; i++)
+ {
+ points.Add(new Vertex(right, top - i * stepV, label));
+ }
+
+ // Bottom box boundary points
+ for (int i = 0; i < nH; i++)
+ {
+ points.Add(new Vertex(right - i * stepH, y, label));
+ }
+
+ return new Contour(points, label, true);
}
///
diff --git a/src/Triangle.Examples/Program.cs b/src/Triangle.Examples/Program.cs
index 4276026..e0ffef4 100644
--- a/src/Triangle.Examples/Program.cs
+++ b/src/Triangle.Examples/Program.cs
@@ -1,21 +1,32 @@
namespace TriangleNet
{
+ using System;
using TriangleNet.Examples;
class Program
{
static void Main(string[] args)
{
- Example1.Run();
- Example2.Run();
- Example3.Run();
- Example4.Run();
- Example5.Run();
- Example8.Run();
- Example6.Run();
- Example7.Run();
- Example9.Run();
+ Check("Example 1", Example1.Run());
+ Check("Example 2", Example2.Run());
+ Check("Example 3", Example3.Run());
+ Check("Example 4", Example4.Run());
+ Check("Example 5", Example5.Run());
+ Check("Example 6", Example8.Run());
+ Check("Example 7", Example6.Run());
+ Check("Example 8", Example7.Run());
+ Check("Example 9", Example9.Run());
+ }
+
+ static void Check(string item, bool success)
+ {
+ var color = Console.ForegroundColor;
+
+ Console.Write(item + " ");
+ Console.ForegroundColor = success ? ConsoleColor.DarkGreen : ConsoleColor.DarkRed;
+ Console.WriteLine(success ? "OK" : "Failed");
+ Console.ForegroundColor = color;
}
}
}
\ No newline at end of file
diff --git a/src/Triangle.Examples/Triangle.Examples.csproj b/src/Triangle.Examples/Triangle.Examples.csproj
index 4282bd9..e5cf28f 100644
--- a/src/Triangle.Examples/Triangle.Examples.csproj
+++ b/src/Triangle.Examples/Triangle.Examples.csproj
@@ -6,17 +6,9 @@
TriangleNet
-
-
-
-
-
-
-
-
-
+