Skip to content

Instantly share code, notes, and snippets.

@monkstone
Last active October 28, 2018 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monkstone/ff22d8725ee03bf8cd4a2638ab0bfb5f to your computer and use it in GitHub Desktop.
Save monkstone/ff22d8725ee03bf8cd4a2638ab0bfb5f to your computer and use it in GitHub Desktop.
RShape and Boundary
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;
}
public boolean inside(RShape shp) {
RPoint[] pts = shp.getPoints();
for (RPoint pt : pts) {
if (!this.contains(pt)) {
return false;
}
}
return true;
}
}
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);
bounds = Boundary.createBoundingRectangle(100, 100, 100, 50);
}
public void draw() {
fill(255);
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();
}
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