Skip to content

Commit 37b7635

Browse files
authored
Add a unit test and a fix for the crash in cut (#255)
1 parent 4c2fbd3 commit 37b7635

File tree

2 files changed

+37
-22
lines changed

2 files changed

+37
-22
lines changed

src/main/java/com/esri/core/geometry/Cutter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import com.esri.core.geometry.OperatorCutLocal;
2929

30-
import java.lang.reflect.Array;
3130
import java.util.ArrayList;
3231
import java.util.Arrays;
3332

@@ -138,6 +137,8 @@ static EditShape CutPolyline(boolean bConsiderTouch, Polyline cuttee,
138137
private static ArrayList<CutEvent> _getCutEvents(int orderIndex,
139138
EditShape editShape) {
140139
int pointCount = editShape.getTotalPointCount();
140+
if (pointCount == 0)
141+
return null;
141142

142143
// Sort vertices lexicographically
143144
// Firstly copy allvertices to an array.
@@ -156,8 +157,6 @@ private static ArrayList<CutEvent> _getCutEvents(int orderIndex,
156157
CompareVertices compareVertices = new CompareVertices(orderIndex,
157158
editShape);
158159
vertices.Sort(0, pointCount, new CutterVertexComparer(compareVertices));
159-
// SORTDYNAMICARRAYEX(vertices, index_type, 0, pointCount,
160-
// CutterVertexComparer, compareVertices);
161160

162161
// Find Cut Events
163162
ArrayList<CutEvent> cutEvents = new ArrayList<CutEvent>(0);

src/test/java/com/esri/core/geometry/TestCut.java

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static void testCut4326() {
5151

5252
}
5353

54-
public static void testConsiderTouch1(SpatialReference spatialReference) {
54+
private static void testConsiderTouch1(SpatialReference spatialReference) {
5555
OperatorFactoryLocal engine = OperatorFactoryLocal.getInstance();
5656
OperatorCut opCut = (OperatorCut) engine.getOperator(Operator.Type.Cut);
5757

@@ -101,7 +101,7 @@ public static void testConsiderTouch1(SpatialReference spatialReference) {
101101
assertTrue(cut == null);
102102
}
103103

104-
public static void testConsiderTouch2(SpatialReference spatialReference) {
104+
private static void testConsiderTouch2(SpatialReference spatialReference) {
105105
OperatorFactoryLocal engine = OperatorFactoryLocal.getInstance();
106106
OperatorCut opCut = (OperatorCut) engine.getOperator(Operator.Type.Cut);
107107

@@ -167,7 +167,7 @@ public static void testConsiderTouch2(SpatialReference spatialReference) {
167167
assertTrue(cut == null);
168168
}
169169

170-
public static void testPolygon5(SpatialReference spatialReference) {
170+
private static void testPolygon5(SpatialReference spatialReference) {
171171
OperatorFactoryLocal engine = OperatorFactoryLocal.getInstance();
172172
OperatorCut opCut = (OperatorCut) engine.getOperator(Operator.Type.Cut);
173173

@@ -201,7 +201,7 @@ public static void testPolygon5(SpatialReference spatialReference) {
201201
assertTrue(cut == null);
202202
}
203203

204-
public static void testPolygon7(SpatialReference spatialReference) {
204+
private static void testPolygon7(SpatialReference spatialReference) {
205205
OperatorFactoryLocal engine = OperatorFactoryLocal.getInstance();
206206
OperatorCut opCut = (OperatorCut) engine.getOperator(Operator.Type.Cut);
207207

@@ -238,7 +238,7 @@ public static void testPolygon7(SpatialReference spatialReference) {
238238
assertTrue(cut == null);
239239
}
240240

241-
public static void testPolygon8(SpatialReference spatialReference) {
241+
private static void testPolygon8(SpatialReference spatialReference) {
242242
OperatorFactoryLocal engine = OperatorFactoryLocal.getInstance();
243243
OperatorCut opCut = (OperatorCut) engine.getOperator(Operator.Type.Cut);
244244

@@ -275,7 +275,7 @@ public static void testPolygon8(SpatialReference spatialReference) {
275275
assertTrue(cut == null);
276276
}
277277

278-
public static void testPolygon9(SpatialReference spatialReference) {
278+
private static void testPolygon9(SpatialReference spatialReference) {
279279
OperatorFactoryLocal engine = OperatorFactoryLocal.getInstance();
280280
OperatorCut opCut = (OperatorCut) engine.getOperator(Operator.Type.Cut);
281281

@@ -309,7 +309,7 @@ public static void testPolygon9(SpatialReference spatialReference) {
309309
assertTrue(cut == null);
310310
}
311311

312-
public static void testEngine(SpatialReference spatialReference) {
312+
private static void testEngine(SpatialReference spatialReference) {
313313
Polygon polygon8 = makePolygon8();
314314
Polyline cutter8 = makePolygonCutter8();
315315

@@ -337,7 +337,7 @@ public static void testEngine(SpatialReference spatialReference) {
337337
assertTrue(area == 800);
338338
}
339339

340-
public static Polyline makePolyline1() {
340+
private static Polyline makePolyline1() {
341341
Polyline poly = new Polyline();
342342

343343
poly.startPath(0, 0);
@@ -355,7 +355,7 @@ public static Polyline makePolyline1() {
355355
return poly;
356356
}
357357

358-
public static Polyline makePolylineCutter1() {
358+
private static Polyline makePolylineCutter1() {
359359
Polyline poly = new Polyline();
360360

361361
poly.startPath(1, 0);
@@ -395,7 +395,7 @@ public static Polyline makePolylineCutter1() {
395395
return poly;
396396
}
397397

398-
public static Polyline makePolyline2() {
398+
private static Polyline makePolyline2() {
399399
Polyline poly = new Polyline();
400400

401401
poly.startPath(-2, 0);
@@ -410,7 +410,7 @@ public static Polyline makePolyline2() {
410410
return poly;
411411
}
412412

413-
public static Polyline makePolylineCutter2() {
413+
private static Polyline makePolylineCutter2() {
414414
Polyline poly = new Polyline();
415415

416416
poly.startPath(-1.5, 0);
@@ -443,7 +443,7 @@ public static Polyline makePolylineCutter2() {
443443
return poly;
444444
}
445445

446-
public static Polygon makePolygon5() {
446+
private static Polygon makePolygon5() {
447447
Polygon poly = new Polygon();
448448

449449
poly.startPath(0, 0);
@@ -454,7 +454,7 @@ public static Polygon makePolygon5() {
454454
return poly;
455455
}
456456

457-
public static Polyline makePolygonCutter5() {
457+
private static Polyline makePolygonCutter5() {
458458
Polyline poly = new Polyline();
459459

460460
poly.startPath(15, 0);
@@ -466,7 +466,7 @@ public static Polyline makePolygonCutter5() {
466466
return poly;
467467
}
468468

469-
public static Polygon makePolygon7() {
469+
private static Polygon makePolygon7() {
470470
Polygon poly = new Polygon();
471471

472472
poly.startPath(0, 0);
@@ -477,7 +477,7 @@ public static Polygon makePolygon7() {
477477
return poly;
478478
}
479479

480-
public static Polyline makePolygonCutter7() {
480+
private static Polyline makePolygonCutter7() {
481481
Polyline poly = new Polyline();
482482

483483
poly.startPath(10, 10);
@@ -489,7 +489,7 @@ public static Polyline makePolygonCutter7() {
489489
return poly;
490490
}
491491

492-
public static Polygon makePolygon8() {
492+
private static Polygon makePolygon8() {
493493
Polygon poly = new Polygon();
494494

495495
poly.startPath(0, 0);
@@ -500,7 +500,7 @@ public static Polygon makePolygon8() {
500500
return poly;
501501
}
502502

503-
public static Polyline makePolygonCutter8() {
503+
private static Polyline makePolygonCutter8() {
504504
Polyline poly = new Polyline();
505505

506506
poly.startPath(10, 10);
@@ -512,7 +512,7 @@ public static Polyline makePolygonCutter8() {
512512
return poly;
513513
}
514514

515-
public static Polygon makePolygon9() {
515+
private static Polygon makePolygon9() {
516516
Polygon poly = new Polygon();
517517

518518
poly.startPath(0, 0);
@@ -533,12 +533,28 @@ public static Polygon makePolygon9() {
533533
return poly;
534534
}
535535

536-
public static Polyline makePolygonCutter9() {
536+
private static Polyline makePolygonCutter9() {
537537
Polyline poly = new Polyline();
538538

539539
poly.startPath(5, -1);
540540
poly.lineTo(5, 51);
541541

542542
return poly;
543543
}
544+
545+
@Test
546+
public void testGithubIssue253() {
547+
//https://github.com/Esri/geometry-api-java/issues/253
548+
SpatialReference spatialReference = SpatialReference.create(3857);
549+
Polyline poly1 = new Polyline();
550+
poly1.startPath(610, 552);
551+
poly1.lineTo(610, 552);
552+
Polyline poly2 = new Polyline();
553+
poly2.startPath(610, 552);
554+
poly2.lineTo(610, 552);
555+
GeometryCursor cursor = OperatorCut.local().execute(true, poly1, poly2, spatialReference, null);
556+
557+
Geometry res = cursor.next();
558+
assertTrue(res == null);
559+
}
544560
}

0 commit comments

Comments
 (0)