Skip to content

Commit

Permalink
added a CHANGELOG
Browse files Browse the repository at this point in the history
fixed the bug where binary ops throw NullPointerException when the result is empty
added an overloaded contains(x, y)
  • Loading branch information
Ricard Marxer committed Nov 5, 2008
1 parent af714aa commit 56f502f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -0,0 +1,3 @@
rev 17:
- fixed the binary shape ops for when the result is null (thanks to ekene ijeoma for spotting it)
- added a RShape.contains(float x, float y)
2 changes: 1 addition & 1 deletion Makefile
@@ -1,5 +1,5 @@

GEOMERATIVE_VERSION=16
GEOMERATIVE_VERSION=18

JAVAC_ARGS=-source 1.3 -target 1.1
CLASSPATH=external/batikfont.jar:"$(PROCESSING_PATH)/lib/core.jar":"$(PROCESSING_PATH)/libraries/xml/library/xml.jar"
Expand Down
14 changes: 13 additions & 1 deletion src/geomerative/RG.java
Expand Up @@ -80,7 +80,7 @@ public static class NoPathInitializedException extends NullPointerException{
private static final long serialVersionUID = -3710605630786298673L;

NoPathInitializedException(){
super("Must initialize a path by calling RG.beginGroup(), RG.beginShape() or RG.beginPath() first.");
super("Must initialize a path by calling RG.beginShape() or RG.beginPath() first.");
}
}

Expand Down Expand Up @@ -270,6 +270,18 @@ protected static PApplet parent(){
public static RShape diff(RShape a, RShape b){
return a.diff(b);
}

public static RShape union(RShape a, RShape b){
return a.union(b);
}

public static RShape intersection(RShape a, RShape b){
return a.intersection(b);
}

public static RShape xor(RShape a, RShape b){
return a.xor(b);
}


public static void ignoreStyles(){
Expand Down
35 changes: 31 additions & 4 deletions src/geomerative/RShape.java
Expand Up @@ -436,7 +436,11 @@ public RShape toShape(){
* @related diff ( )
*/
public RShape intersection( RShape p ){
return RClip.intersection( p.toPolygon(), this.toPolygon() ).toShape();
RPolygon result = RClip.intersection( p.toPolygon(), this.toPolygon() );

if (result == null) return null;

return result.toShape();
}

/**
Expand All @@ -449,7 +453,11 @@ public RShape intersection( RShape p ){
* @related diff ( )
*/
public RShape union( RShape p ){
return RClip.union( p.toPolygon(), this.toPolygon() ).toShape();
RPolygon result = RClip.union( p.toPolygon(), this.toPolygon() );

if (result == null) return null;

return result.toShape();
}

/**
Expand All @@ -462,7 +470,12 @@ public RShape union( RShape p ){
* @related diff ( )
*/
public RShape xor( RShape p ){
return RClip.xor( p.toPolygon(), this.toPolygon() ).toShape();
RPolygon result = RClip.xor( p.toPolygon(), this.toPolygon() );

if (result == null) return null;

return result.toShape();

}

/**
Expand All @@ -475,7 +488,11 @@ public RShape xor( RShape p ){
* @related intersection ( )
*/
public RShape diff( RShape p ){
return RClip.diff( this.toPolygon(), p.toPolygon() ).toShape();
RPolygon result = RClip.diff( p.toPolygon(), this.toPolygon() );

if (result == null) return null;

return result.toShape();
}

/**
Expand Down Expand Up @@ -600,6 +617,16 @@ public RPoint getTangent(float t){
}
}

/**
* Use this to return a specific tangent on the curve. It returns true if the point passed as a parameter is inside the shape. Implementation taken from: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
* @param float x, the X coordinate of the point for which to test containement.
* @param float y, the Y coordinate of the point for which to test containement.
* @return bool, true if the point is in the path.
* */
public boolean contains(float x, float y){
return contains(new RPoint(x, y));
}

/**
* Use this to return a specific tangent on the curve. It returns true if the point passed as a parameter is inside the shape. Implementation taken from: http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
* @param RPoint p, the point for which to test containement..
Expand Down

0 comments on commit 56f502f

Please sign in to comment.