diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9295a4a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+/bin/
+*.iml
+.idea/
+.DS_Store
+*/target/
+.*
+/.settings/
\ No newline at end of file
diff --git a/Clipper Console/.classpath b/Clipper Console/.classpath
deleted file mode 100644
index 6302551..0000000
--- a/Clipper Console/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/Clipper Console/.gitignore b/Clipper Console/.gitignore
deleted file mode 100644
index ae3c172..0000000
--- a/Clipper Console/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/bin/
diff --git a/Clipper Console/.project b/Clipper Console/.project
deleted file mode 100644
index 2b8b478..0000000
--- a/Clipper Console/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- Clipper Console
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
diff --git a/Clipper Console/.settings/org.eclipse.jdt.core.prefs b/Clipper Console/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 3a21537..0000000
--- a/Clipper Console/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,11 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.8
diff --git a/Clipper Console/pom.xml b/Clipper Console/pom.xml
new file mode 100644
index 0000000..343ddd9
--- /dev/null
+++ b/Clipper Console/pom.xml
@@ -0,0 +1,32 @@
+
+
+
+ 4.0.0
+
+
+ de.lighti.clipper
+ clipper-java-double
+
+ 6.4.2.1-SNAPSHOT
+
+
+ clipper-double-console
+
+
+ true
+
+
+
+ src
+
+
+
+
+ de.lighti.clipper
+ clipper
+ 6.4.2.1-SNAPSHOT
+
+
+
+
\ No newline at end of file
diff --git a/Clipper Console/src/de/lighti/clipper/console/Program.java b/Clipper Console/src/de/lighti/clipper/console/Program.java
index a13708e..61b0ba5 100644
--- a/Clipper Console/src/de/lighti/clipper/console/Program.java
+++ b/Clipper Console/src/de/lighti/clipper/console/Program.java
@@ -18,7 +18,7 @@
import de.lighti.clipper.DefaultClipper;
import de.lighti.clipper.Path;
import de.lighti.clipper.Paths;
-import de.lighti.clipper.Point.LongPoint;
+import de.lighti.clipper.Point;
public class Program {
@@ -26,7 +26,7 @@ static Path IntsToPolygon( int[] ints ) {
final int len1 = ints.length / 2;
final Path result = new Path( len1 );
for (int i = 0; i < len1; i++) {
- result.add( new LongPoint( ints[i * 2], ints[i * 2 + 1] ) );
+ result.add( new Point( ints[i * 2], ints[i * 2 + 1] ) );
}
return result;
}
@@ -81,7 +81,7 @@ static boolean LoadFromFile( String filename, Paths ppg, int dec_places, int xOf
x = x + xOffset;
y = y + yOffset;
- pg.add( new LongPoint( x, y ) );
+ pg.add( new Point( x, y ) );
}
}
else {
@@ -100,7 +100,7 @@ static boolean LoadFromFile( String filename, Paths ppg, int dec_places, int xOf
x = x * scaling + xOffset;
y = y * scaling + yOffset;
- pg.add( new LongPoint( (int) Math.round( x ), (int) Math.round( y ) ) );
+ pg.add( new Point( (int) Math.round( x ), (int) Math.round( y ) ) );
}
}
}
@@ -271,7 +271,7 @@ static Path MakeRandomPolygon( Random r, int maxWidth, int maxHeight, int edgeCo
static Path MakeRandomPolygon( Random r, int maxWidth, int maxHeight, int edgeCount, int scale ) {
final Path result = new Path( edgeCount );
for (int i = 0; i < edgeCount; i++) {
- result.add( new LongPoint( r.nextInt( maxWidth ) * scale, r.nextInt( maxHeight ) * scale ) );
+ result.add( new Point( r.nextInt( maxWidth ) * scale, r.nextInt( maxHeight ) * scale ) );
}
return result;
}
@@ -296,7 +296,7 @@ static void saveToFile( String filename, Paths ppg, int dec_places ) throws IOEx
writer.write( String.format( "%d%n", ppg.size() ) );
for (final Path pg : ppg) {
writer.write( String.format( "%d%n", pg.size() ) );
- for (final LongPoint ip : pg) {
+ for (final Point ip : pg) {
writer.write( String.format( "%.2f, %.2f%n", ip.getX() / scaling, ip.getY() / scaling ) );
}
}
diff --git a/Clipper Console/src/de/lighti/clipper/console/SVGBuilder.java b/Clipper Console/src/de/lighti/clipper/console/SVGBuilder.java
index 9587cf8..a61e03a 100644
--- a/Clipper Console/src/de/lighti/clipper/console/SVGBuilder.java
+++ b/Clipper Console/src/de/lighti/clipper/console/SVGBuilder.java
@@ -11,7 +11,7 @@
import de.lighti.clipper.LongRect;
import de.lighti.clipper.Path;
import de.lighti.clipper.Paths;
-import de.lighti.clipper.Point.LongPoint;
+import de.lighti.clipper.Point;
//a very simple class that builds an SVG file with any number of
//polygons of the specified formats ...
@@ -125,7 +125,7 @@ public boolean SaveToFile( String filename, double scale, int margin ) throws IO
for (; i < PolyInfoList.size(); i++) {
for (final Path pg : PolyInfoList.get( i ).polygons) {
- for (final LongPoint pt : pg) {
+ for (final Point pt : pg) {
if (pt.getX() < rec.left) {
rec.left = pt.getX();
}
@@ -146,8 +146,8 @@ else if (pt.getY() > rec.bottom) {
rec.top = (int) (rec.top * scale);
rec.right = (int) (rec.right * scale);
rec.bottom = (int) (rec.bottom * scale);
- final long offsetX = -rec.left + margin;
- final long offsetY = -rec.top + margin;
+ final long offsetX = (long) -rec.left + margin;
+ final long offsetY = (long) -rec.top + margin;
final BufferedWriter writer = new BufferedWriter( new FileWriter( filename ) );
try {
@@ -174,9 +174,9 @@ else if (pt.getY() > rec.bottom) {
if (pi.si.showCoords) {
writer.write( String.format( "%n%n" ) );
for (final Path p : pi.polygons) {
- for (final LongPoint pt : p) {
- final long x = pt.getX();
- final long y = pt.getY();
+ for (final Point pt : p) {
+ final long x = (long) pt.getX();
+ final long y = (long) pt.getY();
writer.write( String.format( "%d,%d\n", (int) (x * scale + offsetX), (int) (y * scale + offsetY), x,
y ) );
diff --git a/Clipper GUI/.classpath b/Clipper GUI/.classpath
deleted file mode 100644
index 6302551..0000000
--- a/Clipper GUI/.classpath
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
-
diff --git a/Clipper GUI/.gitignore b/Clipper GUI/.gitignore
deleted file mode 100644
index ae3c172..0000000
--- a/Clipper GUI/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/bin/
diff --git a/Clipper GUI/.project b/Clipper GUI/.project
deleted file mode 100644
index aaf9eeb..0000000
--- a/Clipper GUI/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- Clipper GUI
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
diff --git a/Clipper GUI/.settings/org.eclipse.jdt.core.prefs b/Clipper GUI/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 3a21537..0000000
--- a/Clipper GUI/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,11 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.8
diff --git a/Clipper GUI/pom.xml b/Clipper GUI/pom.xml
new file mode 100644
index 0000000..c25e339
--- /dev/null
+++ b/Clipper GUI/pom.xml
@@ -0,0 +1,32 @@
+
+
+
+ 4.0.0
+
+
+ de.lighti.clipper
+ clipper-java-double
+
+ 6.4.2.1-SNAPSHOT
+
+
+ clipper-double-gui
+
+
+ true
+
+
+
+ src
+
+
+
+
+ de.lighti.clipper
+ clipper
+ 6.4.2.1-SNAPSHOT
+
+
+
+
\ No newline at end of file
diff --git a/Clipper GUI/src/de/lighti/clipper/gui/ClipperDialog.java b/Clipper GUI/src/de/lighti/clipper/gui/ClipperDialog.java
index 071c7c3..ebbf16d 100644
--- a/Clipper GUI/src/de/lighti/clipper/gui/ClipperDialog.java
+++ b/Clipper GUI/src/de/lighti/clipper/gui/ClipperDialog.java
@@ -38,7 +38,7 @@
import de.lighti.clipper.Clipper.PolyType;
import de.lighti.clipper.Path;
import de.lighti.clipper.Paths;
-import de.lighti.clipper.Point.LongPoint;
+import de.lighti.clipper.Point;
public class ClipperDialog extends JFrame {
static boolean loadFromFile( String filename, Paths ppg, int dec_places ) throws IOException {
@@ -92,7 +92,7 @@ static boolean loadFromFile( String filename, Paths ppg, int dec_places, long xO
x = x + xOffset;
y = y + yOffset;
- pg.add( new LongPoint( x, y ) );
+ pg.add( new Point( x, y ) );
}
}
else {
@@ -111,7 +111,7 @@ static boolean loadFromFile( String filename, Paths ppg, int dec_places, long xO
x = x * scaling + xOffset;
y = y * scaling + yOffset;
- pg.add( new LongPoint( (int) Math.round( x ), (int) Math.round( y ) ) );
+ pg.add( new Point( (int) Math.round( x ), (int) Math.round( y ) ) );
}
}
}
diff --git a/Clipper GUI/src/de/lighti/clipper/gui/PolygonCanvas.java b/Clipper GUI/src/de/lighti/clipper/gui/PolygonCanvas.java
index 899e0c8..474adde 100644
--- a/Clipper GUI/src/de/lighti/clipper/gui/PolygonCanvas.java
+++ b/Clipper GUI/src/de/lighti/clipper/gui/PolygonCanvas.java
@@ -25,7 +25,6 @@
import de.lighti.clipper.DefaultClipper;
import de.lighti.clipper.Path;
import de.lighti.clipper.Paths;
-import de.lighti.clipper.Point.LongPoint;
public class PolygonCanvas extends JPanel {
@@ -95,7 +94,7 @@ private Polygon createPolygonFromPath( Path p ) {
final int[] y = new int[p.size()];
for (int i = p.size() - 1; i >= 0; i--) {
- final LongPoint ip = p.get( i );
+ final de.lighti.clipper.Point ip = p.get( i );
x[i] = (int) (ip.getX() * zoom) + cur.x - origin.x;
y[i] = (int) (ip.getY() * zoom) + cur.y - origin.y;
}
@@ -119,7 +118,7 @@ public void generateAustPlusRandomEllipses() {
for (int j = 0; j < vertCnt; ++j) {
final float x = polyStream.readFloat() * scale;
final float y = polyStream.readFloat() * scale;
- pg.add( new LongPoint( (int) x, (int) y ) );
+ pg.add( new de.lighti.clipper.Point( (int) x, (int) y ) );
}
subjects.add( pg );
}
@@ -157,7 +156,7 @@ public void generateAustPlusRandomEllipses() {
final int type = pit.currentSegment( coords );
switch (type) {
case PathIterator.SEG_LINETO:
- clip.add( new LongPoint( (int) (coords[0] * scale), (int) (coords[1] * scale) ) );
+ clip.add( new de.lighti.clipper.Point( (int) (coords[0] * scale), (int) (coords[1] * scale) ) );
break;
default:
break;
@@ -172,8 +171,8 @@ public void generateAustPlusRandomEllipses() {
}
- private LongPoint GenerateRandomPoint( int l, int t, int r, int b, Random rand ) {
- return new LongPoint( rand.nextInt( r ) + l, rand.nextInt( b ) + t );
+ private de.lighti.clipper.Point GenerateRandomPoint(int l, int t, int r, int b, Random rand ) {
+ return new de.lighti.clipper.Point( rand.nextInt( r ) + l, rand.nextInt( b ) + t );
}
public void generateRandomPolygon() {
diff --git a/Clipper GUI/src/de/lighti/clipper/gui/SVGBuilder.java b/Clipper GUI/src/de/lighti/clipper/gui/SVGBuilder.java
index 3395959..e6aa390 100644
--- a/Clipper GUI/src/de/lighti/clipper/gui/SVGBuilder.java
+++ b/Clipper GUI/src/de/lighti/clipper/gui/SVGBuilder.java
@@ -12,7 +12,7 @@
import de.lighti.clipper.LongRect;
import de.lighti.clipper.Path;
import de.lighti.clipper.Paths;
-import de.lighti.clipper.Point.LongPoint;
+import de.lighti.clipper.Point;
//a very simple class that builds an SVG file with any number of
//polygons of the specified formats ...
@@ -134,7 +134,7 @@ public boolean SaveToFile( String filename, double scale, int margin ) throws IO
for (; i < PolyInfoList.size(); i++) {
- for (final LongPoint pt : PolyInfoList.get( i ).polygons) {
+ for (final Point pt : PolyInfoList.get( i ).polygons) {
if (pt.getX() < rec.left) {
rec.left = pt.getX();
}
@@ -155,8 +155,8 @@ else if (pt.getY() > rec.bottom) {
rec.top = (int) (rec.top * scale);
rec.right = (int) (rec.right * scale);
rec.bottom = (int) (rec.bottom * scale);
- final long offsetX = -rec.left + margin;
- final long offsetY = -rec.top + margin;
+ final long offsetX = (long) -rec.left + margin;
+ final long offsetY = (long) -rec.top + margin;
final BufferedWriter writer = new BufferedWriter( new FileWriter( filename ) );
try {
@@ -182,9 +182,9 @@ else if (pt.getY() > rec.bottom) {
if (pi.si.showCoords) {
writer.write( String.format( "%n%n" ) );
- for (final LongPoint pt : p) {
- final long x = pt.getX();
- final long y = pt.getY();
+ for (final Point pt : p) {
+ final long x = (long) pt.getX();
+ final long y = (long) pt.getY();
writer.write( String.format( "%d,%d\n", (int) (x * scale + offsetX), (int) (y * scale + offsetY), x, y ) );
}
diff --git a/Clipper/.classpath b/Clipper/.classpath
deleted file mode 100644
index f9ea041..0000000
--- a/Clipper/.classpath
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/Clipper/.gitignore b/Clipper/.gitignore
deleted file mode 100644
index ae3c172..0000000
--- a/Clipper/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/bin/
diff --git a/Clipper/.project b/Clipper/.project
deleted file mode 100644
index 1659c61..0000000
--- a/Clipper/.project
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
- Clipper
-
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
-
- org.eclipse.jdt.core.javanature
-
-
diff --git a/Clipper/.settings/org.eclipse.jdt.core.prefs b/Clipper/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 3a21537..0000000
--- a/Clipper/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,11 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.8
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.8
diff --git a/Clipper/pom.xml b/Clipper/pom.xml
new file mode 100644
index 0000000..5dbe7e1
--- /dev/null
+++ b/Clipper/pom.xml
@@ -0,0 +1,20 @@
+
+
+
+ 4.0.0
+
+
+ de.lighti.clipper
+ clipper-java-double
+
+ 6.4.2.1-SNAPSHOT
+
+
+ clipper-double
+
+
+ src
+
+
+
\ No newline at end of file
diff --git a/Clipper/src/de/lighti/clipper/Clipper.java b/Clipper/src/de/lighti/clipper/Clipper.java
index 5acb698..d290b6e 100644
--- a/Clipper/src/de/lighti/clipper/Clipper.java
+++ b/Clipper/src/de/lighti/clipper/Clipper.java
@@ -1,7 +1,5 @@
package de.lighti.clipper;
-import de.lighti.clipper.Point.LongPoint;
-
public interface Clipper {
public enum ClipType {
INTERSECTION, UNION, DIFFERENCE, XOR
@@ -28,7 +26,7 @@ public enum PolyType {
};
public interface ZFillCallback {
- void zFill( LongPoint bot1, LongPoint top1, LongPoint bot2, LongPoint top2, LongPoint pt );
+ void zFill(Point bot1, Point top1, Point bot2, Point top2, Point pt);
};
//InitOptions that can be passed to the constructor ...
diff --git a/Clipper/src/de/lighti/clipper/ClipperBase.java b/Clipper/src/de/lighti/clipper/ClipperBase.java
index c78674f..60544bd 100644
--- a/Clipper/src/de/lighti/clipper/ClipperBase.java
+++ b/Clipper/src/de/lighti/clipper/ClipperBase.java
@@ -5,48 +5,47 @@
import java.util.logging.Logger;
import de.lighti.clipper.Path.OutRec;
-import de.lighti.clipper.Point.LongPoint;
public abstract class ClipperBase implements Clipper {
protected class LocalMinima {
- long y;
+ double y;
Edge leftBound;
Edge rightBound;
LocalMinima next;
}
protected class Scanbeam {
- long y;
+ double y;
Scanbeam next;
}
protected class Maxima {
- long x;
+ double x;
Maxima next;
Maxima prev;
}
- private static void initEdge( Edge e, Edge eNext, Edge ePrev, LongPoint pt ) {
+ private static void initEdge(Edge e, Edge eNext, Edge ePrev, Point pt ) {
e.next = eNext;
e.prev = ePrev;
- e.setCurrent( new LongPoint( pt ) );
+ e.setCurrent( new Point( pt ) );
e.outIdx = Edge.UNASSIGNED;
}
- private static void initEdge2( Edge e, PolyType polyType ) {
+ private static void initEdge2(Edge e, PolyType polyType ) {
if (e.getCurrent().getY() >= e.next.getCurrent().getY()) {
- e.setBot( new LongPoint( e.getCurrent() ) );
- e.setTop( new LongPoint( e.next.getCurrent() ) );
+ e.setBot( new Point( e.getCurrent() ) );
+ e.setTop( new Point( e.next.getCurrent() ) );
}
else {
- e.setTop( new LongPoint( e.getCurrent() ) );
- e.setBot( new LongPoint( e.next.getCurrent() ) );
+ e.setTop( new Point( e.getCurrent() ) );
+ e.setBot( new Point( e.next.getCurrent() ) );
}
e.updateDeltaX();
e.polyTyp = polyType;
}
- private static void rangeTest( LongPoint Pt ) {
+ private static void rangeTest( Point Pt ) {
if (Pt.getX() > LOW_RANGE || Pt.getY() > LOW_RANGE || -Pt.getX() > LOW_RANGE || -Pt.getY() > LOW_RANGE) {
if (Pt.getX() > HI_RANGE || Pt.getY() > HI_RANGE || -Pt.getX() > HI_RANGE || -Pt.getY() > HI_RANGE) {
@@ -123,7 +122,7 @@ public boolean addPath( Path pg, PolyType polyType, boolean Closed ) {
boolean IsFlat = true;
//1. Basic (first) edge initialization ...
- edges.get( 1 ).setCurrent( new LongPoint( pg.get( 1 ) ) );
+ edges.get( 1 ).setCurrent( new Point( pg.get( 1 ) ) );
rangeTest( pg.get( 0 ) );
rangeTest( pg.get( highI ) );
initEdge( edges.get( 0 ), edges.get( 1 ), edges.get( highI ), pg.get( 0 ) );
@@ -343,7 +342,7 @@ public boolean isPreserveCollinear() {
return preserveCollinear;
}
- protected boolean popLocalMinima( long y, LocalMinima[] current ) {
+ protected boolean popLocalMinima( double y, LocalMinima[] current ) {
LOGGER.entering( ClipperBase.class.getName(), "popLocalMinima" );
current[0] = currentLM;
if (currentLM != null && currentLM.y == y) {
@@ -353,7 +352,7 @@ protected boolean popLocalMinima( long y, LocalMinima[] current ) {
return false;
}
- private Edge processBound( Edge e, boolean LeftBoundIsForward ) {
+ private Edge processBound(Edge e, boolean LeftBoundIsForward ) {
Edge EStart, result = e;
Edge Horz;
@@ -498,12 +497,12 @@ protected void reset() {
insertScanbeam(lm.y);
Edge e = lm.leftBound;
if (e != null) {
- e.setCurrent( new LongPoint( e.getBot() ) );
+ e.setCurrent( new Point( e.getBot() ) );
e.outIdx = Edge.UNASSIGNED;
}
e = lm.rightBound;
if (e != null) {
- e.setCurrent( new LongPoint( e.getBot() ) );
+ e.setCurrent( new Point( e.getBot() ) );
e.outIdx = Edge.UNASSIGNED;
}
lm = lm.next;
@@ -511,7 +510,7 @@ protected void reset() {
activeEdges = null;
}
- protected void insertScanbeam( long y ) {
+ protected void insertScanbeam( double y ) {
LOGGER.entering( ClipperBase.class.getName(), "insertScanbeam" );
//single-linked list: sorted descending, ignoring dups.
@@ -541,7 +540,7 @@ else if (y > scanbeam.y) {
}
}
- protected boolean popScanbeam( long[] y ) {
+ protected boolean popScanbeam( double[] y ) {
if (scanbeam == null) {
y[0] = 0;
return false;
@@ -605,7 +604,7 @@ protected void updateEdgeIntoAEL( Edge e ) {
}
}
- protected void swapPositionsInAEL( Edge edge1, Edge edge2 ) {
+ protected void swapPositionsInAEL(Edge edge1, Edge edge2 ) {
LOGGER.entering( ClipperBase.class.getName(), "swapPositionsInAEL" );
//check that one or other edge hasn't already been removed from AEL ...
diff --git a/Clipper/src/de/lighti/clipper/ClipperOffset.java b/Clipper/src/de/lighti/clipper/ClipperOffset.java
index 4b333d4..053c07e 100644
--- a/Clipper/src/de/lighti/clipper/ClipperOffset.java
+++ b/Clipper/src/de/lighti/clipper/ClipperOffset.java
@@ -9,8 +9,6 @@
import de.lighti.clipper.Clipper.JoinType;
import de.lighti.clipper.Clipper.PolyFillType;
import de.lighti.clipper.Clipper.PolyType;
-import de.lighti.clipper.Point.DoublePoint;
-import de.lighti.clipper.Point.LongPoint;
public class ClipperOffset {
private static boolean nearZero( double val ) {
@@ -21,11 +19,12 @@ private static boolean nearZero( double val ) {
private Path srcPoly;
private Path destPoly;
- private final List normals;
+ private final List normals;
private double delta, inA, sin, cos;
private double miterLim, stepsPerRad;
- private LongPoint lowest;
+ private int lowestX;
+ private int lowestY;
private final PolyNode polyNodes;
private final double arcTolerance;
@@ -44,13 +43,13 @@ public ClipperOffset() {
public ClipperOffset( double miterLimit, double arcTolerance ) {
this.miterLimit = miterLimit;
this.arcTolerance = arcTolerance;
- lowest = new LongPoint();
- lowest.setX( -1l );
+ lowestX = -1;
+ lowestY = 0;
polyNodes = new PolyNode();
- normals = new ArrayList();
+ normals = new ArrayList();
}
- public void addPath( Path path, JoinType joinType, EndType endType ) {
+ public void addPath(Path path, JoinType joinType, EndType endType ) {
int highI = path.size() - 1;
if (highI < 0) {
return;
@@ -88,19 +87,21 @@ public void addPath( Path path, JoinType joinType, EndType endType ) {
if (endType != EndType.CLOSED_POLYGON) {
return;
}
- if (lowest.getX() < 0) {
- lowest = new LongPoint( polyNodes.getChildCount() - 1, k );
+ if (lowestX < 0) {
+ lowestX = polyNodes.getChildCount() - 1;
+ lowestY = k;
}
else {
- final LongPoint ip = polyNodes.getChilds().get( (int) lowest.getX() ).getPolygon().get( (int) lowest.getY() );
+ final Point ip = polyNodes.getChilds().get( lowestX ).getPolygon().get( lowestY );
if (newNode.getPolygon().get( k ).getY() > ip.getY() || newNode.getPolygon().get( k ).getY() == ip.getY()
&& newNode.getPolygon().get( k ).getX() < ip.getX()) {
- lowest = new LongPoint( polyNodes.getChildCount() - 1, k );
+ lowestX = polyNodes.getChildCount() - 1;
+ lowestY = k;
}
}
}
- public void addPaths( Paths paths, JoinType joinType, EndType endType ) {
+ public void addPaths(Paths paths, JoinType joinType, EndType endType ) {
for (final Path p : paths) {
addPath( p, joinType, endType );
}
@@ -108,13 +109,13 @@ public void addPaths( Paths paths, JoinType joinType, EndType endType ) {
public void clear() {
polyNodes.getChilds().clear();
- lowest.setX( -1l );
+ lowestX = -1;
}
private void doMiter( int j, int k, double r ) {
final double q = delta / r;
- destPoly.add( new LongPoint( (int) Math.round( srcPoly.get( j ).getX() + (normals.get( k ).getX() + normals.get( j ).getX()) * q ), (int) Math
- .round( srcPoly.get( j ).getY() + (normals.get( k ).getY() + normals.get( j ).getY()) * q ) ) );
+ destPoly.add( new Point( srcPoly.get( j ).getX() + (normals.get( k ).getX() + normals.get( j ).getX()) * q ,
+ srcPoly.get( j ).getY() + (normals.get( k ).getY() + normals.get( j ).getY()) * q ) );
}
private void doOffset( double delta ) {
@@ -175,8 +176,8 @@ else if (arcTolerance > Math.abs( delta ) * DEFAULT_ARC_TOLERANCE) {
if (node.getJoinType() == JoinType.ROUND) {
double X = 1.0, Y = 0.0;
for (int j = 1; j <= steps; j++) {
- destPoly.add( new LongPoint( (int) Math.round( srcPoly.get( 0 ).getX() + X * delta ), (int) Math.round( srcPoly.get( 0 ).getY() + Y
- * delta ) ) );
+ destPoly.add( new Point( srcPoly.get( 0 ).getX() + X * delta , srcPoly.get( 0 ).getY() + Y
+ * delta ) );
final double X2 = X;
X = X * cos - sin * Y;
Y = X2 * sin + Y * cos;
@@ -185,8 +186,8 @@ else if (arcTolerance > Math.abs( delta ) * DEFAULT_ARC_TOLERANCE) {
else {
double X = -1.0, Y = -1.0;
for (int j = 0; j < 4; ++j) {
- destPoly.add( new LongPoint( (int) Math.round( srcPoly.get( 0 ).getX() + X * delta ), (int) Math.round( srcPoly.get( 0 ).getY() + Y
- * delta ) ) );
+ destPoly.add( new Point( srcPoly.get( 0 ).getX() + X * delta , srcPoly.get( 0 ).getY() + Y
+ * delta ) );
if (X < 0) {
X = 1;
}
@@ -211,7 +212,7 @@ else if (Y < 0) {
normals.add( Point.getUnitNormal( srcPoly.get( len - 1 ), srcPoly.get( 0 ) ) );
}
else {
- normals.add( new DoublePoint( normals.get( len - 2 ) ) );
+ normals.add( new Point( normals.get( len - 2 ) ) );
}
if (node.getEndType() == EndType.CLOSED_POLYGON) {
@@ -229,11 +230,11 @@ else if (node.getEndType() == EndType.CLOSED_LINE) {
destPolys.add( destPoly );
destPoly = new Path();
//re-build m_normals ...
- final DoublePoint n = normals.get( len - 1 );
+ final Point n = normals.get( len - 1 );
for (int j = len - 1; j > 0; j--) {
- normals.set( j, new DoublePoint( -normals.get( j - 1 ).getX(), -normals.get( j - 1 ).getY() ) );
+ normals.set( j, new Point( -normals.get( j - 1 ).getX(), -normals.get( j - 1 ).getY() ) );
}
- normals.set( 0, new DoublePoint( -n.getX(), -n.getY(), 0 ) );
+ normals.set( 0, new Point( -n.getX(), -n.getY()) );
k[0] = 0;
for (int j = len - 1; j >= 0; j--) {
offsetPoint( j, k, node.getJoinType() );
@@ -246,21 +247,21 @@ else if (node.getEndType() == EndType.CLOSED_LINE) {
offsetPoint( j, k, node.getJoinType() );
}
- LongPoint pt1;
+ Point pt1;
if (node.getEndType() == EndType.OPEN_BUTT) {
final int j = len - 1;
- pt1 = new LongPoint( (int) Math.round( srcPoly.get( j ).getX() + normals.get( j ).getX() * delta ), (int) Math.round( srcPoly.get( j )
- .getY() + normals.get( j ).getY() * delta ), 0 );
+ pt1 = new Point( srcPoly.get( j ).getX() + normals.get( j ).getX() * delta , srcPoly.get( j )
+ .getY() + normals.get( j ).getY() * delta );
destPoly.add( pt1 );
- pt1 = new LongPoint( (int) Math.round( srcPoly.get( j ).getX() - normals.get( j ).getX() * delta ), (int) Math.round( srcPoly.get( j )
- .getY() - normals.get( j ).getY() * delta ), 0 );
+ pt1 = new Point( srcPoly.get( j ).getX() - normals.get( j ).getX() * delta , srcPoly.get( j )
+ .getY() - normals.get( j ).getY() * delta );
destPoly.add( pt1 );
}
else {
final int j = len - 1;
k[0] = len - 2;
inA = 0;
- normals.set( j, new DoublePoint( -normals.get( j ).getX(), -normals.get( j ).getY() ) );
+ normals.set( j, new Point( -normals.get( j ).getX(), -normals.get( j ).getY() ) );
if (node.getEndType() == EndType.OPEN_SQUARE) {
doSquare( j, k[0] );
}
@@ -271,10 +272,10 @@ else if (node.getEndType() == EndType.CLOSED_LINE) {
//re-build m_normals ...
for (int j = len - 1; j > 0; j--) {
- normals.set( j, new DoublePoint( -normals.get( j - 1 ).getX(), -normals.get( j - 1 ).getY() ) );
+ normals.set( j, new Point( -normals.get( j - 1 ).getX(), -normals.get( j - 1 ).getY() ) );
}
- normals.set( 0, new DoublePoint( -normals.get( 1 ).getX(), -normals.get( 1 ).getY() ) );
+ normals.set( 0, new Point( -normals.get( 1 ).getX(), -normals.get( 1 ).getY() ) );
k[0] = len - 1;
for (int j = k[0] - 1; j > 0; --j) {
@@ -282,11 +283,11 @@ else if (node.getEndType() == EndType.CLOSED_LINE) {
}
if (node.getEndType() == EndType.OPEN_BUTT) {
- pt1 = new LongPoint( (int) Math.round( srcPoly.get( 0 ).getX() - normals.get( 0 ).getX() * delta ), (int) Math.round( srcPoly.get( 0 )
- .getY() - normals.get( 0 ).getY() * delta ) );
+ pt1 = new Point( srcPoly.get( 0 ).getX() - normals.get( 0 ).getX() * delta , srcPoly.get( 0 )
+ .getY() - normals.get( 0 ).getY() * delta );
destPoly.add( pt1 );
- pt1 = new LongPoint( (int) Math.round( srcPoly.get( 0 ).getX() + normals.get( 0 ).getX() * delta ), (int) Math.round( srcPoly.get( 0 )
- .getY() + normals.get( 0 ).getY() * delta ) );
+ pt1 = new Point( srcPoly.get( 0 ).getX() + normals.get( 0 ).getX() * delta , srcPoly.get( 0 )
+ .getY() + normals.get( 0 ).getY() * delta );
destPoly.add( pt1 );
}
else {
@@ -310,13 +311,13 @@ private void doRound( int j, int k ) {
double X = normals.get( k ).getX(), Y = normals.get( k ).getY(), X2;
for (int i = 0; i < steps; ++i) {
- destPoly.add( new LongPoint( (int) Math.round( srcPoly.get( j ).getX() + X * delta ), (int) Math.round( srcPoly.get( j ).getY() + Y * delta ) ) );
+ destPoly.add( new Point( srcPoly.get( j ).getX() + X * delta , srcPoly.get( j ).getY() + Y * delta ) );
X2 = X;
X = X * cos - sin * Y;
Y = X2 * sin + Y * cos;
}
- destPoly.add( new LongPoint( (int) Math.round( srcPoly.get( j ).getX() + normals.get( j ).getX() * delta ), (int) Math.round( srcPoly.get( j ).getY()
- + normals.get( j ).getY() * delta ) ) );
+ destPoly.add( new Point( srcPoly.get( j ).getX() + normals.get( j ).getX() * delta , srcPoly.get( j ).getY()
+ + normals.get( j ).getY() * delta ) );
}
private void doSquare( int j, int k ) {
@@ -327,13 +328,13 @@ private void doSquare( int j, int k ) {
final double sjx = srcPoly.get( j ).getX();
final double sjy = srcPoly.get( j ).getY();
final double dx = Math.tan( Math.atan2( inA, nkx * njx + nky * njy ) / 4 );
- destPoly.add( new LongPoint( (int) Math.round( sjx + delta * (nkx - nky * dx) ), (int) Math.round( sjy + delta * (nky + nkx * dx) ), 0 ) );
- destPoly.add( new LongPoint( (int) Math.round( sjx + delta * (njx + njy * dx) ), (int) Math.round( sjy + delta * (njy - njx * dx) ), 0 ) );
+ destPoly.add( new Point( sjx + delta * (nkx - nky * dx) , sjy + delta * (nky + nkx * dx) ) );
+ destPoly.add( new Point( sjx + delta * (njx + njy * dx) , sjy + delta * (njy - njx * dx) ) );
}
//------------------------------------------------------------------------------
- public void execute( Paths solution, double delta ) {
+ public void execute(Paths solution, double delta ) {
solution.clear();
fixOrientations();
doOffset( delta );
@@ -347,10 +348,10 @@ public void execute( Paths solution, double delta ) {
final LongRect r = destPolys.getBounds();
final Path outer = new Path( 4 );
- outer.add( new LongPoint( r.left - 10, r.bottom + 10, 0 ) );
- outer.add( new LongPoint( r.right + 10, r.bottom + 10, 0 ) );
- outer.add( new LongPoint( r.right + 10, r.top - 10, 0 ) );
- outer.add( new LongPoint( r.left - 10, r.top - 10, 0 ) );
+ outer.add( new Point( r.left - 10, r.bottom + 10 ) );
+ outer.add( new Point( r.right + 10, r.bottom + 10 ) );
+ outer.add( new Point( r.right + 10, r.top - 10 ) );
+ outer.add( new Point( r.left - 10, r.top - 10 ) );
clpr.addPath( outer, PolyType.SUBJECT, true );
@@ -363,7 +364,7 @@ public void execute( Paths solution, double delta ) {
//------------------------------------------------------------------------------
- public void execute( PolyTree solution, double delta ) {
+ public void execute(PolyTree solution, double delta ) {
solution.Clear();
fixOrientations();
doOffset( delta );
@@ -378,10 +379,10 @@ public void execute( PolyTree solution, double delta ) {
final LongRect r = destPolys.getBounds();
final Path outer = new Path( 4 );
- outer.add( new LongPoint( r.left - 10, r.bottom + 10, 0 ) );
- outer.add( new LongPoint( r.right + 10, r.bottom + 10, 0 ) );
- outer.add( new LongPoint( r.right + 10, r.top - 10, 0 ) );
- outer.add( new LongPoint( r.left - 10, r.top - 10, 0 ) );
+ outer.add( new Point( r.left - 10, r.bottom + 10 ) );
+ outer.add( new Point( r.right + 10, r.bottom + 10 ) );
+ outer.add( new Point( r.right + 10, r.top - 10 ) );
+ outer.add( new Point( r.left - 10, r.top - 10 ) );
clpr.addPath( outer, PolyType.SUBJECT, true );
@@ -406,7 +407,7 @@ public void execute( PolyTree solution, double delta ) {
private void fixOrientations() {
//fixup orientations of all closed paths if the orientation of the
//closed path with the lowermost vertex is wrong ...
- if (lowest.getX() >= 0 && !polyNodes.childs.get( (int) lowest.getX() ).getPolygon().orientation()) {
+ if (lowestX >= 0 && !polyNodes.childs.get( lowestX ).getPolygon().orientation()) {
for (int i = 0; i < polyNodes.getChildCount(); i++) {
final PolyNode node = polyNodes.childs.get( i );
if (node.getEndType() == EndType.CLOSED_POLYGON || node.getEndType() == EndType.CLOSED_LINE && node.getPolygon().orientation()) {
@@ -432,8 +433,8 @@ private void offsetPoint( int j, int[] kV, JoinType jointype ) {
final double nky = normals.get( k ).getY();
final double njy = normals.get( j ).getY();
final double njx = normals.get( j ).getX();
- final long sjx = srcPoly.get( j ).getX();
- final long sjy = srcPoly.get( j ).getY();
+ final double sjx = srcPoly.get( j ).getX();
+ final double sjy = srcPoly.get( j ).getY();
inA = nkx * njy - njx * nky;
if (Math.abs( inA * delta ) < 1.0) {
@@ -442,7 +443,7 @@ private void offsetPoint( int j, int[] kV, JoinType jointype ) {
final double cosA = nkx * njx + njy * nky;
if (cosA > 0) // angle ==> 0 degrees
{
- destPoly.add( new LongPoint( (int) Math.round( sjx + nkx * delta ), (int) Math.round( sjy + nky * delta ), 0 ) );
+ destPoly.add( new Point( sjx + nkx * delta, sjy + nky * delta ) );
return;
}
//else angle ==> 180 degrees
@@ -455,9 +456,9 @@ else if (inA < -1.0) {
}
if (inA * delta < 0) {
- destPoly.add( new LongPoint( (int) Math.round( sjx + nkx * delta ), (int) Math.round( sjy + nky * delta ) ) );
+ destPoly.add( new Point( sjx + nkx * delta , sjy + nky * delta ) );
destPoly.add( srcPoly.get( j ) );
- destPoly.add( new LongPoint( (int) Math.round( sjx + njx * delta ), (int) Math.round( sjy + njy * delta ) ) );
+ destPoly.add( new Point( sjx + njx * delta , sjy + njy * delta ) );
}
else {
switch (jointype) {
diff --git a/Clipper/src/de/lighti/clipper/DefaultClipper.java b/Clipper/src/de/lighti/clipper/DefaultClipper.java
index d5e11c2..99488b8 100644
--- a/Clipper/src/de/lighti/clipper/DefaultClipper.java
+++ b/Clipper/src/de/lighti/clipper/DefaultClipper.java
@@ -4,29 +4,29 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.logging.Level;
import java.util.logging.Logger;
import de.lighti.clipper.Path.Join;
import de.lighti.clipper.Path.OutRec;
-import de.lighti.clipper.Point.LongPoint;
public class DefaultClipper extends ClipperBase {
private class IntersectNode {
Edge edge1;
Edge Edge2;
- private LongPoint pt;
+ private Point pt;
- public LongPoint getPt() {
+ public Point getPt() {
return pt;
}
- public void setPt( LongPoint pt ) {
+ public void setPt( Point pt ) {
this.pt = pt;
}
};
- private static void getHorzDirection( Edge HorzEdge, Direction[] Dir, long[] Left, long[] Right ) {
+ private static void getHorzDirection(Edge HorzEdge, Direction[] Dir, double[] Left, double[] Right ) {
if (HorzEdge.getBot().getX() < HorzEdge.getTop().getX()) {
Left[0] = HorzEdge.getBot().getX();
Right[0] = HorzEdge.getTop().getX();
@@ -39,7 +39,7 @@ private static void getHorzDirection( Edge HorzEdge, Direction[] Dir, long[] Lef
}
}
- private static boolean getOverlap( long a1, long a2, long b1, long b2, long[] Left, long[] Right ) {
+ private static boolean getOverlap( double a1, double a2, double b1, double b2, double[] Left, double[] Right ) {
if (a1 < a2) {
if (b1 < b2) {
Left[0] = Math.max( a1, b1 );
@@ -76,15 +76,15 @@ private static boolean isOutRec1RightOfOutRec2( OutRec outRec1, OutRec outRec2 )
//See "The Point in Polygon Problem for Arbitrary Polygons" by Hormann & Agathos
//http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.88.5498&rep=rep1&type=pdf
- private static int isPointInPolygon( LongPoint pt, Path.OutPt op ) {
+ private static int isPointInPolygon(Point pt, Path.OutPt op ) {
//returns 0 if false, +1 if true, -1 if pt ON polygon boundary
int result = 0;
final Path.OutPt startOp = op;
- final long ptx = pt.getX(), pty = pt.getY();
- long poly0x = op.getPt().getX(), poly0y = op.getPt().getY();
+ final double ptx = pt.getX(), pty = pt.getY();
+ double poly0x = op.getPt().getX(), poly0y = op.getPt().getY();
do {
op = op.next;
- final long poly1x = op.getPt().getX(), poly1y = op.getPt().getY();
+ final double poly1x = op.getPt().getX(), poly1y = op.getPt().getY();
if (poly1y == pty) {
if (poly1x == ptx || poly0y == pty && poly1x > ptx == poly0x < ptx) {
@@ -127,7 +127,7 @@ private static int isPointInPolygon( LongPoint pt, Path.OutPt op ) {
}
//------------------------------------------------------------------------------
- private static boolean joinHorz( Path.OutPt op1, Path.OutPt op1b, Path.OutPt op2, Path.OutPt op2b, LongPoint Pt, boolean DiscardLeft ) {
+ private static boolean joinHorz(Path.OutPt op1, Path.OutPt op1b, Path.OutPt op2, Path.OutPt op2b, Point Pt, boolean DiscardLeft ) {
final Direction Dir1 = op1.getPt().getX() > op1b.getPt().getX() ? Direction.RIGHT_TO_LEFT : Direction.LEFT_TO_RIGHT;
final Direction Dir2 = op2.getPt().getX() > op2b.getPt().getX() ? Direction.RIGHT_TO_LEFT : Direction.LEFT_TO_RIGHT;
if (Dir1 == Dir2) {
@@ -149,7 +149,7 @@ private static boolean joinHorz( Path.OutPt op1, Path.OutPt op1b, Path.OutPt op2
op1b = op1.duplicate( !DiscardLeft );
if (!op1b.getPt().equals( Pt )) {
op1 = op1b;
- op1.setPt( new LongPoint( Pt ) );
+ op1.setPt( new Point( Pt ) );
op1b = op1.duplicate( !DiscardLeft );
}
}
@@ -163,7 +163,7 @@ private static boolean joinHorz( Path.OutPt op1, Path.OutPt op1b, Path.OutPt op2
op1b = op1.duplicate( DiscardLeft );
if (!op1b.getPt().equals( Pt )) {
op1 = op1b;
- op1.setPt( new LongPoint( Pt ) );
+ op1.setPt( new Point( Pt ) );
op1b = op1.duplicate( DiscardLeft );
}
}
@@ -178,7 +178,7 @@ private static boolean joinHorz( Path.OutPt op1, Path.OutPt op1b, Path.OutPt op2
op2b = op2.duplicate( !DiscardLeft );
if (!op2b.getPt().equals( Pt )) {
op2 = op2b;
- op2.setPt( new LongPoint( Pt ) );
+ op2.setPt( new Point( Pt ) );
op2b = op2.duplicate( !DiscardLeft );
}
;
@@ -193,7 +193,7 @@ private static boolean joinHorz( Path.OutPt op1, Path.OutPt op1b, Path.OutPt op2
op2b = op2.duplicate( DiscardLeft );
if (!op2b.getPt().equals( Pt )) {
op2 = op2b;
- op2.setPt( new LongPoint( Pt ) );
+ op2.setPt( new Point( Pt ) );
op2b = op2.duplicate( DiscardLeft );
}
;
@@ -295,33 +295,33 @@ else if (isHorizontal) {
return false;
} //a flat 'polygon'
- final long[] LeftV = new long[1], RightV = new long[1];
+ final double[] LeftV = new double[1], RightV = new double[1];
//Op1 -. Op1b & Op2 -. Op2b are the extremites of the horizontal edges
if (!getOverlap( op1.getPt().getX(), op1b.getPt().getX(), op2.getPt().getX(), op2b.getPt().getX(), LeftV, RightV )) {
return false;
}
- final long Left = LeftV[0];
- final long Right = RightV[0];
+ final double Left = LeftV[0];
+ final double Right = RightV[0];
//DiscardLeftSide: when overlapping edges are joined, a spike will created
//which needs to be cleaned up. However, we don't want Op1 or Op2 caught up
//on the discard Side as either may still be needed for other joins ...
- LongPoint Pt;
+ Point Pt;
boolean DiscardLeftSide;
if (op1.getPt().getX() >= Left && op1.getPt().getX() <= Right) {
- Pt = new LongPoint( op1.getPt() );
+ Pt = new Point( op1.getPt() );
DiscardLeftSide = op1.getPt().getX() > op1b.getPt().getX();
}
else if (op2.getPt().getX() >= Left && op2.getPt().getX() <= Right) {
- Pt = new LongPoint( op2.getPt() );
+ Pt = new Point( op2.getPt() );
DiscardLeftSide = op2.getPt().getX() > op2b.getPt().getX();
}
else if (op1b.getPt().getX() >= Left && op1b.getPt().getX() <= Right) {
- Pt = new LongPoint( op1b.getPt() );
+ Pt = new Point( op1b.getPt() );
DiscardLeftSide = op1b.getPt().getX() > op1.getPt().getX();
}
else {
- Pt = new LongPoint( op2b.getPt() );
+ Pt = new Point( op2b.getPt() );
DiscardLeftSide = op2b.getPt().getX() > op2.getPt().getX();
}
j.outPt1 = op1;
@@ -393,7 +393,7 @@ else if (op1b.getPt().getX() >= Left && op1b.getPt().getX() <= Right) {
}
}
- private static Paths minkowski( Path pattern, Path path, boolean IsSum, boolean IsClosed ) {
+ private static Paths minkowski(Path pattern, Path path, boolean IsSum, boolean IsClosed ) {
final int delta = IsClosed ? 1 : 0;
final int polyCnt = pattern.size();
final int pathCnt = path.size();
@@ -401,8 +401,8 @@ private static Paths minkowski( Path pattern, Path path, boolean IsSum, boolean
if (IsSum) {
for (int i = 0; i < pathCnt; i++) {
final Path p = new Path( polyCnt );
- for (final LongPoint ip : pattern) {
- p.add( new LongPoint( path.get( i ).getX() + ip.getX(), path.get( i ).getY() + ip.getY(), 0 ) );
+ for (final Point ip : pattern) {
+ p.add( new Point( path.get( i ).getX() + ip.getX(), path.get( i ).getY() + ip.getY()) );
}
result.add( p );
}
@@ -410,8 +410,8 @@ private static Paths minkowski( Path pattern, Path path, boolean IsSum, boolean
else {
for (int i = 0; i < pathCnt; i++) {
final Path p = new Path( polyCnt );
- for (final LongPoint ip : pattern) {
- p.add( new LongPoint( path.get( i ).getX() - ip.getX(), path.get( i ).getY() - ip.getY(), 0 ) );
+ for (final Point ip : pattern) {
+ p.add( new Point( path.get( i ).getX() - ip.getX(), path.get( i ).getY() - ip.getY() ) );
}
result.add( p );
}
@@ -560,7 +560,7 @@ public DefaultClipper( int InitOptions ) //constructor
sortedEdges = null;
intersectList = new ArrayList();
intersectNodeComparer = ( node1, node2 ) -> {
- final long i = node2.getPt().getY() - node1.getPt().getY();
+ final double i = node2.getPt().getY() - node1.getPt().getY();
if (i > 0) {
return 1;
}
@@ -602,27 +602,27 @@ private void addEdgeToSEL( Edge edge ) {
}
}
- private void addGhostJoin( Path.OutPt Op, LongPoint OffPt ) {
+ private void addGhostJoin(Path.OutPt Op, Point OffPt ) {
final Join j = new Join();
j.outPt1 = Op;
- j.setOffPt( new LongPoint( OffPt ) );
+ j.setOffPt( new Point( OffPt ) );
ghostJoins.add( j );
}
//------------------------------------------------------------------------------
- private void addJoin( Path.OutPt Op1, Path.OutPt Op2, LongPoint OffPt ) {
+ private void addJoin(Path.OutPt Op1, Path.OutPt Op2, Point OffPt ) {
LOGGER.entering( DefaultClipper.class.getName(), "addJoin" );
final Join j = new Join();
j.outPt1 = Op1;
j.outPt2 = Op2;
- j.setOffPt( new LongPoint( OffPt ) );
+ j.setOffPt( new Point( OffPt ) );
joins.add( j );
}
//------------------------------------------------------------------------------
- private void addLocalMaxPoly( Edge e1, Edge e2, LongPoint pt ) {
+ private void addLocalMaxPoly(Edge e1, Edge e2, Point pt ) {
addOutPt( e1, pt );
if (e2.windDelta == 0) {
addOutPt( e2, pt );
@@ -641,7 +641,7 @@ else if (e1.outIdx < e2.outIdx) {
//------------------------------------------------------------------------------
- private Path.OutPt addLocalMinPoly( Edge e1, Edge e2, LongPoint pt ) {
+ private Path.OutPt addLocalMinPoly(Edge e1, Edge e2, Point pt ) {
LOGGER.entering( DefaultClipper.class.getName(), "addLocalMinPoly" );
Path.OutPt result;
Edge e, prevE;
@@ -673,10 +673,10 @@ private Path.OutPt addLocalMinPoly( Edge e1, Edge e2, LongPoint pt ) {
}
if (prevE != null && prevE.outIdx >= 0 && prevE.getTop().getY() < pt.getY() && e.getTop().getY() < pt.getY()) {
- long xPrev = Edge.topX( prevE, pt.getY() );
- long xE = Edge.topX( e, pt.getY() );
+ double xPrev = Edge.topX( prevE, pt.getY() );
+ double xE = Edge.topX( e, pt.getY() );
if (xPrev == xE && e.windDelta != 0 && prevE.windDelta != 0 &&
- Point.slopesEqual( new LongPoint( xPrev, pt.getY() ), prevE.getTop(), new LongPoint( xE, pt.getY() ), e.getTop() )) {
+ Point.slopesEqual( new Point( xPrev, pt.getY() ), prevE.getTop(), new Point( xE, pt.getY() ), e.getTop() )) {
final Path.OutPt outPt = addOutPt( prevE, pt );
addJoin( result, outPt, e.getTop() );
}
@@ -684,7 +684,7 @@ private Path.OutPt addLocalMinPoly( Edge e1, Edge e2, LongPoint pt ) {
return result;
}
- private Path.OutPt addOutPt( Edge e, LongPoint pt ) {
+ private Path.OutPt addOutPt(Edge e, Point pt ) {
LOGGER.entering( DefaultClipper.class.getName(), "addOutPt" );
if (e.outIdx < 0) {
final OutRec outRec = createOutRec();
@@ -692,7 +692,7 @@ private Path.OutPt addOutPt( Edge e, LongPoint pt ) {
final Path.OutPt newOp = new Path.OutPt();
outRec.setPoints( newOp );
newOp.idx = outRec.Idx;
- newOp.setPt( new LongPoint( pt ) );
+ newOp.setPt( new Point( pt ) );
newOp.next = newOp;
newOp.prev = newOp;
if (!outRec.isOpen) {
@@ -707,8 +707,10 @@ private Path.OutPt addOutPt( Edge e, LongPoint pt ) {
//OutRec.Pts is the 'Left-most' point & OutRec.Pts.Prev is the 'Right-most'
final Path.OutPt op = outRec.getPoints();
final boolean ToFront = e.side == Edge.Side.LEFT;
- LOGGER.finest( "op=" + Path.OutPt.getPointCount( op ) );
- LOGGER.finest( ToFront + " " + pt + " " + op.getPt() );
+ if (LOGGER.isLoggable( Level.FINEST )) {
+ LOGGER.finest( "op=" + Path.OutPt.getPointCount( op ) );
+ LOGGER.finest( ToFront + " " + pt + " " + op.getPt() );
+ }
if (ToFront && pt.equals( op.getPt() )) {
return op;
}
@@ -718,7 +720,7 @@ else if (!ToFront && pt.equals( op.prev.getPt() )) {
final Path.OutPt newOp = new Path.OutPt();
newOp.idx = outRec.Idx;
- newOp.setPt( new LongPoint( pt ) );
+ newOp.setPt( new Point( pt ) );
newOp.next = op;
newOp.prev = op.prev;
newOp.prev.next = newOp;
@@ -732,7 +734,7 @@ else if (!ToFront && pt.equals( op.prev.getPt() )) {
private Path.OutPt getLastOutPt(Edge e) {
OutRec outRec = polyOuts.get( e.outIdx );
- if (e.side == Edge.Side.LEFT)
+ if (e.side == Edge.Side.LEFT)
return outRec.getPoints();
else
return outRec.getPoints().prev;
@@ -838,7 +840,7 @@ else if (isOutRec1RightOfOutRec2( outRec2, outRec1 )) {
//------------------------------------------------------------------------------
- private void buildIntersectList( long topY ) {
+ private void buildIntersectList( double topY ) {
if (activeEdges == null) {
return;
}
@@ -860,16 +862,16 @@ private void buildIntersectList( long topY ) {
e = sortedEdges;
while (e.nextInSEL != null) {
final Edge eNext = e.nextInSEL;
- final LongPoint[] pt = new LongPoint[1];
+ final Point[] pt = new Point[1];
if (e.getCurrent().getX() > eNext.getCurrent().getX()) {
intersectPoint( e, eNext, pt );
if (pt[0].getY() < topY) {
- pt[0] = new LongPoint( Edge.topX( e, topY ), topY );
+ pt[0] = new Point( Edge.topX( e, topY ), topY );
}
final IntersectNode newNode = new IntersectNode();
newNode.edge1 = e;
newNode.Edge2 = eNext;
- newNode.setPt( new LongPoint( pt[0] ) ); // TODO is new instance necessary?
+ newNode.setPt( new Point( pt[0] ) ); // TODO is new instance necessary?
intersectList.add( newNode );
swapPositionsInSEL( e, eNext );
@@ -906,7 +908,7 @@ private void buildResult( Paths polyg ) {
}
final Path pg = new Path( cnt );
for (int j = 0; j < cnt; j++) {
- pg.add( new LongPoint( p.getPt() ) );
+ pg.add( new Point( p.getPt() ) );
p = p.prev;
}
polyg.add( pg );
@@ -981,14 +983,14 @@ private boolean deleteFromSEL( Edge[] e ) {
return true;
}
- private boolean doHorzSegmentsOverlap( long seg1a, long seg1b, long seg2a, long seg2b ) {
+ private boolean doHorzSegmentsOverlap( double seg1a, double seg1b, double seg2a, double seg2b ) {
if (seg1a > seg1b) {
- final long tmp = seg1a;
+ final double tmp = seg1a;
seg1a = seg1b;
seg1b = tmp;
}
if (seg2a > seg2b) {
- final long tmp = seg2a;
+ final double tmp = seg2a;
seg2a = seg2b;
seg2b = tmp;
}
@@ -1007,9 +1009,9 @@ private void doMaxima( Edge e ) {
Edge eNext = e.nextInAEL;
while (eNext != null && eNext != eMaxPair) {
- final LongPoint tmp = new LongPoint( e.getTop() );
+ final Point tmp = new Point( e.getTop() );
intersectEdges( e, eNext, tmp );
- e.setTop( new LongPoint( tmp ) );
+ e.setTop( new Point( tmp ) );
swapPositionsInAEL( e, eNext );
eNext = e.nextInAEL;
}
@@ -1186,7 +1188,7 @@ private boolean executeInternal() {
sortedEdges = null;
maxima = null;
- long[] botY = new long[1], topY = new long[1];
+ double[] botY = new double[1], topY = new double[1];
if (!popScanbeam( botY )) return false;
insertLocalMinimaIntoAEL( botY[0] );
while ( popScanbeam( topY ) || localMinimaPending()) {
@@ -1416,7 +1418,7 @@ else if (startEdge == null && Edge.doesE2InsertBeforeE1( activeEdges, edge )) {
//------------------------------------------------------------------------------
- private void insertLocalMinimaIntoAEL( long botY ) {
+ private void insertLocalMinimaIntoAEL( double botY ) {
LOGGER.entering( DefaultClipper.class.getName(), "insertLocalMinimaIntoAEL" );
LocalMinima[] lm = new LocalMinima[1];
@@ -1511,7 +1513,7 @@ else if (rb == null) {
//------------------------------------------------------------------------------
- private void intersectEdges( Edge e1, Edge e2, LongPoint pt ) {
+ private void intersectEdges(Edge e1, Edge e2, Point pt ) {
LOGGER.entering( DefaultClipper.class.getName(), "insersectEdges" );
//e1 will be to the left of e2 BELOW the intersection. Therefore e1 is before
@@ -1727,8 +1729,8 @@ else if (e1Wc == 1 && e2Wc == 1) {
}
}
- private void intersectPoint( Edge edge1, Edge edge2, LongPoint[] ipV ) {
- final LongPoint ip = ipV[0] = new LongPoint();
+ private void intersectPoint(Edge edge1, Edge edge2, Point[] ipV ) {
+ final Point ip = ipV[0] = new Point();
double b1, b2;
//nb: with very large coordinate values, it's possible for SlopesEqual() to
@@ -1746,7 +1748,7 @@ private void intersectPoint( Edge edge1, Edge edge2, LongPoint[] ipV ) {
}
else {
b2 = edge2.getBot().getY() - edge2.getBot().getX() / edge2.deltaX;
- ip.setY( Math.round( ip.getX() / edge2.deltaX + b2 ) );
+ ip.setY( ip.getX() / edge2.deltaX + b2 );
}
}
else if (edge2.getDelta().getX() == 0) {
@@ -1756,19 +1758,19 @@ else if (edge2.getDelta().getX() == 0) {
}
else {
b1 = edge1.getBot().getY() - edge1.getBot().getX() / edge1.deltaX;
- ip.setY( Math.round( ip.getX() / edge1.deltaX + b1 ) );
+ ip.setY( ip.getX() / edge1.deltaX + b1 );
}
}
else {
b1 = edge1.getBot().getX() - edge1.getBot().getY() * edge1.deltaX;
b2 = edge2.getBot().getX() - edge2.getBot().getY() * edge2.deltaX;
final double q = (b2 - b1) / (edge1.deltaX - edge2.deltaX);
- ip.setY( Math.round( q ) );
+ ip.setY( q );
if (Math.abs( edge1.deltaX ) < Math.abs( edge2.deltaX )) {
- ip.setX( Math.round( edge1.deltaX * q + b1 ) );
+ ip.setX( edge1.deltaX * q + b1 );
}
else {
- ip.setX( Math.round( edge2.deltaX * q + b2 ) );
+ ip.setX( edge2.deltaX * q + b2 );
}
}
@@ -1906,7 +1908,7 @@ else if (poly2ContainsPoly1( outRec1.getPoints(), outRec2.getPoints() )) {
}
}
- private void processEdgesAtTopOfScanbeam( long topY ) {
+ private void processEdgesAtTopOfScanbeam( double topY ) {
LOGGER.entering( DefaultClipper.class.getName(), "processEdgesAtTopOfScanbeam" );
Edge e = activeEdges;
@@ -1952,7 +1954,7 @@ else if (e.getBot().getY() == topY) {
e.getCurrent().setZ( e.getBot().getZ() );
}
else {
- e.getCurrent().setZ( 0L );
+ e.getCurrent().setZ( 0d );
}
}
@@ -1962,7 +1964,7 @@ else if (e.getBot().getY() == topY) {
final Edge ePrev = e.prevInAEL;
if (e.outIdx >= 0 && e.windDelta != 0 && ePrev != null && ePrev.outIdx >= 0 && ePrev.getCurrent().getX() == e.getCurrent().getX()
&& ePrev.windDelta != 0) {
- final LongPoint ip = new LongPoint( e.getCurrent() );
+ final Point ip = new Point( e.getCurrent() );
setZ( ip, ePrev, e );
@@ -2016,7 +2018,7 @@ else if (eNext != null && eNext.getCurrent().getX() == e.getBot().getX() && eNex
private void processHorizontal( Edge horzEdge ) {
LOGGER.entering( DefaultClipper.class.getName(), "isHorizontal" );
final Direction[] dir = new Direction[1];
- final long[] horzLeft = new long[1], horzRight = new long[1];
+ final double[] horzLeft = new double[1], horzRight = new double[1];
boolean isOpen = horzEdge.windDelta == 0;
getHorzDirection( horzEdge, dir, horzLeft, horzRight );
@@ -2062,7 +2064,7 @@ private void processHorizontal( Edge horzEdge ) {
if (dir[0] == Direction.LEFT_TO_RIGHT) {
while (currMax != null && currMax.x < e.getCurrent().getX()) {
if (horzEdge.outIdx >= 0 && !isOpen) {
- addOutPt( horzEdge, new LongPoint( currMax.x, horzEdge.getBot().getY() ) );
+ addOutPt( horzEdge, new Point( currMax.x, horzEdge.getBot().getY() ) );
}
currMax = currMax.next;
}
@@ -2070,7 +2072,7 @@ private void processHorizontal( Edge horzEdge ) {
else {
while (currMax != null && currMax.x > e.getCurrent().getX()) {
if (horzEdge.outIdx >= 0 && !isOpen) {
- addOutPt( horzEdge, new LongPoint( currMax.x, horzEdge.getBot().getY() ) );
+ addOutPt( horzEdge, new Point( currMax.x, horzEdge.getBot().getY() ) );
}
currMax = currMax.prev;
}
@@ -2117,11 +2119,11 @@ private void processHorizontal( Edge horzEdge ) {
}
if (dir[0] == Direction.LEFT_TO_RIGHT) {
- final LongPoint Pt = new LongPoint( e.getCurrent().getX(), horzEdge.getCurrent().getY() );
+ final Point Pt = new Point( e.getCurrent().getX(), horzEdge.getCurrent().getY() );
intersectEdges( horzEdge, e, Pt );
}
else {
- final LongPoint Pt = new LongPoint( e.getCurrent().getX(), horzEdge.getCurrent().getY() );
+ final Point Pt = new Point( e.getCurrent().getX(), horzEdge.getCurrent().getY() );
intersectEdges( e, horzEdge, Pt );
}
final Edge eNext = e.getNextInAEL( dir[0] );
@@ -2193,7 +2195,7 @@ private void processHorizontals() {
//------------------------------------------------------------------------------
- private boolean processIntersections( long topY ) {
+ private boolean processIntersections( double topY ) {
LOGGER.entering( DefaultClipper.class.getName(), "processIntersections" );
if (activeEdges == null) {
@@ -2233,7 +2235,7 @@ private void processIntersectList() {
//------------------------------------------------------------------------------
- private void insertMaxima( long x ) {
+ private void insertMaxima( double x ) {
//double-linked list: sorted ascending, ignoring dups.
final Maxima newMax = new Maxima();
newMax.x = x;
@@ -2287,7 +2289,7 @@ else if (eTmp.outIdx == e2.outIdx) {
}
}
- private void setZ( LongPoint pt, Edge e1, Edge e2 ) {
+ private void setZ(Point pt, Edge e1, Edge e2 ) {
if (pt.getZ() != 0 || zFillFunction == null) {
return;
}
@@ -2397,7 +2399,7 @@ private void updateEdgeIntoAEL( Edge[] eV ) {
e.nextInLML.windCnt = e.windCnt;
e.nextInLML.windCnt2 = e.windCnt2;
eV[0] = e = e.nextInLML;
- e.setCurrent( new LongPoint( e.getBot() ) );
+ e.setCurrent( new Point( e.getBot() ) );
e.prevInAEL = AelPrev;
e.nextInAEL = AelNext;
if (!e.isHorizontal()) {
diff --git a/Clipper/src/de/lighti/clipper/Edge.java b/Clipper/src/de/lighti/clipper/Edge.java
index 5ccac86..23afb82 100644
--- a/Clipper/src/de/lighti/clipper/Edge.java
+++ b/Clipper/src/de/lighti/clipper/Edge.java
@@ -6,7 +6,6 @@
import de.lighti.clipper.Clipper.Direction;
import de.lighti.clipper.Clipper.PolyFillType;
import de.lighti.clipper.Clipper.PolyType;
-import de.lighti.clipper.Point.LongPoint;
class Edge {
static enum Side {
@@ -44,20 +43,20 @@ static void swapSides( Edge edge1, Edge edge2 ) {
edge2.side = side;
}
- static long topX( Edge edge, long currentY ) {
+ static double topX(Edge edge, double currentY ) {
if (currentY == edge.getTop().getY()) {
return edge.getTop().getX();
}
- return (int) (edge.getBot().getX() + Math.round( edge.deltaX * (currentY - edge.getBot().getY()) ));
+ return edge.getBot().getX() + edge.deltaX * (currentY - edge.getBot().getY());
}
- private final LongPoint bot;
+ private final Point bot;
- private final LongPoint current; //current (updated for every new scanbeam)
+ private final Point current; //current (updated for every new scanbeam)
- private final LongPoint top;
+ private final Point top;
- private final LongPoint delta;
+ private final Point delta;
double deltaX;
PolyType polyTyp;
@@ -86,10 +85,10 @@ static long topX( Edge edge, long currentY ) {
private final static Logger LOGGER = Logger.getLogger( Edge.class.getName() );
public Edge() {
- delta = new LongPoint();
- top = new LongPoint();
- bot = new LongPoint();
- current = new LongPoint();
+ delta = new Point();
+ top = new Point();
+ bot = new Point();
+ current = new Point();
}
public Edge findNextLocMin() {
@@ -120,15 +119,15 @@ public Edge findNextLocMin() {
return e;
}
- public LongPoint getBot() {
+ public Point getBot() {
return bot;
}
- public LongPoint getCurrent() {
+ public Point getCurrent() {
return current;
}
- public LongPoint getDelta() {
+ public Point getDelta() {
return delta;
}
@@ -152,11 +151,11 @@ Edge getMaximaPairEx() {
return result;
}
- public Edge getNextInAEL( Direction direction ) {
+ public Edge getNextInAEL(Direction direction ) {
return direction == Direction.LEFT_TO_RIGHT ? nextInAEL : prevInAEL;
}
- public LongPoint getTop() {
+ public Point getTop() {
return top;
}
@@ -294,7 +293,7 @@ public void reverseHorizontal() {
//swap horizontal edges' top and bottom x's so they follow the natural
//progression of the bounds - ie so their xbots will align with the
//adjoining lower edge. [Helpful in the ProcessHorizontal() method.]
- long temp = top.getX();
+ double temp = top.getX();
top.setX( bot.getX() );
bot.setX( temp );
@@ -304,15 +303,15 @@ public void reverseHorizontal() {
}
- public void setBot( LongPoint bot ) {
+ public void setBot( Point bot ) {
this.bot.set( bot );
}
- public void setCurrent( LongPoint current ) {
+ public void setCurrent( Point current ) {
this.current.set( current );
}
- public void setTop( LongPoint top ) {
+ public void setTop( Point top ) {
this.top.set( top );
}
diff --git a/Clipper/src/de/lighti/clipper/LongRect.java b/Clipper/src/de/lighti/clipper/LongRect.java
index 18a10a4..97cf834 100644
--- a/Clipper/src/de/lighti/clipper/LongRect.java
+++ b/Clipper/src/de/lighti/clipper/LongRect.java
@@ -1,16 +1,16 @@
package de.lighti.clipper;
public class LongRect {
- public long left;
- public long top;
- public long right;
- public long bottom;
+ public double left;
+ public double top;
+ public double right;
+ public double bottom;
public LongRect() {
}
- public LongRect( long l, long t, long r, long b ) {
+ public LongRect( double l, double t, double r, double b ) {
left = l;
top = t;
right = r;
diff --git a/Clipper/src/de/lighti/clipper/Path.java b/Clipper/src/de/lighti/clipper/Path.java
index 9972488..9896d62 100644
--- a/Clipper/src/de/lighti/clipper/Path.java
+++ b/Clipper/src/de/lighti/clipper/Path.java
@@ -3,25 +3,23 @@
import java.util.ArrayList;
import java.util.Collections;
-import de.lighti.clipper.Point.LongPoint;
-
/**
* A pure convenience class to avoid writing List everywhere.
*
* @author Tobias Mahlmann
*
*/
-public class Path extends ArrayList {
+public class Path extends ArrayList {
static class Join {
Path.OutPt outPt1;
Path.OutPt outPt2;
- private LongPoint offPt;
+ private Point offPt;
- public LongPoint getOffPt() {
+ public Point getOffPt() {
return offPt;
}
- public void setOffPt( LongPoint offPt ) {
+ public void setOffPt( Point offPt ) {
this.offPt = offPt;
}
@@ -69,24 +67,24 @@ private static boolean isFirstBottomPt( Path.OutPt btmPt1, Path.OutPt btmPt2 ) {
while (p.getPt().equals( btmPt1.getPt() ) && !p.equals( btmPt1 )) {
p = p.prev;
}
- final double dx1p = Math.abs( LongPoint.getDeltaX( btmPt1.getPt(), p.getPt() ) );
+ final double dx1p = Math.abs( Point.getDeltaX( btmPt1.getPt(), p.getPt() ) );
p = btmPt1.next;
while (p.getPt().equals( btmPt1.getPt() ) && !p.equals( btmPt1 )) {
p = p.next;
}
- final double dx1n = Math.abs( LongPoint.getDeltaX( btmPt1.getPt(), p.getPt() ) );
+ final double dx1n = Math.abs( Point.getDeltaX( btmPt1.getPt(), p.getPt() ) );
p = btmPt2.prev;
while (p.getPt().equals( btmPt2.getPt() ) && !p.equals( btmPt2 )) {
p = p.prev;
}
- final double dx2p = Math.abs( LongPoint.getDeltaX( btmPt2.getPt(), p.getPt() ) );
+ final double dx2p = Math.abs( Point.getDeltaX( btmPt2.getPt(), p.getPt() ) );
p = btmPt2.next;
while (p.getPt().equals( btmPt2.getPt() ) && p.equals( btmPt2 )) {
p = p.next;
}
- final double dx2n = Math.abs( LongPoint.getDeltaX( btmPt2.getPt(), p.getPt() ) );
-
+ final double dx2n = Math.abs( Point.getDeltaX( btmPt2.getPt(), p.getPt() ) );
+
if (Math.max( dx1p, dx1n ) == Math.max( dx2p, dx2n ) && Math.min( dx1p, dx1n ) == Math.min( dx2p, dx2n )) {
return btmPt1.area() > 0; //if otherwise identical use orientation
}
@@ -96,14 +94,14 @@ private static boolean isFirstBottomPt( Path.OutPt btmPt1, Path.OutPt btmPt2 ) {
}
int idx;
- private LongPoint pt;
+ private Point pt;
OutPt next;
OutPt prev;
public Path.OutPt duplicate( boolean InsertAfter ) {
final Path.OutPt result = new Path.OutPt();
- result.setPt( new LongPoint( getPt() ) );
+ result.setPt( new Point( getPt() ) );
result.idx = idx;
if (InsertAfter) {
result.next = next;
@@ -169,7 +167,7 @@ public static int getPointCount( OutPt pts ) {
return result;
}
- public LongPoint getPt() {
+ public Point getPt() {
return pt;
}
@@ -187,10 +185,10 @@ public void reversePolyPtLinks() {
while (pp1 != this);
}
- public void setPt( LongPoint pt ) {
+ public void setPt( Point pt ) {
this.pt = pt;
}
-
+
private double area() {
Path.OutPt op = this;
double a = 0;
@@ -198,7 +196,7 @@ private double area() {
a = a + (double) (op.prev.getPt().getX() + op.getPt().getX()) * (double) (op.prev.getPt().getY() - op.getPt().getY());
op = op.next;
} while (op != this);
- return a * 0.5;
+ return a * 0.5;
}
}
@@ -345,7 +343,7 @@ else if (Point.slopesNearCollinear( op.prev.pt, op.pt, op.next.pt, distSqrd )) {
return result;
}
- public int isPointInPolygon( LongPoint pt ) {
+ public int isPointInPolygon(Point pt) {
//returns 0 if false, +1 if true, -1 if pt ON polygon boundary
//See "The Point in Polygon Problem for Arbitrary Polygons" by Hormann & Agathos
//http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.88.5498&rep=rep1&type=pdf
@@ -354,9 +352,9 @@ public int isPointInPolygon( LongPoint pt ) {
if (cnt < 3) {
return 0;
}
- LongPoint ip = get( 0 );
+ Point ip = get( 0 );
for (int i = 1; i <= cnt; ++i) {
- final LongPoint ipNext = i == cnt ? get( 0 ) : get( i );
+ final Point ipNext = i == cnt ? get( 0 ) : get( i );
if (ipNext.getY() == pt.getY()) {
if (ipNext.getX() == pt.getX() || ip.getY() == pt.getY() && ipNext.getX() > pt.getX() == ip.getX() < pt.getX()) {
return -1;
@@ -404,10 +402,10 @@ public void reverse() {
Collections.reverse( this );
}
- public Path TranslatePath( LongPoint delta ) {
+ public Path TranslatePath(Point delta ) {
final Path outPath = new Path( size() );
for (int i = 0; i < size(); i++) {
- outPath.add( new LongPoint( get( i ).getX() + delta.getX(), get( i ).getY() + delta.getY() ) );
+ outPath.add( new Point( get( i ).getX() + delta.getX(), get( i ).getY() + delta.getY() ) );
}
return outPath;
}
diff --git a/Clipper/src/de/lighti/clipper/Point.java b/Clipper/src/de/lighti/clipper/Point.java
index 50b6ced..67f2d72 100644
--- a/Clipper/src/de/lighti/clipper/Point.java
+++ b/Clipper/src/de/lighti/clipper/Point.java
@@ -2,74 +2,27 @@
import java.util.Comparator;
-public abstract class Point> {
- public static class DoublePoint extends Point {
- public DoublePoint() {
- this( 0, 0 );
- }
-
- public DoublePoint( double x, double y ) {
- this( x, y, 0 );
- }
-
- public DoublePoint( double x, double y, double z ) {
- super( x, y, z );
- }
-
- public DoublePoint( DoublePoint other ) {
- super( other );
- }
-
- public double getX() {
- return x;
- }
+public class Point {
- public double getY() {
- return y;
+ public static double getDeltaX(Point pt1, Point pt2 ) {
+ if (pt1.getY() == pt2.getY()) {
+ return Edge.HORIZONTAL;
}
-
- public double getZ() {
- return z;
+ else {
+ return (pt2.getX() - pt1.getX()) / (pt2.getY() - pt1.getY());
}
}
- public static class LongPoint extends Point {
- public static double getDeltaX( LongPoint pt1, LongPoint pt2 ) {
- if (pt1.getY() == pt2.getY()) {
- return Edge.HORIZONTAL;
- }
- else {
- return (double) (pt2.getX() - pt1.getX()) / (pt2.getY() - pt1.getY());
- }
- }
-
- public LongPoint() {
- this( 0, 0 );
- }
-
- public LongPoint( long x, long y ) {
- this( x, y, 0 );
- }
-
- public LongPoint( long x, long y, long z ) {
- super( x, y, z );
- }
-
- public LongPoint( LongPoint other ) {
- super( other );
- }
-
- public long getX() {
- return x;
- }
+ public double getX() {
+ return x;
+ }
- public long getY() {
- return y;
- }
+ public double getY() {
+ return y;
+ }
- public long getZ() {
- return z;
- }
+ public double getZ() {
+ return z;
}
private static class NumberComparator> implements Comparator {
@@ -80,41 +33,41 @@ public int compare( T a, T b ) throws ClassCastException {
}
}
- static boolean arePointsClose( Point extends Number> pt1, Point extends Number> pt2, double distSqrd ) {
- final double dx = pt1.x.doubleValue() - pt2.x.doubleValue();
- final double dy = pt1.y.doubleValue() - pt2.y.doubleValue();
+ static boolean arePointsClose(Point pt1, Point pt2, double distSqrd ) {
+ final double dx = pt1.x - pt2.x;
+ final double dy = pt1.y - pt2.y;
return dx * dx + dy * dy <= distSqrd;
}
- static double distanceFromLineSqrd( Point extends Number> pt, Point extends Number> ln1, Point extends Number> ln2 ) {
+ static double distanceFromLineSqrd(Point pt, Point ln1, Point ln2 ) {
//The equation of a line in general form (Ax + By + C = 0)
- //given 2 points (x¹,y¹) & (x²,y²) is ...
- //(y¹ - y²)x + (x² - x¹)y + (y² - y¹)x¹ - (x² - x¹)y¹ = 0
- //A = (y¹ - y²); B = (x² - x¹); C = (y² - y¹)x¹ - (x² - x¹)y¹
- //perpendicular distance of point (x³,y³) = (Ax³ + By³ + C)/Sqrt(A² + B²)
+ //given 2 points (x¹,y¹) & (x²,y²) is ...
+ //(y¹ - y²)x + (x² - x¹)y + (y² - y¹)x¹ - (x² - x¹)y¹ = 0
+ //A = (y¹ - y²); B = (x² - x¹); C = (y² - y¹)x¹ - (x² - x¹)y¹
+ //perpendicular distance of point (x³,y³) = (Ax³ + By³ + C)/Sqrt(A² + B²)
//see http://en.wikipedia.org/wiki/Perpendicular_distance
- final double A = ln1.y.doubleValue() - ln2.y.doubleValue();
- final double B = ln2.x.doubleValue() - ln1.x.doubleValue();
- double C = A * ln1.x.doubleValue() + B * ln1.y.doubleValue();
- C = A * pt.x.doubleValue() + B * pt.y.doubleValue() - C;
+ final double A = ln1.y - ln2.y;
+ final double B = ln2.x - ln1.x;
+ double C = A * ln1.x + B * ln1.y;
+ C = A * pt.x + B * pt.y - C;
return C * C / (A * A + B * B);
}
- static DoublePoint getUnitNormal( LongPoint pt1, LongPoint pt2 ) {
+ static Point getUnitNormal(Point pt1, Point pt2 ) {
double dx = pt2.x - pt1.x;
double dy = pt2.y - pt1.y;
if (dx == 0 && dy == 0) {
- return new DoublePoint();
+ return new Point();
}
final double f = 1 * 1.0 / Math.sqrt( dx * dx + dy * dy );
dx *= f;
dy *= f;
- return new DoublePoint( dy, -dx );
+ return new Point( dy, -dx);
}
- protected static boolean isPt2BetweenPt1AndPt3( LongPoint pt1, LongPoint pt2, LongPoint pt3 ) {
+ protected static boolean isPt2BetweenPt1AndPt3(Point pt1, Point pt2, Point pt3 ) {
if (pt1.equals( pt3 ) || pt1.equals( pt2 ) || pt3.equals( pt2 )) {
return false;
}
@@ -126,15 +79,15 @@ else if (pt1.x != pt3.x) {
}
}
- protected static boolean slopesEqual( LongPoint pt1, LongPoint pt2, LongPoint pt3 ) {
+ protected static boolean slopesEqual(Point pt1, Point pt2, Point pt3 ) {
return (pt1.y - pt2.y) * (pt2.x - pt3.x) - (pt1.x - pt2.x) * (pt2.y - pt3.y) == 0;
}
- protected static boolean slopesEqual( LongPoint pt1, LongPoint pt2, LongPoint pt3, LongPoint pt4 ) {
+ protected static boolean slopesEqual(Point pt1, Point pt2, Point pt3, Point pt4 ) {
return (pt1.y - pt2.y) * (pt3.x - pt4.x) - (pt1.x - pt2.x) * (pt3.y - pt4.y) == 0;
}
- static boolean slopesNearCollinear( LongPoint pt1, LongPoint pt2, LongPoint pt3, double distSqrd ) {
+ static boolean slopesNearCollinear(Point pt1, Point pt2, Point pt3, double distSqrd ) {
//this function is more accurate when the point that's GEOMETRICALLY
//between the other 2 points is the one that's tested for distance.
//nb: with 'spikes', either pt1 or pt3 is geometrically between the other pts
@@ -164,29 +117,41 @@ else if (pt2.y > pt1.y == pt2.y < pt3.y) {
private final static NumberComparator NUMBER_COMPARATOR = new NumberComparator();
- protected T x;
+ protected double x;
- protected T y;
+ protected double y;
- protected T z;
+ protected double z;
- protected Point( Point pt ) {
+ protected Point(Point pt ) {
this( pt.x, pt.y, pt.z );
}
- protected Point( T x, T y, T z ) {
+ protected Point(double x, double y, double z ) {
this.x = x;
this.y = y;
this.z = z;
}
+ public Point(double x, double y) {
+ this.x = x;
+ this.y = y;
+ this.z = 0.0;
+ }
+
+ public Point() {
+ this.x = 0.0;
+ this.y = 0.0;
+ this.z = 0.0;
+ }
+
@Override
public boolean equals( Object obj ) {
if (obj == null) {
return false;
}
- if (obj instanceof Point>) {
- final Point> a = (Point>) obj;
+ if (obj instanceof Point) {
+ final Point a = (Point) obj;
return NUMBER_COMPARATOR.compare( x, a.x ) == 0 && NUMBER_COMPARATOR.compare( y, a.y ) == 0;
}
else {
@@ -194,21 +159,21 @@ public boolean equals( Object obj ) {
}
}
- public void set( Point other ) {
+ public void set( Point other ) {
x = other.x;
y = other.y;
z = other.z;
}
- public void setX( T x ) {
+ public void setX( double x ) {
this.x = x;
}
- public void setY( T y ) {
+ public void setY( double y ) {
this.y = y;
}
- public void setZ( T z ) {
+ public void setZ( double z ) {
this.z = z;
}
diff --git a/Clipper/src/de/lighti/clipper/PolyNode.java b/Clipper/src/de/lighti/clipper/PolyNode.java
index fd5f9c4..85989dc 100644
--- a/Clipper/src/de/lighti/clipper/PolyNode.java
+++ b/Clipper/src/de/lighti/clipper/PolyNode.java
@@ -6,9 +6,8 @@
import de.lighti.clipper.Clipper.EndType;
import de.lighti.clipper.Clipper.JoinType;
-import de.lighti.clipper.Point.LongPoint;
-class PolyNode {
+public class PolyNode {
enum NodeType {
ANY, OPEN, CLOSED
}
@@ -36,7 +35,7 @@ public List getChilds() {
return Collections.unmodifiableList( childs );
}
- public List getContour() {
+ public List getContour() {
return polygon;
}
diff --git a/Clipper/src/de/lighti/clipper/PolyTree.java b/Clipper/src/de/lighti/clipper/PolyTree.java
index f785cc0..b0c191b 100644
--- a/Clipper/src/de/lighti/clipper/PolyTree.java
+++ b/Clipper/src/de/lighti/clipper/PolyTree.java
@@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;
-class PolyTree extends PolyNode {
+public class PolyTree extends PolyNode {
private final List allPolys = new ArrayList();
public void Clear() {
diff --git a/README.md b/README.md
index dcb6372..2b7c7c8 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,41 @@
# clipper-java
A Polygon clipper for Java
-Polygon Clipper is a library to execute various boolean operations (Union, Difference, XOR, etc.) on arbitrary 2D polygons, e.g. calculate the area in which two polygons overlap. It comes with two Demo applications, one for the console and one using a Swing based GUI.
+Polygon Clipper is a library to execute various boolean operations (Union, Difference, XOR, etc.) on arbitrary 2D
+polygons, e.g. calculate the area in which two polygons overlap. It comes with two Demo applications, one for the
+console and one using a Swing based GUI.
-It’s a 1:1 Java portation of the Clipper project developed by Angus Johnson, which as an implementation of the algorithm proposed by Bala R. Vatti. I just converted the code to Java 8, based on his C# Clipper version 6.4.2. If you’re interested in the documentation or have questions regarding the algorithm, please head over to his homepage. However, feel free to contact me if you found a bug or have a question regarding the Java version.
+It’s a 1:1 Java portation of the Clipper project developed by
+Angus Johnson, which as an implementation of the algorithm
+proposed by Bala R. Vatti.
+I just converted the code to Java 8, based on his C# Clipper version 6.4.2. If you’re interested in the documentation
+or have questions regarding the algorithm, please head over to his homepage. However, feel free to contact me if you
+found a bug or have a question regarding the Java version.
+
+## Release Notes
+
+### 6.4.2.1-SNAPSHOT
+
+- Use long instead of double for coordinates.
+
+### Prerequisites
+
+clipper-java requires Java 8.
+
+### Installing
+
+The project can be installed in the local repository using Maven.
+From the base directory, type:
+
+```
+mvn clean install
+```
+
+## Built With
+
+* [Maven](https://maven.apache.org/) - Dependency Management
+
+## License
+
+This project is licensed under the Boost Software License - Version 1.0 - August 17th, 2003 - see the license.txt
+file for details
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..21942e6
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,25 @@
+
+
+
+ 4.0.0
+
+ de.lighti.clipper
+ clipper-java-double
+
+ 6.4.2.1-SNAPSHOT
+ pom
+
+
+ Clipper
+ Clipper Console
+ Clipper GUI
+
+
+
+ 1.8
+ 1.8
+ UTF-8
+
+
+