diff --git a/tests/AreaBooleans/Area2D.pde b/tests/AreaBooleans/Area2D.pde index 3d85b22..2ea6513 100644 --- a/tests/AreaBooleans/Area2D.pde +++ b/tests/AreaBooleans/Area2D.pde @@ -6,20 +6,35 @@ import java.awt.geom.PathIterator; import java.awt.Polygon; class Area2D extends Area{ + float gridScale; public Area2D(Poly p) { super( (Polygon) p ); + gridScale=p.gridScale; } - public Area2D() { + public Area2D(float gScale) { super(); + gridScale=gScale; } + boolean contains(int x, int y) { + double dx=x/gridScale; + double dy=y/gridScale; + return super.contains(dx,dy); + } + + boolean contains(double x, double y) { + double dx=x/gridScale; + double dy=y/gridScale; + return super.contains(dx,dy); + } + void drawMe(){ PathIterator pathIter=getPathIterator(new AffineTransform()); beginShape(); float[] newCoords={0,0}; while(!pathIter.isDone()) { pathIter.currentSegment(newCoords); - vertex(newCoords[0],newCoords[1]); + vertex(gridScale*newCoords[0],gridScale*newCoords[1]); pathIter.next(); } endShape(); diff --git a/tests/AreaBooleans/AreaBooleans.pde b/tests/AreaBooleans/AreaBooleans.pde index 2179e17..b98ba07 100644 --- a/tests/AreaBooleans/AreaBooleans.pde +++ b/tests/AreaBooleans/AreaBooleans.pde @@ -1,19 +1,21 @@ // Testing 2D boolean operation using Java built-in Area construct. // - extending example from http://wiki.processing.org/w/Using_AWT's_Polygon_class +// - added gridScale parameter to handle int-only shapes like Polygons and general point-snapping. Poly p1,p2; Area2D a1,a2,a3; +float gridScale=0.01; void setup() { size(200,200); int[]x={ 20,40,40,60,60,20 }; int[]y={ 20,20,40,40,60,60 }; - p1=new Poly(x,y,6); - p2=new Poly(x,y,6); + p1=new Poly(gridScale,x,y,6); + p2=new Poly(gridScale,x,y,6); p2.translate(20,20); a1=new Area2D(p1); a2=new Area2D(p2); - a3=new Area2D(); + a3=new Area2D(gridScale); a3.add(a1); a3.intersect(a2); } diff --git a/tests/AreaBooleans/Poly.pde b/tests/AreaBooleans/Poly.pde index 5bfbdb7..f7c85f2 100644 --- a/tests/AreaBooleans/Poly.pde +++ b/tests/AreaBooleans/Poly.pde @@ -8,15 +8,57 @@ import java.awt.Polygon; */ class Poly extends Polygon{ - public Poly(int[] x,int[] y, int n){ - //call the java.awt.Polygon constructor - super(x,y,n); + float gridScale; + + public Poly(float gScale, int[] x,int[] y, int n) { + super(); + gridScale=gScale; + //call the java.awt.Polygon addPoint function + for(int i=0;i