Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Working Magically - dont look at source code ;)
  • Loading branch information
JimmyBoivie authored and JimmyBoivie committed Dec 8, 2015
1 parent 1c3f30b commit c8a8171
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 15 deletions.
45 changes: 40 additions & 5 deletions main/Face.pde
Expand Up @@ -9,17 +9,52 @@ public class Face {
innerComponents = CompGeo.findFriends(outerComponent, points);
}

public void daColoring(int r, int g, int b, PointList pl, float x, float y) {
Point p = null;
stroke(r,g,b);
for (int i = 0; i < (int)x; i++) {
for (int j = 0; j < (int)y; j++) {
p = new Point(i, j);
if (inSpecificFace(p, pl)) {
point(i,j);
System.out.println(p);
}
}
}
stroke(0);
}

public boolean inSpecificFace(Point a, PointList pl) {
if ((outerComponent == null) || (CompGeo.inside(outerComponent, a, pl.getFar()))) {
System.out.println(a);
int num = innerComponents.size();
for (int i = 0; i < num; i++) {
if (inAnInner(innerComponents.get(i), a, pl)) {
return false;
}
}
return true;
}
return false;
}

public boolean inAnInner(HalfEdge inner, Point a, PointList pl) {
if (CompGeo.signedArea(inner) == 0) { return false; }
if (CompGeo.inside(inner, a, pl.getFar())) { return true; }
return false;
}

public void printFace() {
//System.out.println("Outer Face:");
System.out.println("Outer Face:");
if (outerComponent != null) { outerComponent.printRNext(); }
//System.out.println();
//System.out.println("Inner Components:");
System.out.println();
System.out.println("Inner Components:");
int num = innerComponents.size();
for (int i = 0; i < num; i++) {
//System.out.println("COMPONENT[" + i + "]");
System.out.println("COMPONENT[" + i + "]");
innerComponents.get(i).printRNext();
}
//System.out.println();
System.out.println();
}

}
12 changes: 6 additions & 6 deletions main/HalfEdge.pde
Expand Up @@ -18,7 +18,7 @@ public class HalfEdge {
p.setRef(null);
q.setRef(null);
state = 0;
console.log("CLASS0");
//console.log("CLASS0");
} else if (p.count() == 1) {
p.setRef(null);
q.setRef(twin.getAnotherLeaving());
Expand All @@ -27,7 +27,7 @@ public class HalfEdge {
// NOTHING SPECIAL MUST BE DONE
// Make Sure face is not represented by dissapearing edge
state = 1;
console.log("CLASS1A");
//console.log("CLASS1A");
} else if (q.count() == 1) {
p.setRef(this.getAnotherLeaving());
q.setRef(null);
Expand All @@ -36,7 +36,7 @@ public class HalfEdge {
// NOTHING SPECIAL MUST BE DONE
// Make sure face is not represented by dissapearing edge
state = 1;
console.log("CLASS1B");
//console.log("CLASS1B");
} else {
int expected = p.count() - 2;
p.setRef(this.getAnotherLeaving());
Expand All @@ -45,7 +45,7 @@ public class HalfEdge {
twin.getprevious().setnext(this.getnext());
this.getprevious().setnext(twin.getnext());
twin.getnext().setprevious(this.getprevious());
console.log("CLASS23");
//console.log("CLASS23");
if (p.count() == expected) {
// was not broken faces merge!
//
Expand Down Expand Up @@ -371,10 +371,10 @@ public class HalfEdge {
}

public void printRNext() {
////System.out.println(" " + origin);
System.out.println(" " + origin);
HalfEdge temp = next;
while (temp != this) {
//System.out.println(" " + temp.getOrigin());
System.out.println(" " + temp.getOrigin());
temp = temp.getnext();
}
}
Expand Down
4 changes: 3 additions & 1 deletion main/PointList.pde
Expand Up @@ -52,10 +52,12 @@ public class PointList {
}

public HalfEdge getHalfEdge(Point p, Point q) {
System.out.println(p);
System.out.println(q);
int num = points.size();
int id = -1;
for (int i = 0; i < num; i++) {
if (p.equals(points.get(i))) {
if (p == points.get(i)) {
id = i;
}
}
Expand Down
49 changes: 46 additions & 3 deletions main/main.pde
Expand Up @@ -6,12 +6,13 @@ PointList list = new PointList();
DrawHalfEdge drawgraph = new DrawHalfEdge();
boolean removeEdge = false;
Point removeEdgePoint;

boolean colorEdge = false;
Point colorEdgePoint;
int colorFaceColor = 0;

public void setup() {
size(800, 500);
background(255);
fill(0,0);
translate(width/2, height/2);
/*Point p1 = new Point(300, 300);
list.addPoint(p1);
Expand Down Expand Up @@ -92,7 +93,7 @@ public void setup() {
//(new Face(h12, list)).printFace();
}
void draw() {
background(255);
//background(255);
drawgraph.drawGraph(list.getPoints());
}
void keyPressed() {
Expand Down Expand Up @@ -131,7 +132,47 @@ void mouseReleased() {
case 2:
removeEdgeMode(x,y);
break;
case 4:
colorFace(x, y);
colorFaceColor = 0;
break;
case 5:
colorFace(x,y);
colorFaceColor = 1;
break;
}
}
public void colorFace(float x, float y) {
if(colorEdge) {
for(Point p: list.getPoints()) {
if((p.getX() - 10 < x) && (p.getX() + 10 > x)) {
if((p.getY() - 10 < y) && (p.getY() + 10 > y)) {
HalfEdge h = list.getHalfEdge(colorEdgePoint, p);
if(h != null) {
System.out.println("h is not null");
Face f = new Face(h, list);
f.printFace();
if(colorFaceColor == 0) {
f.daColoring(0,0,255,list, width, height);
} else if(colorFaceColor ==1) {
f.daColoring(0,255,0,list, width, height);
}
}
}
}
}
colorEdge = false;
} else {
for(Point p: list.getPoints()) {
if((p.getX() - 10 < x) && (p.getX() + 10 > x)) {
if((p.getY() - 10 < y) && (p.getY() + 10 > y)) {
colorEdgePoint = p;
colorEdge = true;
}
}
}
}
noFill();
}
public void insertMode(float x, float y) {
if(pointclickedbool) {
Expand Down Expand Up @@ -180,6 +221,7 @@ public void removePointMode(float x, float y) {
}
if(removePoint) {
list.removePoint(removeThis);
background(255);
}
}

Expand All @@ -191,6 +233,7 @@ public void removeEdgeMode(float x, float y) {
HalfEdge h = list.getHalfEdge(removeEdgePoint, p);
if(h != null) {
h.Remove();
background(255);
}
removeEdge = false;
}
Expand Down

0 comments on commit c8a8171

Please sign in to comment.