2424package com .esri .core .geometry ;
2525
2626class Boundary {
27+
28+ static boolean hasNonEmptyBoundary (Geometry geom ,
29+ ProgressTracker progress_tracker ) {
30+ if (geom .isEmpty ())
31+ return false ;
32+
33+ Geometry .Type gt = geom .getType ();
34+ if (gt == Geometry .Type .Polygon ) {
35+ if (geom .calculateArea2D () == 0 )
36+ return false ;
37+
38+ return true ;
39+ } else if (gt == Geometry .Type .Polyline ) {
40+ boolean [] b = new boolean [1 ];
41+ b [0 ] = false ;
42+ calculatePolylineBoundary_ (geom ._getImpl (), progress_tracker , true ,
43+ b );
44+ return b [0 ];
45+ } else if (gt == Geometry .Type .Envelope ) {
46+ return true ;
47+ } else if (Geometry .isSegment (gt .value ())) {
48+ if (!((Segment ) geom ).isClosed ()) {
49+ return true ;
50+ }
51+
52+ return false ;
53+ } else if (Geometry .isPoint (gt .value ())) {
54+ return false ;
55+ }
56+
57+ return false ;
58+ }
59+
2760 static Geometry calculate (Geometry geom , ProgressTracker progress_tracker ) {
2861 int gt = geom .getType ().value ();
2962 if (gt == Geometry .GeometryType .Polygon ) {
3063 Polyline dst = new Polyline (geom .getDescription ());
31- if (!geom .isEmpty ()) {
32- ((MultiPathImpl )geom ._getImpl ())._copyToUnsafe ((MultiPathImpl )dst ._getImpl ());
64+ if (!geom .isEmpty ()) {
65+ ((MultiPathImpl ) geom ._getImpl ())
66+ ._copyToUnsafe ((MultiPathImpl ) dst ._getImpl ());
3367 }
3468
3569 return dst ;
3670 } else if (gt == Geometry .GeometryType .Polyline ) {
37- return calculatePolylineBoundary_ (geom ._getImpl (), progress_tracker );
71+ return calculatePolylineBoundary_ (geom ._getImpl (),
72+ progress_tracker , false , null );
3873 } else if (gt == Geometry .GeometryType .Envelope ) {
3974 Polyline dst = new Polyline (geom .getDescription ());
4075 if (!geom .isEmpty ())
@@ -98,9 +133,15 @@ public double getValue(int index) {
98133 }
99134
100135 static MultiPoint calculatePolylineBoundary_ (Object impl ,
101- ProgressTracker progress_tracker ) {
136+ ProgressTracker progress_tracker ,
137+ boolean only_check_non_empty_boundary , boolean [] not_empty ) {
138+ if (not_empty != null )
139+ not_empty [0 ] = false ;
102140 MultiPathImpl mpImpl = (MultiPathImpl ) impl ;
103- MultiPoint dst = new MultiPoint (mpImpl .getDescription ());
141+ MultiPoint dst = null ;
142+ if (!only_check_non_empty_boundary )
143+ dst = new MultiPoint (mpImpl .getDescription ());
144+
104145 if (!mpImpl .isEmpty ()) {
105146 AttributeStreamOfInt32 indices = new AttributeStreamOfInt32 (0 );
106147 indices .reserve (mpImpl .getPathCount () * 2 );
@@ -151,6 +192,12 @@ static MultiPoint calculatePolylineBoundary_(Object impl,
151192 } else {
152193 if ((counter & 1 ) == 0 ) {// remove boundary point
153194 indices .set (ind , NumberUtils .intMax ());
195+ } else {
196+ if (only_check_non_empty_boundary ) {
197+ if (not_empty != null )
198+ not_empty [0 ] = true ;
199+ return null ;
200+ }
154201 }
155202
156203 ptPrev .setCoords (pt );
@@ -161,20 +208,30 @@ static MultiPoint calculatePolylineBoundary_(Object impl,
161208
162209 if ((counter & 1 ) == 0 ) {// remove the point
163210 indices .set (ind , NumberUtils .intMax ());
211+ } else {
212+ if (only_check_non_empty_boundary ) {
213+ if (not_empty != null )
214+ not_empty [0 ] = true ;
215+ return null ;
216+ }
164217 }
218+ if (!only_check_non_empty_boundary ) {
219+ indices .sort (0 , indices .size ());
165220
166- indices .sort (0 , indices .size ());
167-
168- for (int i = 0 , n = indices .size (); i < n ; i ++) {
169- if (indices .get (i ) == NumberUtils .intMax ())
170- break ;
221+ for (int i = 0 , n = indices .size (); i < n ; i ++) {
222+ if (indices .get (i ) == NumberUtils .intMax ())
223+ break ;
171224
172- mpImpl .getPointByVal (indices .get (i ), point );
173- dst .add (point );
225+ mpImpl .getPointByVal (indices .get (i ), point );
226+ dst .add (point );
227+ }
174228 }
175229 }
176230 }
177231
232+ if (only_check_non_empty_boundary )
233+ return null ;
234+
178235 return dst ;
179236 }
180237}
0 commit comments