11package 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+
37import java .util .ArrayList ;
48import java .util .Collections ;
59import 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-
1511public 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