Update examples.

This commit is contained in:
wo80
2022-03-05 20:49:49 +01:00
parent 4484c6c31a
commit 1383b57f0a
13 changed files with 115 additions and 44 deletions
+3 -1
View File
@@ -11,7 +11,7 @@ namespace TriangleNet.Examples
/// </summary>
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;
}
}
}
+3 -1
View File
@@ -18,7 +18,7 @@ namespace TriangleNet.Examples
/// <summary>
/// Reads all .poly files from given directory and processes them in parallel.
/// </summary>
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)
+3 -1
View File
@@ -9,7 +9,7 @@
/// </summary>
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)
+3 -1
View File
@@ -12,12 +12,14 @@ namespace TriangleNet.Examples
/// </summary>
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()
+3 -1
View File
@@ -12,7 +12,7 @@ namespace TriangleNet.Examples
/// </summary>
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()
+3 -1
View File
@@ -13,7 +13,7 @@ namespace TriangleNet.Examples
/// </summary>
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;
}
/// <summary>
+5 -3
View File
@@ -12,14 +12,14 @@
/// </summary>
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;
}
}
}
+4 -2
View File
@@ -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)
+3 -1
View File
@@ -12,11 +12,13 @@ namespace TriangleNet.Examples
/// </summary>
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)
+3 -1
View File
@@ -11,7 +11,7 @@ namespace TriangleNet.Examples
/// </summary>
public class Example9
{
public static void Run(bool print = false)
public static bool Run(bool print = false)
{
var pts = new List<Vertex>
{
@@ -56,6 +56,8 @@ namespace TriangleNet.Examples
// Random rotation.
poly = Rotate(pts, Math.PI * r.NextDouble());
}
return true;
}
/// <summary>