@@ -9,9 +9,24 @@ public class Delaunator
99 private readonly double EPSILON = Math . Pow ( 2 , - 52 ) ;
1010 private readonly int [ ] EDGE_STACK = new int [ 512 ] ;
1111
12+ /// <summary>
13+ /// One value per half-edge, containing the point index of where a given half edge starts.
14+ /// </summary>
1215 public int [ ] Triangles { get ; private set ; }
16+
17+ /// <summary>
18+ /// One value per half-edge, containing the opposite half-edge in the adjacent triangle, or -1 if there is no adjacent triangle
19+ /// </summary>
1320 public int [ ] Halfedges { get ; private set ; }
21+
22+ /// <summary>
23+ /// The initial points Delaunator was constructed with.
24+ /// </summary>
1425 public IPoint [ ] Points { get ; private set ; }
26+
27+ /// <summary>
28+ /// A list of point indices that traverses the hull of the points.
29+ /// </summary>
1530 public int [ ] Hull { get ; private set ; }
1631
1732 private readonly int hashSize ;
@@ -560,18 +575,18 @@ public IEnumerable<IVoronoiCell> GetVoronoiCells(Func<int, IPoint> triangleVerti
560575 var seen = new HashSet < int > ( ) ;
561576 var vertices = new List < IPoint > ( 10 ) ; // Keep it outside the loop, reuse capacity, less resizes.
562577
563- for ( var triangleId = 0 ; triangleId < Triangles . Length ; triangleId ++ )
578+ for ( var e = 0 ; e < Triangles . Length ; e ++ )
564579 {
565- var id = Triangles [ NextHalfedge ( triangleId ) ] ;
580+ var pointIndex = Triangles [ NextHalfedge ( e ) ] ;
566581 // True if element was added, If resize the set? O(n) : O(1)
567- if ( seen . Add ( id ) )
582+ if ( seen . Add ( pointIndex ) )
568583 {
569- foreach ( var edge in EdgesAroundPoint ( triangleId ) )
584+ foreach ( var edge in EdgesAroundPoint ( e ) )
570585 {
571586 // triangleVerticeSelector cant be null, no need to check before invoke (?.).
572587 vertices . Add ( triangleVerticeSelector . Invoke ( TriangleOfEdge ( edge ) ) ) ;
573588 }
574- yield return new VoronoiCell ( id , vertices . ToArray ( ) ) ;
589+ yield return new VoronoiCell ( pointIndex , vertices . ToArray ( ) ) ;
575590 vertices . Clear ( ) ; // Clear elements, keep capacity
576591 }
577592 }
@@ -690,6 +705,9 @@ public void ForEachVoronoiCell(Action<IVoronoiCell> callback, Func<int, IPoint>
690705 #endregion ForEachMethods
691706
692707 #region Methods based on index
708+ /// <summary>
709+ /// Returns the half-edges that share a start point with the given half edge, in order.
710+ /// </summary>
693711 public IEnumerable < int > EdgesAroundPoint ( int start )
694712 {
695713 var incoming = start ;
@@ -700,13 +718,22 @@ public IEnumerable<int> EdgesAroundPoint(int start)
700718 incoming = Halfedges [ outgoing ] ;
701719 } while ( incoming != - 1 && incoming != start ) ;
702720 }
721+
722+ /// <summary>
723+ /// Returns the three point indices of a given triangle id.
724+ /// </summary>
703725 public IEnumerable < int > PointsOfTriangle ( int t )
704726 {
705727 foreach ( var edge in EdgesOfTriangle ( t ) )
706728 {
707729 yield return Triangles [ edge ] ;
708730 }
709731 }
732+
733+ /// <summary>
734+ /// Returns the triangle ids adjacent to the given triangle id.
735+ /// Will return up to three values.
736+ /// </summary>
710737 public IEnumerable < int > TrianglesAdjacentToTriangle ( int t )
711738 {
712739 var adjacentTriangles = new List < int > ( ) ;
@@ -724,7 +751,15 @@ public IEnumerable<int> TrianglesAdjacentToTriangle(int t)
724751
725752 public static int NextHalfedge ( int e ) => ( e % 3 == 2 ) ? e - 2 : e + 1 ;
726753 public static int PreviousHalfedge ( int e ) => ( e % 3 == 0 ) ? e + 2 : e - 1 ;
754+
755+ /// <summary>
756+ /// Returns the three half-edges of a given triangle id.
757+ /// </summary>
727758 public static int [ ] EdgesOfTriangle ( int t ) => new int [ ] { 3 * t , 3 * t + 1 , 3 * t + 2 } ;
759+
760+ /// <summary>
761+ /// Returns the triangle id of a given half-edge.
762+ /// </summary>
728763 public static int TriangleOfEdge ( int e ) { return e / 3 ; }
729764 #endregion Methods based on index
730765 }
0 commit comments