From 93a592f37d9f5f98ed71588df3143db69d6855dc Mon Sep 17 00:00:00 2001 From: Thomas Kremer <-> Date: Wed, 28 Sep 2022 06:38:36 +0200 Subject: DXF.pm: fixed lwpolyline->line conversion for closed polylines. --- DXF.pm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/DXF.pm b/DXF.pm index 259db8a..23eef35 100644 --- a/DXF.pm +++ b/DXF.pm @@ -826,7 +826,7 @@ sub colorize_dxf { # 2*(b*m-a)*l + 2*(b*m-a)*x*(1-c) - 2*x*l - 2*x^2*(1-c) + l^2*m + 2*l*x*m = 0 # -2*(1-c)*x^2 + 2*((b*m-a)*(1-c) + l*(m-1))*x + (2*b*m+l*m-2*a)*l = 0 -# TODO: code 70: open and closed splines and polylines. +# DONE: code 70: open and closed splines and polylines. # dest => source => sub{} my %replacers = ( LWPOLYLINE => { @@ -951,8 +951,18 @@ my %replacers = ( my $node = shift; my @x = @{$node->{attrs}{x}}; my @y = @{$node->{attrs}{y}}; - die "invalid polyline" - unless @x == @y && @x >= 1; + my $flags = $node->{attrs}{int}//0; + my $closed = $flags & 1; + die "invalid lwpolyline" + unless @x == @y; + if (@x == 0) { + warn "empty lwpolyline"; + return (); + } + if ($closed) { + push @x,$x[0]; + push @y,$y[0]; + } my @lines = map lol(LINE => {x => $x[$_], y => $y[$_], x1 => $x[$_+1], y1 => $y[$_+1] }), 0..$#x-1; return @lines; -- cgit v1.2.3