@@ -58,7 +58,7 @@ public void Init(IPool pool)
5858 public void Reset ( IPool pool )
5959 {
6060 _eUp = null ;
61- _nodeUp = null ;
61+ _nodeUp = null ; // don't return to pool as Dict takes care of that
6262 _windingNumber = 0 ;
6363 _inside = false ;
6464 _sentinel = false ;
@@ -129,7 +129,7 @@ private void DeleteRegion(ActiveRegion reg)
129129 }
130130 reg . _eUp . _activeRegion = null ;
131131 _dict . Remove ( reg . _nodeUp ) ;
132- _pool . Return ( reg ) ;
132+ _pool . Return ( ref reg ) ;
133133 }
134134
135135 /// <summary>
@@ -609,7 +609,7 @@ private bool CheckForIntersect(ActiveRegion regUp)
609609 {
610610 // Easy case -- intersection at one of the right endpoints
611611 CheckForRightSplice ( regUp ) ;
612- _pool . Return ( isect ) ;
612+ _pool . Return ( ref isect ) ;
613613 return false ;
614614 }
615615
@@ -630,7 +630,7 @@ private bool CheckForIntersect(ActiveRegion regUp)
630630 eUp = RegionBelow ( regUp ) . _eUp ;
631631 FinishLeftRegions ( RegionBelow ( regUp ) , regLo ) ;
632632 AddRightEdges ( regUp , eUp . _Oprev , eUp , eUp , true ) ;
633- _pool . Return ( isect ) ;
633+ _pool . Return ( ref isect ) ;
634634 return true ;
635635 }
636636 if ( dstUp == _event ) {
@@ -643,7 +643,7 @@ private bool CheckForIntersect(ActiveRegion regUp)
643643 regLo . _eUp = eLo . _Oprev ;
644644 eLo = FinishLeftRegions ( regLo , null ) ;
645645 AddRightEdges ( regUp , eLo . _Onext , eUp . _Rprev , e , true ) ;
646- _pool . Return ( isect ) ;
646+ _pool . Return ( ref isect ) ;
647647 return true ;
648648 }
649649 // Special case: called from ConnectRightVertex. If either
@@ -664,7 +664,7 @@ private bool CheckForIntersect(ActiveRegion regUp)
664664 eLo . _Org . _t = _event . _t ;
665665 }
666666 // leave the rest for ConnectRightVertex
667- _pool . Return ( isect ) ;
667+ _pool . Return ( ref isect ) ;
668668 return false ;
669669 }
670670
@@ -680,7 +680,7 @@ private bool CheckForIntersect(ActiveRegion regUp)
680680 _mesh . Splice ( _pool , eLo . _Oprev , eUp ) ;
681681 eUp . _Org . _s = isect . _s ;
682682 eUp . _Org . _t = isect . _t ;
683- _pool . Return ( isect ) ;
683+ _pool . Return ( ref isect ) ;
684684 isect = null ;
685685 eUp . _Org . _pqHandle = _pq . Insert ( eUp . _Org ) ;
686686 if ( eUp . _Org . _pqHandle . _handle == PQHandle . Invalid )
@@ -933,7 +933,7 @@ private void ConnectLeftVertex(MeshUtils.Vertex vEvent)
933933 // Get a pointer to the active region containing vEvent
934934 tmp . _eUp = vEvent . _anEdge . _Sym ;
935935 var regUp = _dict . Find ( tmp ) . Key ;
936- _pool . Return ( tmp ) ;
936+ _pool . Return ( ref tmp ) ;
937937 var regLo = RegionBelow ( regUp ) ;
938938 if ( regLo == null )
939939 {
@@ -1064,7 +1064,14 @@ private void AddSentinel(Real smin, Real smax, Real t)
10641064 /// </summary>
10651065 private void InitEdgeDict ( )
10661066 {
1067- _dict = new Dict < ActiveRegion > ( EdgeLeq ) ;
1067+ if ( _dict == null )
1068+ {
1069+ _dict = new Dict < ActiveRegion > ( _pool , EdgeLeq ) ;
1070+ }
1071+ else
1072+ {
1073+ _dict . Init ( ) ;
1074+ }
10681075
10691076 AddSentinel ( - SentinelCoord , SentinelCoord , - SentinelCoord ) ;
10701077 AddSentinel ( - SentinelCoord , SentinelCoord , + SentinelCoord ) ;
@@ -1089,7 +1096,8 @@ private void DoneEdgeDict()
10891096 DeleteRegion ( reg ) ;
10901097 }
10911098
1092- _dict = null ;
1099+ Debug . Assert ( _dict . Empty ) ;
1100+ _dict . Reset ( ) ;
10931101 }
10941102
10951103 /// <summary>
@@ -1149,8 +1157,11 @@ private void InitPriorityQ()
11491157 }
11501158 // Make sure there is enough space for sentinels.
11511159 vertexCount += 8 ;
1152-
1153- _pq = new PriorityQueue < MeshUtils . Vertex > ( vertexCount , Geom . VertLeq ) ;
1160+
1161+ if ( _pq == null )
1162+ {
1163+ _pq = new PriorityQueue < MeshUtils . Vertex > ( vertexCount , Geom . VertLeq ) ;
1164+ }
11541165
11551166 vHead = _mesh . _vHead ;
11561167 for ( v = vHead . _next ; v != vHead ; v = v . _next ) {
@@ -1165,7 +1176,7 @@ private void InitPriorityQ()
11651176
11661177 private void DonePriorityQ ( )
11671178 {
1168- _pq = null ;
1179+ Debug . Assert ( _pq . Empty ) ;
11691180 }
11701181
11711182 /// <summary>
0 commit comments