AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Endlosschleife

Ein Thema von daschaos · begonnen am 7. Aug 2007 · letzter Beitrag vom 7. Aug 2007
 
daschaos

Registriert seit: 23. Mai 2007
117 Beiträge
 
Delphi 2006 Professional
 
#1

Endlosschleife

  Alt 7. Aug 2007, 10:37
Hi!

Ich möchte einen Squarified Treemap - Algorithmus implementieren. Auf meinen kleinen Testdaten hatte alles wunderbar funktioniert, jetzt hab ich mir aber reale Daten von der Festplatte geholt und mein Programm stürzt ab. Nach langem Suchen ist mir aufgefallen, dass irgendwie eine Endlosschleife produziert wird. Und zwar ist ja ein continue im if-Teil von LastAspect>CurrentAspect, das heißt, immer wenn er in den If - Teil reingeht, springt er beim continue aus der Schleife raus und beginnt mit einem neuen Durchlauf. EndIndex, welcher ja bei EndIndex=ChildCount zum Abbruch der Schleife führt, wird aber nur im Else - Teil von LastAspect>CurrentAspect erhöht. Wenn ich jetzt das Continue mal ausklammer, malt er es nich mehr hundertprozentig richtig, er malt das letzte Kind der jeweiligen Verzeichnisebene glaub ich nich mehr, ansonsten stürzt das Programm aber nicht mehr ab, weil EndIndex in jedem Fall erhöht wird. Also liegt es daran, dass EndIndex nich immer erhöht wird und somit manchmal zu einer Endlosschleife führt. Ich bin irgendwie wie so oft anscheinend zu blöd dafür, das Problem behoben zu bekommen, ohne diesen Continue Sprung zu benutzen.

Der Code, in dem der Fehler auftritt:


Delphi-Quellcode:
while (EndIndex <> ChildCount) do
  begin
    // compute aspect ratio with current start- and end index
    LastAspect := SquarifiedTryLayout(StartIndex, EndIndex, Orientation, TempWidth, TempHeight);

    // if the computed aspect ratio is greater than CurrentAspect
    if ((LastAspect > CurrentAspect) or (LastAspect < 1)) then
    begin
      CurrentX := ARect.TopLeft.X;
      CurrentY := ARect.TopLeft.Y;

      // the new calculated aspect is inferior, so codify the calculated coordinates for the starting point of a rectangle
      for i:= StartIndex to EndIndex-1 do
      begin
        SortArray[i].X := OffsetX + CurrentX;
        SortArray[i].Y := OffsetY + CurrentY;

        // set new starting points
        if (Orientation)then
          CurrentY := Single(CurrentY) + Single(SortArray[i].Height)
        else
          CurrentX := Single(CurrentX) + Single(SortArray[i].Width);
      end;//for

      if (Orientation) then
        OffsetX := Single(OffsetX) + Single(SortArray[StartIndex].Width)
      else
        OffsetY := Single(OffsetY) + Single(SortArray[StartIndex].Height);

      // calculate the leftover size of the width and height of the rectangle
      TempWidth := AWidth - OffsetX;
      TempHeight := AHeight - OffsetY;

      // check, if orientation has changed and you have to draw vertical or horizontal now
      Orientation := DrawingOrientation(TempWidth, TempHeight);
      StartIndex := EndIndex;
      CurrentAspect := 999;
      continue;
    end//if(LastAspect>CurrentAspect)
    else
    begin
      // store the temp measurements
      for i:= StartIndex to EndIndex do
      begin
        SortArray[i].Width := SortArray[i].TempWidth;
        SortArray[i].Height := SortArray[i].TempHeight;
      end;//for

      // store the last aspect for later comparisons
      CurrentAspect := LastAspect;

      end;//else

      // increment index to try to draw another rectangle
      EndIndex := EndIndex + 1;
  end;//while(EndIndex <> ChildCount)
Es wäre ganz ganz toll, wenn jemand eine Idee hätte, wie ich mein Problem lösen könnte! Ich wäre euch auf Lebenszeit dankbar!
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:03 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz