Last active
October 29, 2018 06:47
-
-
Save monkstone/44aa5ae72d8305d97d990f94b506cdf3 to your computer and use it in GitHub Desktop.
Boundary from RShape
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import geomerative.RPoint; | |
import geomerative.RShape; | |
public class Boundary extends RShape { | |
static Boundary createBoundingRectangle(float x, float y, float w, float h) { | |
Boundary rect = new Boundary(); | |
rect.addMoveTo(x, y); | |
rect.addLineTo(x + w, y); | |
rect.addLineTo(x + w, y + h); | |
rect.addLineTo(x, y + h); | |
rect.addLineTo(x, y); | |
return rect; | |
} | |
static Boundary createBoundingShape(RShape shp) { | |
return new Boundary(shp); | |
} | |
private Boundary() { | |
super(); | |
} | |
private Boundary(RShape shp) { | |
super(shp); | |
} | |
public boolean inside(RShape shp) { | |
RPoint[] pts = shp.getPoints(); | |
for (RPoint pt : pts) { | |
if (!this.contains(pt)) { | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.core.*; | |
import geomerative.*; | |
public class BoundaryTest extends PApplet { | |
Boundary bounds; | |
RShape my_rect; | |
public void setup() { | |
RG.init(this); | |
RG.setPolygonizer(RG.ADAPTATIVE); | |
RShape circle = RShape.createCircle(100, 100, 100); | |
RShape rectangle = RShape.createRectangle(100, 100, 100, 50); | |
bounds = Boundary.createBoundingShape(circle.union(rectangle)); | |
} | |
public void draw() { | |
fill(255); | |
stroke(0); | |
my_rect = RShape.createRectangle(mouseX, mouseY, 10, 10); | |
bounds.draw(); | |
drawMyRect(bounds.inside(my_rect)); | |
} | |
public void drawMyRect(boolean inside) { | |
if (inside) { | |
noStroke(); | |
fill(255, 0, 0); | |
} else { | |
stroke(0); | |
fill(255); | |
} | |
my_rect.draw(this); | |
} | |
public void settings() { | |
size(600, 600, P2D); | |
} | |
static public void main(String[] passedArgs) { | |
String[] appletArgs = new String[]{"BoundaryTest"}; | |
if (passedArgs != null) { | |
PApplet.main(concat(appletArgs, passedArgs)); | |
} else { | |
PApplet.main(appletArgs); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment