Page 1 of 1

about NormalizeBreakPoints -talk about a bug

PostPosted: August 7th, 2008, 6:39 am
by liu8670
I think LastAngle:=Angle; must be added

Code: Select all
function TGraphLink.NormalizeBreakPoints(Options: TLinkNormalizeOptions): Boolean;
var
  I: Integer;
  Neighborhood: Integer;
  LastAngle, Angle, DiffAngle: Double;
begin
  Result := False;
  if (PointCount > 2) and (Options <> []) then
  begin
    BeginUpdate;
    try
      // Delete breakpoints on same point
      if lnoDeleteSamePoint in Options then
      begin
        Neighborhood := NeighborhoodRadius;
        I := 1;
        while I < PointCount do
        begin
          if LineLength(Points[I - 1], Points[I]) <= Neighborhood then
          begin
            if I = PointCount - 1 then
              RemovePoint(I - 1)
            else
              RemovePoint(I);
            Result := True;
          end
          else
            Inc(I);
        end;
      end;
      // Delete breakpoints on a straight line
      if lnoDeleteSameAngle in Options then
      begin
        LastAngle := LineSlopeAngle(Points[0], Points[1]);
        I := 2;
        while I < PointCount do
        begin
          Angle := LineSlopeAngle(Points[I - 1], Points[I]);
          ifDiffAngle:= Abs(Angle - LastAngle) * 180 /PI;//< Pi / 360 must be rewrited
          if  DiffAngle < 1 then
          begin
            if I = PointCount - 1 then
              RemovePoint(I - 1)
            else
              RemovePoint(I);
            Result := True;
          end
          else
            Inc(I);
          LastAngle:=Angle;// I think it is important
        end;
      end;
    finally
      EndUpdate;
    end;
  end;
end;

PostPosted: August 7th, 2008, 11:48 am
by Kambiz
You are right. Thank you.