Skip to content

Commit 826057a

Browse files
committed
Minor cleanup and updates to DCEL entities.
* Rename 'Boundary' property of HalfEdge class to 'Label' * Add 'Label' property to Face class and initialize to generator label * Update Voronoi tests.
1 parent 3654aeb commit 826057a

File tree

6 files changed

+57
-33
lines changed

6 files changed

+57
-33
lines changed

src/Triangle.Tests/Voronoi/BoundedVoronoiTest.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@ public class BoundedVoronoiTest
1111
[Test]
1212
public void TestBoundedVoronoi()
1313
{
14-
var p = Helper.SplitRectangle(-1, 1, 1, -1, 3);
14+
int boundaryLabel = 3;
15+
16+
var p = Helper.SplitRectangle(-1, 1, 1, -1, boundaryLabel);
17+
18+
Assert.That(p.Regions.Count, Is.EqualTo(2));
19+
20+
int regionLabel1 = p.Regions[0].Label;
21+
int regionLabel2 = p.Regions[1].Label;
1522

1623
var mesher = new GenericMesher();
1724
var mesh = (Mesh)mesher.Triangulate(p);
1825

1926
var voronoi = new BoundedVoronoi(mesh);
2027

2128
// The "split rectangle" polygon has two region pointer set.
22-
Assert.That(voronoi.Vertices.Count(v => v.Label == 1), Is.EqualTo(2));
23-
Assert.That(voronoi.Vertices.Count(v => v.Label == 2), Is.EqualTo(2));
29+
Assert.That(voronoi.Vertices.Count(v => v.Label == regionLabel1), Is.EqualTo(2));
30+
Assert.That(voronoi.Vertices.Count(v => v.Label == regionLabel2), Is.EqualTo(2));
2431

2532
// The polygon has 6 boundary segments, so the Voronoi diagram
2633
// should have 6 infinite edges (which are projected onto the
@@ -32,6 +39,9 @@ public void TestBoundedVoronoi()
3239
// All Voronoi cells should have a generator vertex.
3340
Assert.That(voronoi.Faces.All(f => f.Generator is not null));
3441

42+
// All Voronoi cells should have the same label as the dual vertex.
43+
Assert.That(voronoi.Faces.All(f => f.Label == boundaryLabel));
44+
3545
// Check DCEL topology (all Voronoi cells should be closed).
3646
Assert.That(voronoi.IsConsistent());
3747
}

src/Triangle.Tests/Voronoi/StandardVoronoiTest.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,23 @@ public class StandardVoronoiTest
1111
[Test]
1212
public void TestStandardVoronoi()
1313
{
14-
var p = Helper.SplitRectangle(-1, 1, 1, -1, 3);
14+
int boundaryLabel = 3;
15+
16+
var p = Helper.SplitRectangle(-1, 1, 1, -1, boundaryLabel);
17+
18+
Assert.That(p.Regions.Count, Is.EqualTo(2));
19+
20+
int regionLabel1 = p.Regions[0].Label;
21+
int regionLabel2 = p.Regions[1].Label;
1522

1623
var mesher = new GenericMesher();
1724
var mesh = (Mesh)mesher.Triangulate(p);
1825

1926
var voronoi = new StandardVoronoi(mesh);
2027

2128
// The "split rectangle" polygon has two region pointer set.
22-
Assert.That(voronoi.Vertices.Count(v => v.Label == 1), Is.EqualTo(2));
23-
Assert.That(voronoi.Vertices.Count(v => v.Label == 2), Is.EqualTo(2));
29+
Assert.That(voronoi.Vertices.Count(v => v.Label == regionLabel1), Is.EqualTo(2));
30+
Assert.That(voronoi.Vertices.Count(v => v.Label == regionLabel2), Is.EqualTo(2));
2431

2532
// The polygon has 6 boundary segments, so the Voronoi diagram
2633
// should have 6 infinite edges.
@@ -30,6 +37,9 @@ public void TestStandardVoronoi()
3037
// All Voronoi cells should have a generator vertex.
3138
Assert.That(voronoi.Faces.All(f => f.Generator is not null));
3239

40+
// All Voronoi cells should have the same label as the dual vertex.
41+
Assert.That(voronoi.Faces.All(f => f.Label == boundaryLabel));
42+
3343
// Check DCEL topology (account for unbounded Voronoi cells).
3444
Assert.That(voronoi.IsConsistent(false));
3545
}

src/Triangle/Topology/DCEL/DcelMesh.cs

+6-18
Original file line numberDiff line numberDiff line change
@@ -48,34 +48,22 @@ protected DcelMesh(bool initialize)
4848
/// <summary>
4949
/// Gets the vertices of the Voronoi diagram.
5050
/// </summary>
51-
public List<Vertex> Vertices
52-
{
53-
get { return vertices; }
54-
}
51+
public List<Vertex> Vertices => vertices;
5552

