java - I'm working on a convex hull project using processing3, could somebody tell me if there's anyway to quit a function (not the whole program)? -
int currentpoint = 2; int direction = 1; pvector copyof(pvector p){ return new pvector(p.x, p.y); } void addpoint() { hull.add(points.get(currentpoint)); // @ turn direction in last 3 points // (we have work copies of points because java) p1 = copyof(hull.get(hull.size() - 3)); p2 = copyof(hull.get(hull.size() - 2)); p3 = copyof(hull.get(hull.size() - 1)); while (!crossprod (p1, p2, p3) && hull.size() > 2) { // if crossproduct <= 0, remove middle point // if crossproduct >= 0, nothing because have add point before hull.remove(hull.size() - 2); if (hull.size() >= 3) { //in case of null pointer error p1 = copyof(hull.get(hull.size() - 3)); } p2 = copyof(hull.get(hull.size() - 2)); p3 = copyof(hull.get(hull.size() - 1)); } //you'll see information in console println("currentpoint: " + currentpoint + " numpoints: " + points.size() + " hullsize: " + hull.size()+" direction:"+direction); if (currentpoint == points.size() -1 || currentpoint == 0) { //when direction = 1, it's traversal of points o(n) //when direction = -1, construction of convex hull began o(nlogn) direction = direction * -1; if (currentpoint == 0){ /****add code here*****/ } } currentpoint+= direction; }
it's quite hard explain question without code. want add code when currentpoint = 0
, quit addpoint()
function. exit()
won't work, quit whole program , animation played disappear. can't think solution that, has ideas that?
from the reference:
the keyword
return
may used break out of function, not allowing program remaining statements.void draw() { background(204); line(0, 0, width, height); if (mousepressed) { return; // break out of draw(), skipping line statement below } line(0, height, width, 0); // executed if mouse not pressed }
so in case:
i want add code when currentpoint = 0, quit addpoint() function.
if(currentpoint == 0){ return; }
taking step back, should habit of doing research. quick google search of "java quit function" returns bunch of results, including:
Comments
Post a Comment