Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added keyboard methods
  • Loading branch information
cor11004 committed Dec 7, 2015
1 parent 462e5c0 commit 0efe435
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
2 changes: 1 addition & 1 deletion main/HalfEdge.pde
Expand Up @@ -346,4 +346,4 @@ public class HalfEdge {
}
}

}
}
5 changes: 3 additions & 2 deletions main/PointList.pde
Expand Up @@ -30,7 +30,8 @@ public class PointList {
}

public boolean removePoint(Point p) {
return points.remove(p);
p.deleteEdges();
return points.remove(p);
}

public ArrayList<HalfEdge> getAllStructures() {
Expand All @@ -50,4 +51,4 @@ public class PointList {
return struct;
}

}
}
51 changes: 49 additions & 2 deletions main/main.pde
@@ -1,5 +1,6 @@
boolean pointclickedbool = false;
boolean linedrawn = false;
int mode = 0;
Point pointclicked;
PointList list = new PointList();
DrawHalfEdge drawgraph = new DrawHalfEdge();
Expand All @@ -10,7 +11,7 @@ public void setup() {
fill(0,0);
translate(width/2, height/2);

/*Point p1 = new Point(0, 0);
Point p1 = new Point(0, 0);
list.addPoint(p1);
Point p2 = new Point(100, 50);
list.addPoint(p2);
Expand Down Expand Up @@ -59,7 +60,7 @@ public void setup() {
HalfEdge h13 = new HalfEdge(p7, p15);
HalfEdge h14 = new HalfEdge(p8, p15);
HalfEdge h15 = new HalfEdge(p9, p15);
HalfEdge h16 = new HalfEdge(p16, p17); */
HalfEdge h16 = new HalfEdge(p16, p17);

//h1.printFace();
//float f = CompGeo.signedArea(h1.gettwin());
Expand Down Expand Up @@ -91,9 +92,39 @@ public void setup() {
void draw() {
drawgraph.drawGraph(list.getPoints());
}
void keyPressed() {
switch (key) {
case 'i':
mode = 0;
break;
case 'r':
mode = 1;
break;
case 'p':
mode = 2;
break;
case 'b':
mode = 3;
break;
case 'g':
mode = 4;
break;
}

}
void mouseReleased() {
float x = mouseX;
float y = mouseY;
switch (mode){
case 0:
insertMode(x,y);
break;
case 1:
removePointMode(x,y);
break;
}
}
public void insertMode(float x, float y) {
if(pointclickedbool) {
pointclickedbool = false;
for(Point p: list.getPoints()) {
Expand Down Expand Up @@ -124,3 +155,19 @@ void mouseReleased() {
}
linedrawn = false;
}

public void removePointMode(float x, float y) {
boolean removePoint= false;
Point removeThis = null;
for(Point p: list.getPoints()) {
if((p.getX() - 10 < x) && (p.getX() + + 10 > x)) {
if((p.getY() - 10 < y) && (p.getY() + 10 > y)) {
removeThis = p;
removePoint = true;
}
}
}
if(removePoint) {
list.removePoint(removeThis);
}
}

0 comments on commit 0efe435

Please sign in to comment.