Last active
October 28, 2018 19:01
-
-
Save monkstone/ff22d8725ee03bf8cd4a2638ab0bfb5f to your computer and use it in GitHub Desktop.
RShape and Boundary
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; | |
} | |
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); | |
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