Darstellungsprobleme mit Polygonen



  • Hi,
    hab keine Zeit, deswegen äußere mich kurz.
    Kann mir jemand sagen warum das hier nicht richtig angezeigt wird:

    TPoint points[] = { Point(10,10), Point(40,10), Point(10,40) };
    Canvas->Polygon( points, sizeof(points) / sizeof(points[0]) );
    

    und das auch nicht:

    TPoint points[3];
    points[0].x = 10; points[0].y = 10;
    points[1].x = 40; points[1].y = 10;
    points[2].x = 10; points[2].x = 40;
    Canvas->Polygon( points, sizeof(points) / sizeof(points[0]) );
    

    das aber schon:

    TPoint points[] = { Point(10,10), Point(40,10), Point(10,40) };
    Canvas->Polygon( points, sizeof(points) / sizeof(points[0]) -1 );
    

    und das auch:

    TPoint points[3];
    points[0] = Point(10,10);
    points[1] = Point(40,10);
    points[2] = Point(10,40);
    Canvas->Polygon( points, sizeof(points) / sizeof(points[0]) );
    

    ich versteh es einfach nicht. 😕



  • Ich hab mal ein wenig rumprobiert. Also
    1. muss die Anzahl der Punkte (2. Parameter) einen runtergeschraubt werden. Du hast 3 Punkte, also muss da 2 hin.
    2. hast du in deinem 2. Beispiel einmal x statt y geschrieben
    3. Geht dein 4. Beispiel ebenfalls nicht!



  • WebFritzi schrieb:

    muss die Anzahl der Punkte (2. Parameter) einen runtergeschraubt werden. Du hast 3 Punkte, also muss da 2 hin.

    das heißt also, dass ich nicht die anzahl der Punkte, sondern den letzten Index
    nehmen soll. Verstehe erst jetzt.

    hast du in deinem 2. Beispiel einmal x statt y geschrieben

    ist ein Tippfehler von mir, aber wenn es sogar richtig geschrieben ist, funktioniert es nicht. Mit dem Index funkts.

    Geht dein 4. Beispiel ebenfalls nicht!

    Also, bei mir geht es. Das ist auch das verwirrende daran. Poste nochmal vielleicht habe ich wieder einen Tippfehler übersehen

    TPoint points[3];
    points[0] = Point(10,10);
    points[1] = Point(40,10);
    points[2] = Point(10,40);
    Canvas->Polygon( points, sizeof(points) / sizeof(points[0]) );
    


  • Hab das direkt kopiert - und es geht nicht!



  • stimmt, geht nicht. Aber so:

    TPoint points[3];
    points[0] = Point(10,10);
    points[1] = Point(40,10);
    points[2] = Point(10,40);
    Canvas->Polygon( points, sizeof(points) / sizeof(points[0])-1 );
    

    Kann es sein, dass du in deiner Version das -1 schon eingetippt hast, wie oben, bIce???



  • Hab auch einfach kopiert und es geht. Ziemlich seltsam. Vielleicht liegt es aber am Betriebssystem (Win98) oder am Bibliotheken, bzw. Compiler (BCB 5 Standard).

    Poste nochmal, diesmal aber den Inhalt der gesamten Unit1.cpp:

    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    #pragma hdrstop
    
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
       : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    
    void __fastcall TForm1::FormPaint(TObject *Sender)
    {
       TPoint points[3]; 
       points[0] = Point(10,10); 
       points[1] = Point(40,10); 
       points[2] = Point(10,40); 
       Canvas->Polygon( points, sizeof(points) / sizeof(points[0]) );
    
    }
    //---------------------------------------------------------------------------
    


  • Sogar wenn ich statt

    Canvas->Polygon( points, sizeof(points) / sizeof(points[0]) );
    

    das hier schreibe funktioniert es

    Canvas->Polygon( points, 3 );
    

    aber auch wenn da eine 2 steht geht es

    Canvas->Polygon( points, 2);
    

    wie es eigentlich auch sein sollte



  • Komisch... bei mir geht's nur mit 2. 😕



  • Ich ließ gerade mit

    int x = StrToInt(Edit1->Text);
    TPoint points[3];
    points[0] = Point(10,10);
    points[1] = Point(40,10);
    points[2] = Point(10,40);
    Caption = sizeof(points) / sizeof(points[0]);
    Canvas->Polygon( points, 2 );
    
    char* str = new char[sizeof(points) + x + 1];
    memcpy(str, points, sizeof(points) + x);
    str[sizeof(points) + x] = 0;
    
    AnsiString out;
    for (int i=0; i< sizeof(points) + x; i++){
       AppendStr(out, IntToStr((int)str[i]) + " " );
    }
    Memo1->Text = out;
    delete [] str;
    

    den Speicher ausgeben + 10 folgende Bytes, kam das heraus:

    10  0  0 0 
    10  0  0 0 
    40  0  0 0 
    10  0  0 0 
    10  0  0 0 
    40  0  0 0 
     4 10 67 1 
    72 89 25 1 
    10  0
    

    vielleicht kannst Du daran etwas erkennen? Auf 4 Zeichen pro Zeile hab ich per Hand formatiert.



  • Bei mir kam bis zum letzten 40,0,0,0 (also inklusive) das gleiche raus.



  • Sogar mit dem WinApi-Typ POINT funktioniert es bei mir.
    Wollte auch mit der Polygon() probieren, aber sie erwartet sowieso die Anzahl der Elemente.



  • Hab jetzt im Quelltext der VCL nachgeschaut, sieht folgendermaßen aus:

    procedure TCanvas.Polygon(const Points: array of TPoint);
    begin
      ...
      Windows.Polygon(FHandle, PPoints(@Points)^, High(Points) + 1);
      ...
    end;
    

    in Delphi sieht es so aus. Das hilft aber ebenfalls nicht weiter, denn wie man sieht gibt es hier garnicht das Argument für den letzten Index, dieser wird mit Hilfe der High()-Funktion ermittelt.


Anmelden zum Antworten