2017-09-12 5 views
-1
int currentPoint = 2; 
    int direction = 1; 
    PVector copyOf(PVector p){ 
     return new PVector(p.x, p.y); 
    } 

    void addPoint() { 

     hull.add(points.get(currentPoint)); 

    // look at the turn direction in the last three points 
    // (we have to work with copies of the 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 is <= 0, then remove the middle point 
    // if crossproduct is >= 0, do nothing because we have add the 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 the console 
     println("currentPoint: " + currentPoint + " numPoints: " + points.size() + " hullSize: " + hull.size()+" direction:"+direction); 
     if (currentPoint == points.size() -1 || currentPoint == 0) { 
    //when direction = 1, it's a traversal of all points with O(n) 
    //when direction = -1, the construction of convex hull began which is O(nlogn) 
      direction = direction * -1; 
      if (currentPoint == 0){ 
    /****add code here*****/ 
      } 
     } 

     currentPoint+= direction; 
    } 

코드없이 명확하게 제 질문을 설명하기가 어렵습니다. currentPoint = 0 일 때 addpoint() 함수를 종료 할 수 있도록 몇 가지 코드를 추가하고 싶습니다. exit()가 작동하지 않습니다. 프로그램 전체가 종료되고 이미 재생 된 애니메이션이 사라지기 때문입니다. 나는 그것에 대한 좋은 해결책을 생각할 수 없다. 그것에 대해 누구나 아이디어를 가지고 있는가?processing3을 사용하여 볼록한 선체 프로젝트를 만들고 있는데, 어쨌든 함수 (전체 프로그램이 아님)를 종료 할 수 있는지 누군가가 말해 줄 수 있습니까?

+0

추가 할'반환,'상기 보지 않고 (작동된다 ..that 나머지 구현). – nullpointer

+0

more info http://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html – nullpointer

+1

앞으로는 전체 프로그램 대신 [mcve]를 게시하십시오. 간단한 프로그램은 디버그하는 것이 훨씬 쉽습니다. 또한 올바른 형식을 사용하십시오. 코드를 읽기가 매우 어렵습니다. –

답변

1

:

키워드 return은 따라서에 프로그램을 허용하지 않는, 함수의 탈옥하기 위해 사용될 수있다 나머지 진술. 따라서 귀하의 경우

void draw() { 
    background(204); 
    line(0, 0, width, height); 
    if (mousePressed) { 
    return; // Break out of draw(), skipping the line statement below 
    } 
    line(0, height, width, 0); // Executed only if mouse is not pressed 
} 

는 :

나는 현재 점 = 0, 그것은 addpoint() 함수를 종료 할 때 수 있도록 몇 가지 코드를 추가합니다.

if(currentPoint == 0){ 
    return; 
} 

다시 발걸음을 내 디뎌, 당신은 정말 어떤 연구를하고하는 습관을 얻어야한다. "자바 기능을 종료"의 빠른 구글 검색을 포함하여, 결과의 무리를 반환