Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoClosedDetect for BuildPolyPolyLine #84

Open
lamdalili opened this issue Jun 6, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@lamdalili
Copy link

commented Jun 6, 2019

BuildPolyPolyLine treats all its elements either opened or closed but there are many situations where both kinds of path are used.
My new implementation for BuildPolyPolyLine :


function BuildPolyPolyLine(const Points: TArrayOfArrayOfFloatPoint;
  Closed: Boolean; StrokeWidth: TFloat; JoinStyle: TJoinStyle;
  EndStyle: TEndStyle; MiterLimit: TFloat;AutoClosedDetect:Boolean=False): TArrayOfArrayOfFloatPoint;
var
  I,Len,Cap,L: Integer;
  P1, P2,t: TArrayOfFloatPoint;
  Dst: TArrayOfArrayOfFloatPoint;
  Normals: TArrayOfFloatPoint;
  t1,t2:TFloatpoint;
  procedure Add(const V:TArrayOfFloatPoint);
  begin
      if Cap=Len then
      begin
         Cap:=Cap+64;
         Setlength(Result,Cap);
      end;
      Result[len]:=v;
      inc(len);
  end;
begin
  Cap:=0;
  Len:=0;
  for I := 0 to High(Points) do
  begin
    t:=Points[I];
    if AutoClosedDetect then
    begin
      L:=Length(t);
      if L<2 then
         continue;
      t1:=t[0];
      t2:=t[L-1];
      Closed:=(t1.X=t2.X)and(t1.Y=t2.Y);
    end;
    if Closed then
    begin
      Normals := BuildNormals(t);
      P1 := Grow(t, Normals, StrokeWidth * 0.5, JoinStyle, True, MiterLimit);
      P2 := Grow(t, Normals, -StrokeWidth * 0.5, JoinStyle, True, MiterLimit);
      Add(P1);
      Add(ReversePolygon(P2));
    end else
         Add(BuildPolyline(t, StrokeWidth, JoinStyle, EndStyle,MiterLimit));
  end;
  Setlength(Result,Len);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.