Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 7f1bc70

Browse files
authored
Merge pull request #11 from NoyaD9/cleanups
cleanup some warnings
2 parents 11d5fbf + 27fce7f commit 7f1bc70

10 files changed

Lines changed: 157 additions & 167 deletions

File tree

Clipper/src/de/lighti/clipper/Clipper.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,52 @@
33
import de.lighti.clipper.Point.LongPoint;
44

55
public interface Clipper {
6-
public enum ClipType {
6+
enum ClipType {
77
INTERSECTION, UNION, DIFFERENCE, XOR
88
}
99

1010
enum Direction {
1111
RIGHT_TO_LEFT, LEFT_TO_RIGHT
12-
};
12+
}
1313

14-
public enum EndType {
14+
enum EndType {
1515
CLOSED_POLYGON, CLOSED_LINE, OPEN_BUTT, OPEN_SQUARE, OPEN_ROUND
16-
};
16+
}
1717

18-
public enum JoinType {
18+
enum JoinType {
1919
SQUARE, ROUND, MITER
20-
};
20+
}
2121

22-
public enum PolyFillType {
22+
enum PolyFillType {
2323
EVEN_ODD, NON_ZERO, POSITIVE, NEGATIVE
24-
};
24+
}
2525

26-
public enum PolyType {
26+
enum PolyType {
2727
SUBJECT, CLIP
28-
};
28+
}
2929

30-
public interface ZFillCallback {
31-
void zFill( LongPoint bot1, LongPoint top1, LongPoint bot2, LongPoint top2, LongPoint pt );
32-
};
30+
interface ZFillCallback {
31+
void zFill(LongPoint bot1, LongPoint top1, LongPoint bot2, LongPoint top2, LongPoint pt);
32+
}
3333

3434
//InitOptions that can be passed to the constructor ...
35-
public final static int REVERSE_SOLUTION = 1;
35+
int REVERSE_SOLUTION = 1;
3636

37-
public final static int STRICTLY_SIMPLE = 2;
37+
int STRICTLY_SIMPLE = 2;
3838

39-
public final static int PRESERVE_COLINEAR = 4;
39+
int PRESERVE_COLINEAR = 4;
4040

41-
boolean addPath( Path pg, PolyType polyType, boolean Closed );
41+
boolean addPath(Path pg, PolyType polyType, boolean Closed);
4242

43-
boolean addPaths( Paths ppg, PolyType polyType, boolean closed );
43+
boolean addPaths(Paths ppg, PolyType polyType, boolean closed);
4444

4545
void clear();
4646

47-
boolean execute( ClipType clipType, Paths solution );
47+
boolean execute(ClipType clipType, Paths solution);
4848

49-
boolean execute( ClipType clipType, Paths solution, PolyFillType subjFillType, PolyFillType clipFillType );
49+
boolean execute(ClipType clipType, Paths solution, PolyFillType subjFillType, PolyFillType clipFillType);
5050

51-
boolean execute( ClipType clipType, PolyTree polytree );
51+
boolean execute(ClipType clipType, PolyTree polytree);
5252

53-
public boolean execute( ClipType clipType, PolyTree polytree, PolyFillType subjFillType, PolyFillType clipFillType );
53+
boolean execute(ClipType clipType, PolyTree polytree, PolyFillType subjFillType, PolyFillType clipFillType);
5454
}

Clipper/src/de/lighti/clipper/ClipperBase.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package de.lighti.clipper;
22

3+
import de.lighti.clipper.Path.OutRec;
4+
import de.lighti.clipper.Point.LongPoint;
5+
36
import java.util.ArrayList;
47
import java.util.List;
58
import java.util.logging.Logger;
69

