Rekursiv void-Methode?

Ich habe ein problem mit meinem Programm (mein Programmiersprache ist java) :
Ich habe ein Objekt Douglas-Peucker ist ein array von Punkten, und ich habe einen Algorithmus der Douglas-Peucker-Algorithmus. Ich möchte nach der Arbeit direkt auf dieses array von Punkten und hier das problem beginnt. Dies ist der Douglas-Peucker-Algorithmus :

protected Point[] coinImage;

//Mein Konstruktor

public Peucker(Point [] tab) {
    coinImage = new Point[tab.length];
    for(int i = 0; i < coinImage.length; i++) {
        coinImage[i] = new Point(tab[i].x, tab[i].y);
    }
}
public Point[] algoDouglasPeucker() {
    return douglasPeuckerAux(0,coinImage.length - 1);
}

public Point[] douglasPeuckerAux(int startIndex, int endIndex) {
    double dmax = 0;
    int index = 0;
    for(int i  = startIndex + 1; i < endIndex; i++) {
        double distance = this.distancePointSegment(this.coinImage[i], this.coinImage[startIndex], this.coinImage[endIndex]);
        if(distance > dmax) {
            index = i;
            dmax = distance;
        }
    } ***
    if(dmax >= this.epsilon) {
        Point[] recResult1 = douglasPeuckerAux(startIndex,index);
        Point[] recResult2 = douglasPeuckerAux(index,endIndex);
        Point [] result = this.unionTabPoint(recResult1, recResult2);
        return result;
    }
    else {
        return new Point[] { coinImage[0],coinImage[endIndex] };
        }
} 

*** my problem is here : both methods have a specific type of return : array of Point or I want to change this because I want to work directly on my attribut (coinImage).

Wie dies auch in void-Methoden ?
Helfen Sie mir bitte !
Sorry, habe ich vergessen eine Methode : ich will mich auch ändern, geben Sie dieser Methode :

    public Point[] unionTabPoint(Point [] P1,Point [] P2) {
    Point[] res = new Point[P1.length + P2.length];
    for(int i = 0; i < P1.length;i++) {
        res[i] = new Point(P1[i].x,P1[i].y);
    }
    int k = 0;
    for(int j = P1.length; j < res.length; j++) {
        res[j] = new Point(P2[k].x,P2[k].y);
        k++;
    }
    return res;
}

Sie zurückkehren, die union der zwei array, aber ohne bestimmte Reihenfolge.

  • Was void-Methode?
  • Ich will zu ändern, die drei Methoden : algoDouglasPeucker,DouglasPeuckerAux und unionTabPoint zu void-Methode. Ich will arbeiten im Objekt -, aber es ist hier nicht der Fall. Aber Wie ändern Sie die drei Methoden in der leere ? Weil man dieses rekursiv...
InformationsquelleAutor afk | 2011-12-09
Schreibe einen Kommentar