Image-Bitmap2Paths
view release on metacpan or search on metacpan
script/in-preparation/convex.pl view on Meta::CPAN
and (not defined $A or abs($A - $L->[0][1]) < 0.0001) and (not defined $B or abs($B - $L->[0][2]) < 0.0001) ;
# @$dirs are for the join-the-centers broken line (1 for 45 degrees, 0 for horizontal)
for my $l (@$L) {
$l->[$_] = 1+sprintf "%.12g", $l->[$_]-1 for 1, 2; # Round also values close to 0
}
print "\\doCase{$P}{$PRE@SIDES$POST}{", (join ', ', map +(join '/', @$_), @$L), "}{$Perp}{$minDir16\\dots $maxDir16} % (@DIRS) [@SIDES] (", !!$addL,", ", !!$addR, ")\n";
print "%\\doSlopes{$SL}{$SLint} %\n" unless @$lines <= 2;
}
sub test_encodes_line_prologue {
<<'EOP';
\documentclass{amsart}
\usepackage[margin=0.4in,landscape,nohead,nofoot]{geometry} % may need a4paper/letterpaper
\usepackage{tikz}
\newcommand\doCase[5]{% 1: points (X/Y) 2: descr 3: lines (A/B/x0/x1/extend_dotted_left_dx/extend_dotted_right_dx) y=A*x+B
\fbox{\tikz[scale=0.3]{% 4: perpendiculars X Y dX dY len
\foreach \X/\Y/\how in {#1} {%
\draw[gray!75,densely dotted] (\X-0.5,\Y-0.5) rectangle ++(1,1);%
\pgfmathsetmacro\DIR{\how<0?-1:1}%
% \pgfmathsetmacro\isVERT{\how==0}%
\ifnum \how=0 %
\fill[blue] (\X,\Y-0.5) circle (0.2em);%
\fill[red] (\X,\Y+0.5) circle (0.2em);%
\else % \how=-1: decreasing; lower bound on the left, upper on the right; 1: opposite
\fill[blue] (\X+\DIR/2,\Y) circle (0.2em);% lower
\fill[red] (\X-\DIR/2,\Y) circle (0.2em);% upper
\fi
}%
\foreach [count=\c] \inv/\A/\B/\x/\X/\pre/\post in {#3} {%
\pgfmathsetmacro\COL{{"orange","purple"}[mod(\c,2)]}%
\pgfmathtruncatemacro\DO{\pre>0}%
\pgfmathtruncatemacro\DOii{\post>0}%
\ifnum \inv=0 %
\draw[\COL] (\x,\x*\A+\B) -- (\X,\X*\A+\B);%
\ifnum \DO > 0 %
\draw[\COL,densely dotted] (\x-\pre,\x*\A-\pre*\A+\B) -- (\x,\x*\A+\B);%
\fi
\ifnum \DOii > 0 %
\draw[\COL,densely dotted] (\X+\post,\X*\A+\post*\A+\B) -- (\X,\X*\A+\B);%
\fi
\else % exchange 1st and 2nd coordinate
\draw[\COL] (\x*\A+\B,\x) -- (\X*\A+\B,\X);%
\ifnum \DO > 0 %
\draw[\COL,densely dotted] (\x*\A-\pre*\A+\B,\x-\pre) -- (\x*\A+\B,\x);%
\fi
\ifnum \DOii > 0 %
\draw[\COL,densely dotted] (\X*\A+\post*\A+\B,\X+\post) -- (\X*\A+\B,\X);%
\fi
\fi
}%
\foreach [count=\c] \x/\y/\dx/\dy/\len/\X/\Y/\i/\XX/\YY in {#4} {%
\pgfmathtruncatemacro\DO{\len<30}%
\ifnum \DO > 0 %
\draw[] (\x,\y) -- ++(\dx,\dy) coordinate (e);%
\fill[] (e) circle (0.28em);% vs thickness of "thick"
\draw[violet,thick] (e) -- (\XX,\YY) coordinate (ee);%
\fill[violet] (ee) circle (0.28em);%
\fi
}%
\node[below left, overlay] at (current bounding box.north east) {#5};%
}}\llap{\small #2 }\hfil}
\newcommand\doSlopes[2]{% points (X/Ymin/Ymax)
{\color{blue}\fbox{\tikz[scale=0.3]{%
\foreach \Z/\ZZ/\slope/\inv in {#2} {%
\draw[gray!66,very thick] (\Z,\slope*5) -- (\ZZ,\slope*5);%
}%
\foreach \Z/\Umin/\Umax in {#1} {%
\fill[blue] (\Z,\Umin*5) circle (0.2em);%
\fill[red] (\Z,\Umax*5) circle (0.2em);%
}%
}}}\hfil}
\begin{document}
\noindent
EOP
}
sub _decode_expectations ($) {
my $in = shift;
return $in, undef unless ref $in;
$in->[0], $in->[1]
}
# Encoding: numbers>=0 --> adjacent "horizontal" runs of this many tiles (1 level above the previous reference height, and change
# this height); [N]: rotate whatever "increments" follow N * 90 degrees clockwise; numbers<0: change the reference height so that
# the next run of tiles is that much below the preceding one.
sub _test_encodes_lines($$$$) { # Need to check incredible amount of branches...
my($how, $rot, $maxDx, $maxRoAng) = (shift, shift, shift, shift);
print test_encodes_line_prologue;
# Actually, the slopes below are for the old algorithm; the new one gives slightly different fits.
my @exp;
(@exp = _decode_expectations $_->[0]), test_encodes_line($rot, $exp[0], $exp[1], $_->[1], $_->[2], $_->[3], $how, $maxDx, $maxRoAng)
# for [undef, [7, 5], 0, 1]; 0
# for [undef, [3,3,4,4,3], 1]; 0
# for [[1, 0], [1,1]]; 0
# for [undef, [1,3,1,1,3,1]]; 0
# for [3, [3], 0, 1]; 0
# for [undef, [7, 9], 1, 1]; 0
# for [undef, [7, 9], 1]; 0
# for [undef, [9, 7], 1, 1]; 0
# for [undef, [1,1,1,2,2,2,5], 1]; 0
# for [1, [1,1]]; 0
# for [undef, [4,4,4,3,3], 0, 1], ; 0
# for [undef, [1,-2,1,-1,1,-1,2,-1,5,2,1,1,0,1]], [undef, [[1], 1,[],1,[-1],-1,1,-1,2,-1,5,2,1,1,0,1]], ; 0
# for [undef, [[1], 2,1]], ; 0
# for [undef, [[1], 1, 2,1]], ; 0
# for [undef, [[1], 1,2]], [undef, [[1], 1,2,1]], [undef, [[1], 1,2,1,1]], ; 0
# for [undef, [[1], 1,2, [-1], -1,1,-1,2,-1,5,2,1,1,0,1]], ; 0
# for [undef, [[1], 1,2, [-1], -1,1,-1,2,-1, 5]], ; 0
# for [undef, [[1], 1,2, [-1], -1,1,-1,2]], ; 0
# for [undef, [[1], 1,2, [-1], -1,1,-1,2,-1,5,2,1,[-1],-1,2,-1,1]], ; 0
# for [undef, [[1], 5, 1]], [-1/5, [[1], 5, 2]], ; 0
# for [undef, [[1], 5, 1]], ; 0
# for [-1/5, [[1], 5, 2]], ; 0
for [7, [7], 1, 1], [7, [7], 0, 1],
[7, [7], 1], [undef, [7, 9], 1, 1], [undef, [7,9], 1], [undef, [5,7], 1], [undef, [7, 5], 0, 1],
[9, [7, 9], 0, 1], [9, [7,9]], [5.5, [5,6], 1], [5.5, [6, 5], 0, 1],
( run in 1.469 second using v1.01-cache-2.11-cpan-e1769b4cff6 )