7-
import de.lighti.clipper.Path.OutRec;
8-
import de.lighti.clipper.Point.LongPoint;
9-
1010
public abstract class ClipperBase implements Clipper {
1111
protected class LocalMinima {
1212
long y;
@@ -26,14 +26,14 @@ protected class Maxima {
2626
Maxima prev;
2727
}
2828

29-
private static void initEdge( Edge e, Edge eNext, Edge ePrev, LongPoint pt ) {
29+
private static void initEdge(Edge e, Edge eNext, Edge ePrev, LongPoint pt ) {
3030
e.next = eNext;
3131
e.prev = ePrev;
3232
e.setCurrent( new LongPoint( pt ) );
3333
e.outIdx = Edge.UNASSIGNED;
3434
}
3535

36-
private static void initEdge2( Edge e, PolyType polyType ) {
36+
private static void initEdge2(Edge e, PolyType polyType ) {
3737
if (e.getCurrent().getY() >= e.next.getCurrent().getY()) {
3838
e.setBot( new LongPoint( e.getCurrent() ) );
3939
e.setTop( new LongPoint( e.next.getCurrent() ) );
@@ -55,7 +55,7 @@ private static void rangeTest( LongPoint Pt ) {
5555
}
5656
}
5757

58-
private static Edge removeEdge( Edge e ) {
58+
private static Edge removeEdge(Edge e ) {
5959
//removes e from double_linked_list (but without removing from memory)
6060
e.prev.next = e.next;
6161
e.next.prev = e.prev;
@@ -72,11 +72,9 @@ private static Edge removeEdge( Edge e ) {
7272

7373
protected LocalMinima currentLM;
7474

75-
private final List<List<Edge>> edges = new ArrayList<List<Edge>>();
76-
7775
protected Scanbeam scanbeam;
7876

79-
protected final List<OutRec> polyOuts = new ArrayList<OutRec>();
77+
protected final List<OutRec> polyOuts = new ArrayList<>();
8078

8179
protected Edge activeEdges;
8280

@@ -95,7 +93,7 @@ protected ClipperBase( boolean preserveCollinear ) //constructor (nb: no externa
9593
}
9694

9795
@Override
98-
public boolean addPath( Path pg, PolyType polyType, boolean Closed ) {
96+
public boolean addPath(Path pg, PolyType polyType, boolean Closed ) {
9997

10098
if (!Closed && polyType == PolyType.CLIP) {
10199
throw new IllegalStateException( "AddPath: Open paths must be subject." );
@@ -115,7 +113,7 @@ public boolean addPath( Path pg, PolyType polyType, boolean Closed ) {
115113
}
116114

117115
//create a new edge array ...
118-
final List<Edge> edges = new ArrayList<Edge>( highI + 1 );
116+
final List<Edge> edges = new ArrayList<>( highI + 1 );
119117
for (int i = 0; i <= highI; i++) {
120118
edges.add( new Edge() );
121119
}
@@ -217,11 +215,9 @@ else if (Closed && Point.slopesEqual( e.prev.getCurrent(), e.getCurrent(), e.nex
217215
e = e.next;
218216
}
219217
insertLocalMinima( locMin );
220-
this.edges.add( edges );
221218
return true;
222219
}
223220

224-
this.edges.add( edges );
225221
boolean leftBoundIsForward;
226222
Edge EMin = null;
227223

@@ -295,10 +291,10 @@ else if (locMin.rightBound.outIdx == Edge.SKIP) {
295291
}
296292

297293
@Override
298-
public boolean addPaths( Paths ppg, PolyType polyType, boolean closed ) {
294+
public boolean addPaths(Paths paths, PolyType polyType, boolean closed ) {
299295
boolean result = false;
300-
for (int i = 0; i < ppg.size(); ++i) {
301-
if (addPath( ppg.get( i ), polyType, closed )) {
296+
for (Path path : paths) {
297+
if (addPath(path, polyType, closed)) {
302298
result = true;
303299
}
304300
}
@@ -308,7 +304,6 @@ public boolean addPaths( Paths ppg, PolyType polyType, boolean closed ) {
308304
@Override
309305
public void clear() {
310306
disposeLocalMinimaList();
311-
edges.clear();
312307
hasOpenPaths = false;
313308
}
314309

@@ -338,8 +333,7 @@ else if (newLm.y >= minimaList.y) {
338333
tmpLm.next = newLm;
339334
}
340335
}
341-
342-
public boolean isPreserveCollinear() {
336+
private boolean isPreserveCollinear() {
343337
return preserveCollinear;
344338
}
345339

@@ -353,7 +347,7 @@ protected boolean popLocalMinima( long y, LocalMinima[] current ) {
353347
return false;
354348
}
355349

356-
private Edge processBound( Edge e, boolean LeftBoundIsForward ) {
350+
private Edge processBound(Edge e, boolean LeftBoundIsForward ) {
357351
Edge EStart, result = e;
358352
Edge Horz;
359353

@@ -605,7 +599,7 @@ protected void updateEdgeIntoAEL( Edge e ) {
605599
}
606600
}
607601

608-
protected void swapPositionsInAEL( Edge edge1, Edge edge2 ) {
602+
protected void swapPositionsInAEL(Edge edge1, Edge edge2 ) {
609603
LOGGER.entering( ClipperBase.class.getName(), "swapPositionsInAEL" );
610604

611605
//check that one or other edge hasn't already been removed from AEL ...

Clipper/src/de/lighti/clipper/ClipperOffset.java

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package de.lighti.clipper;
22

3+
import de.lighti.clipper.Clipper.*;
4+
import de.lighti.clipper.Point.DoublePoint;
5+
import de.lighti.clipper.Point.LongPoint;
6+
37
import java.util.ArrayList;
48
import java.util.Collections;
59
import java.util.List;
610

7-
import de.lighti.clipper.Clipper.ClipType;
8-
import de.lighti.clipper.Clipper.EndType;
9-
import de.lighti.clipper.Clipper.JoinType;
10-
import de.lighti.clipper.Clipper.PolyFillType;
11-
import de.lighti.clipper.Clipper.PolyType;
12-
import de.lighti.clipper.Point.DoublePoint;
13-
import de.lighti.clipper.Point.LongPoint;
14-
1511
public class ClipperOffset {
1612
private static boolean nearZero( double val ) {
1713
return val > -TOLERANCE && val < TOLERANCE;
@@ -45,12 +41,12 @@ public ClipperOffset( double miterLimit, double arcTolerance ) {
4541
this.miterLimit = miterLimit;
4642
this.arcTolerance = arcTolerance;
4743
lowest = new LongPoint();
48-
lowest.setX( -1l );
44+
lowest.setX( -1L );
4945
polyNodes = new PolyNode();
50-
normals = new ArrayList<DoublePoint>();
46+
normals = new ArrayList<>();
5147
}
5248

53-
public void addPath( Path path, JoinType joinType, EndType endType ) {
49+
public void addPath(Path path, JoinType joinType, EndType endType ) {
5450
int highI = path.size() - 1;
5551
if (highI < 0) {
5652
return;
@@ -100,20 +96,20 @@ public void addPath( Path path, JoinType joinType, EndType endType ) {
10096
}
10197
}
10298

103-
public void addPaths( Paths paths, JoinType joinType, EndType endType ) {
99+
public void addPaths(Paths paths, JoinType joinType, EndType endType ) {
104100
for (final Path p : paths) {
105101
addPath( p, joinType, endType );
106102
}
107103
}
108104

109105
public void clear() {
110106
polyNodes.getChilds().clear();
111-
lowest.setX( -1l );
107+
lowest.setX( -1L );
112108
}
113109

114110
private void doMiter( int j, int k, double r ) {
115111
final double q = delta / r;
116-
destPoly.add( new LongPoint( (int) Math.round( srcPoly.get( j ).getX() + (normals.get( k ).getX() + normals.get( j ).getX()) * q ), (int) Math
112+
destPoly.add( new LongPoint( Math.round( srcPoly.get( j ).getX() + (normals.get( k ).getX() + normals.get( j ).getX()) * q ), Math
117113
.round( srcPoly.get( j ).getY() + (normals.get( k ).getY() + normals.get( j ).getY()) * q ) ) );
118114
}
119115

@@ -175,7 +171,7 @@ else if (arcTolerance > Math.abs( delta ) * DEFAULT_ARC_TOLERANCE) {
175171
if (node.getJoinType() == JoinType.ROUND) {
176172
double X = 1.0, Y = 0.0;
177173
for (int j = 1; j <= steps; j++) {
178-
destPoly.add( new LongPoint( (int) Math.round( srcPoly.get( 0 ).getX() + X * delta ), (int) Math.round( srcPoly.get( 0 ).getY() + Y
174+
destPoly.add( new LongPoint( Math.round( srcPoly.get( 0 ).getX() + X * delta ), Math.round( srcPoly.get( 0 ).getY() + Y
179175
* delta ) ) );
180176
final double X2 = X;
181177
X = X * cos - sin * Y;
@@ -185,7 +181,7 @@ else if (arcTolerance > Math.abs( delta ) * DEFAULT_ARC_TOLERANCE) {
185181
else {
186182
double X = -1.0, Y = -1.0;
187183
for (int j = 0; j < 4; ++j) {
188-
destPoly.add( new LongPoint( (int) Math.round( srcPoly.get( 0 ).getX() + X * delta ), (int) Math.round( srcPoly.get( 0 ).getY() + Y
184+
destPoly.add( new LongPoint( Math.round( srcPoly.get( 0 ).getX() + X * delta ), Math.round( srcPoly.get( 0 ).getY() + Y
189185
* delta ) ) );
190186
if (X < 0) {
191187
X = 1;
@@ -249,10 +245,10 @@ else if (node.getEndType() == EndType.CLOSED_LINE) {
249245
LongPoint pt1;
250246
if (node.getEndType() == EndType.OPEN_BUTT) {
251247
final int j = len - 1;
252-
pt1 = new LongPoint( (int) Math.round( srcPoly.get( j ).getX() + normals.get( j ).getX() * delta ), (int) Math.round( srcPoly.get( j )
248+
pt1 = new LongPoint( Math.round( srcPoly.get( j ).getX() + normals.get( j ).getX() * delta ), Math.round( srcPoly.get( j )
253249
.getY() + normals.get( j ).getY() * delta ), 0 );
254250
destPoly.add( pt1 );
255-
pt1 = new LongPoint( (int) Math.round( srcPoly.get( j ).getX() - normals.get( j ).getX() * delta ), (int) Math.round( srcPoly.get( j )
251+
pt1 = new LongPoint( Math.round( srcPoly.get( j ).getX() - normals.get( j ).getX() * delta ), Math.round( srcPoly.get( j )
256252
.getY() - normals.get( j ).getY() * delta ), 0 );
257253
destPoly.add( pt1 );
258254
}
@@ -282,10 +278,10 @@ else if (node.getEndType() == EndType.CLOSED_LINE) {
282278
}
283279

284280
if (node.getEndType() == EndType.OPEN_BUTT) {
285-
pt1 = new LongPoint( (int) Math.round( srcPoly.get( 0 ).getX() - normals.get( 0 ).getX() * delta ), (int) Math.round( srcPoly.get( 0 )
281+
pt1 = new LongPoint( Math.round( srcPoly.get( 0 ).getX() - normals.get( 0 ).getX() * delta ), Math.round( srcPoly.get( 0 )
286282
.getY() - normals.get( 0 ).getY() * delta ) );
287283
destPoly.add( pt1 );
288-
pt1 = new LongPoint( (int) Math.round( srcPoly.get( 0 ).getX() + normals.get( 0 ).getX() * delta ), (int) Math.round( srcPoly.get( 0 )
284+
pt1 = new LongPoint( Math.round( srcPoly.get( 0 ).getX() + normals.get( 0 ).getX() * delta ), Math.round( srcPoly.get( 0 )
289285
.getY() + normals.get( 0 ).getY() * delta ) );
290286
destPoly.add( pt1 );
291287
}
@@ -310,12 +306,12 @@ private void doRound( int j, int k ) {
310306

311307
double X = normals.get( k ).getX(), Y = normals.get( k ).getY(), X2;
312308
for (int i = 0; i < steps; ++i) {
313-
destPoly.add( new LongPoint( (int) Math.round( srcPoly.get( j ).getX() + X * delta ), (int) Math.round( srcPoly.get( j ).getY() + Y * delta ) ) );
309+
destPoly.add( new LongPoint( Math.round( srcPoly.get( j ).getX() + X * delta ), Math.round( srcPoly.get( j ).getY() + Y * delta ) ) );
314310
X2 = X;
315311
X = X * cos - sin * Y;
316312
Y = X2 * sin + Y * cos;
317313
}
318-
destPoly.add( new LongPoint( (int) Math.round( srcPoly.get( j ).getX() + normals.get( j ).getX() * delta ), (int) Math.round( srcPoly.get( j ).getY()
314+
destPoly.add( new LongPoint( Math.round( srcPoly.get( j ).getX() + normals.get( j ).getX() * delta ), Math.round( srcPoly.get( j ).getY()
319315
+ normals.get( j ).getY() * delta ) ) );
320316
}
321317

@@ -327,13 +323,13 @@ private void doSquare( int j, int k ) {
327323
final double sjx = srcPoly.get( j ).getX();
328324
final double sjy = srcPoly.get( j ).getY();
329325
final double dx = Math.tan( Math.atan2( inA, nkx * njx + nky * njy ) / 4 );
330-
destPoly.add( new LongPoint( (int) Math.round( sjx + delta * (nkx - nky * dx) ), (int) Math.round( sjy + delta * (nky + nkx * dx) ), 0 ) );
331-
destPoly.add( new LongPoint( (int) Math.round( sjx + delta * (njx + njy * dx) ), (int) Math.round( sjy + delta * (njy - njx * dx) ), 0 ) );
326+
destPoly.add( new LongPoint( Math.round( sjx + delta * (nkx - nky * dx) ), Math.round( sjy + delta * (nky + nkx * dx) ), 0 ) );
327+
destPoly.add( new LongPoint( Math.round( sjx + delta * (njx + njy * dx) ), Math.round( sjy + delta * (njy - njx * dx) ), 0 ) );
332328
}
333329

334330
//------------------------------------------------------------------------------
335331

336-
public void execute( Paths solution, double delta ) {
332+
public void execute(Paths solution, double delta ) {
337333
solution.clear();
338334
fixOrientations();
339335
doOffset( delta );
@@ -363,7 +359,7 @@ public void execute( Paths solution, double delta ) {
363359

364360
//------------------------------------------------------------------------------
365361

366-
public void execute( PolyTree solution, double delta ) {
362+
public void execute(PolyTree solution, double delta ) {
367363
solution.Clear();
368364
fixOrientations();
369365
doOffset( delta );
@@ -442,7 +438,7 @@ private void offsetPoint( int j, int[] kV, JoinType jointype ) {
442438
final double cosA = nkx * njx + njy * nky;
443439
if (cosA > 0) // angle ==> 0 degrees
444440
{
445-
destPoly.add( new LongPoint( (int) Math.round( sjx + nkx * delta ), (int) Math.round( sjy + nky * delta ), 0 ) );
441+
destPoly.add( new LongPoint( Math.round( sjx + nkx * delta ), Math.round( sjy + nky * delta ), 0 ) );
446442
return;
447443
}
448444
//else angle ==> 180 degrees
@@ -455,9 +451,9 @@ else if (inA < -1.0) {
455451
}
456452

457453
if (inA * delta < 0) {
458-
destPoly.add( new LongPoint( (int) Math.round( sjx + nkx * delta ), (int) Math.round( sjy + nky * delta ) ) );
454+
destPoly.add( new LongPoint( Math.round( sjx + nkx * delta ), Math.round( sjy + nky * delta ) ) );
459455
destPoly.add( srcPoly.get( j ) );
460-
destPoly.add( new LongPoint( (int) Math.round( sjx + njx * delta ), (int) Math.round( sjy + njy * delta ) ) );
456+
destPoly.add( new LongPoint( Math.round( sjx + njx * delta ), Math.round( sjy + njy * delta ) ) );
461457
}
462458
else {
463459
switch (jointype) {

0 commit comments

Comments
 (0)