5653
/// <summary>
5754
/// Gets the list of half-edges specify the Voronoi diagram topology.
5855
/// </summary>
59-
public List<HalfEdge> HalfEdges
60-
{
61-
get { return edges; }
62-
}
56+
public List<HalfEdge> HalfEdges => edges;
6357

6458
/// <summary>
6559
/// Gets the faces of the Voronoi diagram.
6660
/// </summary>
67-
public List<Face> Faces
68-
{
69-
get { return faces; }
70-
}
61+
public List<Face> Faces => faces;
7162

7263
/// <summary>
7364
/// Gets the collection of edges of the Voronoi diagram.
7465
/// </summary>
75-
public IEnumerable<IEdge> Edges
76-
{
77-
get { return EnumerateEdges(); }
78-
}
66+
public IEnumerable<IEdge> Edges => EnumerateEdges();
7967

8068
/// <summary>
8169
/// Check if the DCEL is consistent.
@@ -234,7 +222,7 @@ public void ResolveBoundaryEdges()
234222
var map = new Dictionary<int, HalfEdge>();
235223

236224
// TODO: parallel?
237-
foreach (var edge in this.edges)
225+
foreach (var edge in edges)
238226
{
239227
if (edge.twin == null)
240228
{
@@ -252,7 +240,7 @@ public void ResolveBoundaryEdges()
252240
edge.id = j++;
253241
edge.next = map[edge.twin.origin.id];
254242

255-
this.edges.Add(edge);
243+
edges.Add(edge);
256244
}
257245
}
258246

src/Triangle/Topology/DCEL/Face.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace TriangleNet.Topology.DCEL
1010
using TriangleNet.Geometry;
1111

1212
/// <summary>
13-
/// A face of the DCEL datastructure.
13+
/// A face of the DCEL data structure.
1414
/// </summary>
1515
public class Face
1616
{
@@ -30,7 +30,7 @@ static Face()
3030
#endregion
3131

3232
internal int id;
33-
internal int mark;
33+
internal int label;
3434

3535
// If the face is a Voronoi cell, this is the point that generates the cell.
3636
internal Point generator;
@@ -53,6 +53,18 @@ public int ID
5353
set { id = value; }
5454
}
5555

56+
/// <summary>
57+
/// Gets or sets a general-purpose label.
58+
/// </summary>
59+
/// <remarks>
60+
/// For Voronoi diagrams, this will be the same as the <see cref="Generator"/> label.
61+
/// </remarks>
62+
public int Label
63+
{
64+
get { return label; }
65+
set { label = value; }
66+
}
67+
5668
/// <summary>
5769
/// Gets or sets a half-edge connected to the face.
5870
/// </summary>
@@ -95,6 +107,7 @@ public Face(Point generator, HalfEdge edge)
95107
if (generator != null)
96108
{
97109
id = generator.ID;
110+
label = generator.Label;
98111
}
99112
}
100113

src/Triangle/Topology/DCEL/HalfEdge.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
namespace TriangleNet.Topology.DCEL
88
{
99
/// <summary>
10-
/// A half-edge of the DCEL datastructure.
10+
/// A half-edge of the DCEL data structure.
1111
/// </summary>
1212
public class HalfEdge
1313
{
1414
internal int id;
15-
internal int mark;
15+
internal int label;
1616

1717
internal Vertex origin;
1818
internal Face face;
@@ -29,12 +29,15 @@ public int ID
2929
}
3030

3131
/// <summary>
32-
/// Gets or sets a boundary marker.
32+
/// Gets or sets a general-purpose label.
3333
/// </summary>
34-
public int Boundary
34+
/// <remarks>
35+
/// Can be used to identify boundary segments.
36+
/// </remarks>
37+
public int Label
3538
{
36-
get { return mark; }
37-
set { mark = value; }
39+
get { return label; }
40+
set { label = value; }
3841
}
3942

4043
/// <summary>

src/Triangle/Voronoi/StandardVoronoi.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public StandardVoronoi(Mesh mesh, Rectangle box)
3737
/// Initializes a new instance of the <see cref="StandardVoronoi" /> class.
3838
/// </summary>
3939
/// <param name="mesh">The mesh.</param>
40-
/// <param name="box">The bounding box used for clipping (not implemented.)</param>
40+
/// <param name="box">The bounding box used for clipping (not implemented).</param>
4141
/// <param name="factory"></param>
4242
/// <param name="predicates"></param>
4343
public StandardVoronoi(Mesh mesh, Rectangle box, IVoronoiFactory factory, IPredicates predicates)

0 commit comments

Comments
 (0)