  procedure FillFromFlatExt(FP: TsgFlatEntity);
  var
    I, vIndex, vCounterLines, vCounterInitPoints, vCounterFinalPoints: Integer;
    P, P0, vPixel: TPoint;
    PF, PFNew, PFOld: TFPoint;
    vIsMissedVertex: Boolean;


      procedure AddPoint(APoint: TPoint);
      begin
        FPoly.Add(APoint.X);
        FPoly.Add(APoint.Y);
        Inc(vCounterFinalPoints);
      end;

      procedure AddPointF;
      begin
        PF := PFNew;
        P := GetPoint(PF);
        AddPoint(P);
        if not IsDisableSnapMatrix then
          SetPixelSnapEx(PF, P, [osEndPt]);
      end;

      procedure AddPoly;
      begin
        FCounts.Add(vCounterFinalPoints);
        AddLastPixelToPoly(FPoly, FCounts);
        vCounterFinalPoints := 0;
      end;

   begin
    if FPoly.Capacity < FP.Points.Count then
      FPoly.Capacity := FP.Points.Count;
    FPoly.Count := 0;
    vCounterInitPoints := 0;     //evg
    vCounterFinalPoints := 0;
    vCounterLines := 0;
    vPixel.X := MaxInt;
    vPixel.Y := MaxInt;
    //evg packing
    if FP.PCount > 0 then
    begin
      PF := FP.XY[0];
      PFNew := PF;
      AddPointF;
      Inc(vCounterInitPoints);
    end;
    vIsMissedVertex := False;
    for I := 1 to FP.PCount - 1 do
    begin
     vIndex := I + I;
     PFNew.X := Single(FP.Points[vIndex]);
     PFNew.Y := Single(FP.Points[vIndex + 1]);
     PFNew.Z := 0;
     if (Abs(PFNew.X - PF.X) > vdX)
       or (Abs(PFNew.Y - PF.Y) > vdY) then
     begin
        if vIsMissedVertex then   // add last missed point if it is really should be in other pixel than the last added-pixel. the same is in DrawPointsListByPolyline()
        begin
          P0 := GetPoint(PFOld);
          if not IsEqualPoints(P, P0) then
            AddPoint(P0);
        end;
       if vCounterInitPoints > 0 then // add additional points to current poly
         AddPointF
       else // current point is from another poly, check for merging
         begin
           if (vCounterFinalPoints = 1) and (FPenWidth > 1) then // point
           begin
             AddPoint(P);
           end;
           AddPoly;
           AddPointF;
         end;
       vIsMissedVertex := False;
     end
     else
     begin
       vIsMissedVertex := True;
       PFOld := PFNew;
     end;
      Inc(vCounterInitPoints);
      if vCounterInitPoints = Integer(FP.Counts[vCounterLines]) then
      begin
      vCounterInitPoints := 0;
      Inc(vCounterLines);
      end;
    end;
    if (vCounterFinalPoints = 1) and (FPenWidth > 1) then // point
      AddPoint(P);
    AddPoly;
  end;
