Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code cleanup #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,4 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
.idea/
6 changes: 3 additions & 3 deletions src/Triangle.Examples/Examples/Example1.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

namespace TriangleNet.Examples
{
using TriangleNet.Geometry;
using TriangleNet.Meshing.Algorithm;
using TriangleNet.Rendering.Text;
using Geometry;
using Meshing.Algorithm;
using Rendering.Text;

/// <summary>
/// Simple point set triangulation.
Expand Down
18 changes: 9 additions & 9 deletions src/Triangle.Examples/Examples/Example10.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace TriangleNet.Examples
using System;
using System.Collections.Generic;
using System.Linq;
using TriangleNet.Geometry;
using Geometry;

/// <summary>
/// Troubleshooting: finding degenerate boundary triangles.
Expand Down Expand Up @@ -33,7 +33,7 @@ public static bool Run(bool print = false)
// The original rectangle.
var poly = Rotate(pts, 0);

for (int i = 0; i < 10; i++)
for (var i = 0; i < 10; i++)
{
var mesh = poly.Triangulate();

Expand Down Expand Up @@ -67,18 +67,18 @@ private static IPolygon Rotate(List<Vertex> points, double radians)
{
var poly = new Polygon(points.Count);

int id = 0;
var id = 0;

foreach (var p in points)
{
double x = p.X;
double y = p.Y;
var x = p.X;
var y = p.Y;

double s = Math.Sin(radians);
double c = Math.Cos(radians);
var s = Math.Sin(radians);
var c = Math.Cos(radians);

double xr = c * x - s * y;
double yr = s * x + c * y;
var xr = c * x - s * y;
var yr = s * x + c * y;

poly.Points.Add(new Vertex(xr, yr) { ID = id++ });
}
Expand Down
12 changes: 6 additions & 6 deletions src/Triangle.Examples/Examples/Example11.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static bool Run(bool print = false)
//var mesh = GetStructuredDataMesh(r);

// Generate function values for mesh points.
double[] data = GetFunctionValues(mesh.Vertices);
var data = GetFunctionValues(mesh.Vertices);

if (print) SvgImage.Save(mesh, "example-11.svg", 500);

Expand All @@ -38,13 +38,13 @@ public static bool Run(bool print = false)

var xyData = InterpolateData((Mesh)mesh, data, xy);

double error = xy.Max(p => Math.Abs(xyData[p.ID] - F(p)));
var error = xy.Max(p => Math.Abs(xyData[p.ID] - F(p)));

// L2 error
//double error = Math.Sqrt(xy.Sum(p => Math.Pow(xyData[p.ID] - F(p), 2)));

// Define tolerance dependent on mesh dimensions and size.
double tolerance = 0.5 * Math.Max(r.Width, r.Height) / SIZE;
var tolerance = 0.5 * Math.Max(r.Width, r.Height) / SIZE;

return error < tolerance;
}
Expand All @@ -62,7 +62,7 @@ private static IMesh GetScatteredDataMesh(Rectangle domain)
{
var r = new Rectangle(domain);

double h = domain.Width / SIZE;
var h = domain.Width / SIZE;

// Generate a rectangle boundary point set (SIZE points on each side).
var input = Generate.Rectangle(r, h);
Expand All @@ -71,7 +71,7 @@ private static IMesh GetScatteredDataMesh(Rectangle domain)
h = -h / 2;
r.Resize(h, h);

int n = Math.Max(1, SIZE * SIZE - input.Points.Count);
var n = Math.Max(1, SIZE * SIZE - input.Points.Count);

// Add more input points (more sampling points, better interpolation).
input.Points.AddRange(Generate.RandomPoints(n, r));
Expand Down Expand Up @@ -105,7 +105,7 @@ private static double[] InterpolateData(Mesh mesh, double[] data, IEnumerable<Po

var qtree = new TriangleQuadTree(mesh);

int i = 0;
var i = 0;

foreach (var p in xy)
{
Expand Down
14 changes: 7 additions & 7 deletions src/Triangle.Examples/Examples/Example2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
namespace TriangleNet.Examples
{
using System.Collections.Generic;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using TriangleNet.Rendering.Text;
using Geometry;
using Meshing;
using Rendering.Text;

/// <summary>
/// Simple point set triangulation with convex hull.
/// </summary>
public class Example2
public sealed class Example2
{
public static bool Run(bool print = false)
{
Expand Down Expand Up @@ -38,7 +38,7 @@ private static bool CheckConvexHull(IEnumerable<ISegment> segments)
{
int first = -1, prev = -1;

Point a = null, b, c;
Point a = new();

var p = RobustPredicates.Default;

Expand All @@ -63,8 +63,8 @@ private static bool CheckConvexHull(IEnumerable<ISegment> segments)
return false;
}

b = s.GetVertex(1);
c = s.GetVertex(0);
Point b = s.GetVertex(1);
Point c = s.GetVertex(0);

// Check whether the convex hull is traversed in counterclockwise.
if (p.CounterClockwise(a, b, c) < 0)
Expand Down
6 changes: 3 additions & 3 deletions src/Triangle.Examples/Examples/Example3.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace TriangleNet.Examples
{
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using TriangleNet.Rendering.Text;
using Geometry;
using Meshing;
using Rendering.Text;

/// <summary>
/// Triangulate a polygon with hole and set minimum angle constraint.
Expand Down
14 changes: 7 additions & 7 deletions src/Triangle.Examples/Examples/Example4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
namespace TriangleNet.Examples
{
using System;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using TriangleNet.Rendering.Text;
using TriangleNet.Smoothing;
using TriangleNet.Tools;
using Geometry;
using Meshing;
using Rendering.Text;
using Smoothing;
using Tools;

/// <summary>
/// Triangulate a polygon with hole with maximum area constraint, followed by mesh smoothing.
Expand Down Expand Up @@ -39,10 +39,10 @@ public static bool Run(bool print = false)
}

// The boundary segment size of the input geometry.
const double h = 0.2;
private const double h = 0.2;

// Parameter to relax the maximum area constraint.
const double relax = 1.45;
private const double relax = 1.45;

public static IMesh CreateMesh()
{
Expand Down
8 changes: 4 additions & 4 deletions src/Triangle.Examples/Examples/Example5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
namespace TriangleNet.Examples
{
using TriangleNet;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using TriangleNet.Rendering.Text;
using TriangleNet.Smoothing;
using Geometry;
using Meshing;
using Rendering.Text;
using Smoothing;

/// <summary>
/// Refine only a part of a polygon mesh by using region pointers and an area constraint.
Expand Down
14 changes: 7 additions & 7 deletions src/Triangle.Examples/Examples/Example6.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ namespace TriangleNet.Examples
{
using System.Collections.Generic;
using TriangleNet;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using TriangleNet.Meshing.Iterators;
using TriangleNet.Rendering.Text;
using Geometry;
using Meshing;
using Meshing.Iterators;
using Rendering.Text;

/// <summary>
/// Two ways finding boundary triangles.
Expand Down Expand Up @@ -41,9 +41,9 @@ private static void FindBoundary1(IMesh mesh, bool neigbours = true)

foreach (var s in mesh.Segments)
{
int label = s.Label;
var label = s.Label;

for (int i = 0; i < 2; i++)
for (var i = 0; i < 2; i++)
{
var vertex = s.GetVertex(i);

Expand Down Expand Up @@ -81,7 +81,7 @@ private static void FindBoundary2(IMesh mesh)

foreach (var vertex in mesh.Vertices)
{
int label = vertex.Label;
var label = vertex.Label;

if (label > 0)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Triangle.Examples/Examples/Example7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
{
using System.Linq;
using TriangleNet;
using TriangleNet.Geometry;
using TriangleNet.Meshing.Iterators;
using TriangleNet.Rendering.Text;
using TriangleNet.Tools;
using TriangleNet.Topology;
using Geometry;
using Meshing.Iterators;
using Rendering.Text;
using Tools;
using Topology;

/// <summary>
/// Boolean operations on mesh regions (intersection, difference, xor).
Expand All @@ -32,7 +32,7 @@ public static bool Run(bool print = false)

// Find a seeding triangle (in this case, the point (2, 2) lies in
// both rectangles).
var seed = (new TriangleQuadTree(mesh)).Query(2.0, 2.0) as Triangle;
var seed = (Triangle)new TriangleQuadTree(mesh).Query(2.0, 2.0);

var iterator = new RegionIterator(mesh);

Expand Down
16 changes: 8 additions & 8 deletions src/Triangle.Examples/Examples/Example8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
namespace TriangleNet.Examples
{
using System;
using TriangleNet.Geometry;
using TriangleNet.Meshing;
using TriangleNet.Meshing.Iterators;
using TriangleNet.Rendering.Text;
using Geometry;
using Meshing;
using Meshing.Iterators;
using Rendering.Text;

/// <summary>
/// Using a user test function to define a maximum edge length constraint.
/// </summary>
public static class Example8
{
const double MAX_EDGE_LENGTH = 0.2;
private const double MAX_EDGE_LENGTH = 0.2;

public static bool Run(bool print = false)
{
Expand All @@ -33,7 +33,7 @@ public static bool Run(bool print = false)
// Validate.
foreach (var e in EdgeIterator.EnumerateEdges(mesh))
{
double length = Math.Sqrt(DistSqr(e.GetVertex(0), e.GetVertex(1)));
var length = Math.Sqrt(DistSqr(e.GetVertex(0), e.GetVertex(1)));

if (length > MAX_EDGE_LENGTH)
{
Expand All @@ -46,7 +46,7 @@ public static bool Run(bool print = false)
return true;
}

static bool MaxEdgeLength(ITriangle tri, double area)
private static bool MaxEdgeLength(ITriangle tri, double area)
{
var p0 = tri.GetVertex(0);
var p1 = tri.GetVertex(1);
Expand All @@ -62,7 +62,7 @@ static bool MaxEdgeLength(ITriangle tri, double area)
return s1 > maxlen || s2 > maxlen || s3 > maxlen;
}

static double DistSqr(Vertex a, Vertex b)
private static double DistSqr(Vertex a, Vertex b)
{
var dx = a.X - b.X;
var dy = a.Y - b.Y;
Expand Down
10 changes: 5 additions & 5 deletions src/Triangle.Examples/Examples/Example9.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace TriangleNet.Examples
using System;
using System.Collections.Generic;
using TriangleNet;
using TriangleNet.Meshing.Iterators;
using TriangleNet.Tools;
using Meshing.Iterators;
using Tools;

/// <summary>
/// Compute the adjacency matrix of the mesh vertices.
Expand All @@ -28,7 +28,7 @@ private static bool FindAdjacencyMatrix(Mesh mesh)

var circulator = new VertexCirculator(mesh);

int k = 0;
var k = 0;

foreach (var vertex in mesh.Vertices)
{
Expand Down Expand Up @@ -63,14 +63,14 @@ private static bool FindAdjacencyMatrix(Mesh mesh)

private static bool CompareArray(int[] a, int[] b)
{
int length = a.Length;
var length = a.Length;

if (b.Length != length)
{
return false;
}

for (int i = 0; i < length; i++)
for (var i = 0; i < length; i++)
{
if (a[i] != b[i])
{
Expand Down
Loading