From: Ian Jackson Date: Thu, 4 Feb 2016 17:54:39 +0000 (+0000) Subject: commitid.scad.pl: wip, before remove simplification X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-play.git;a=commitdiff_plain;h=5c7ecbf56066a938bdb4635ef274af12d8ca788b commitid.scad.pl: wip, before remove simplification --- diff --git a/commitid.scad.pl b/commitid.scad.pl new file mode 100755 index 0000000..e1caf36 --- /dev/null +++ b/commitid.scad.pl @@ -0,0 +1,139 @@ +#!/usr/bin/perl -w +use strict; + +$SIG{__WARN__} = sub { die @_; }; + +# We generate a physical indication of which commit was used. +# +# We can generate three forms: +# +# Tiny3: +# Tiny4: +# Tiny5: +# Tiny6: +# Tiny7: +# Tiny8: +# git rev-list --first-parent --count HEAD +# typically 3-4 characters but we allow for up to 6 +# eg +# Tiny4 1070 +# +# Tiny4Q: +# Tiny6Q: +# Tiny9Q: +# same but in two lines eg +# Tiny4Q 10 +# 70 +# +# Small4 +# Small6 +# Small8 +# git-rev-list --first-parent --count HEAD +# git-rev-parse HEAD +# eg +# Small6 1070 +# 82f2a2 + +sub parsefont () { + my %cellmap; + while () { + last if %cellmap && !m/\S/; + next unless m/\S/; + chomp; + s{^(.) }{}; + $cellmap{$1} = $_; + } + my %chrpolys; + while () { + next unless m/\S/; + my @chrs = split / /, $_; + !~ m/\S/ or die; + foreach my $row (0..4) { + $_ = ; + chomp; + s{^}{ }; + $_ .= ' ' x (@chrs * 4); + m{\S/\S} and die; + s{/(?=\s)}{L}g; + s{/(?=\S)}{r}g; + s{\\(?=\s)}{l}g; + s{\\(?=\S)}{R}g; + foreach my $chr (@chrs) { + s{^ }{} or die "$chr $_ ?"; + foreach my $col (0..2) { + my @verts; + if (s{^ }{}) { + } elsif (s{^\S}{}) { + my $f = $cellmap{$&}; + die unless $f; + $f =~ s/\b\d/ sprintf '%x', $col*2 + $& /ge; + $f =~ s/\d\b/ sprintf '%x', $row*2 + $& /ge; + push @{ $chrpolys{$chr} }, [ split / /, $f ]; + } else { + die "$_ ?"; + } + } + } + die "$_ ?" if m{\S}; + } + } + foreach my $polys (values %chrpolys) { + my %edges; + foreach my $p (@$polys) { + foreach my $ei (0..$#$p) { + my $e = $p->[$ei].$p->[($ei+1) % @$p]; + die if $edges{$e}; + $edges{$e} = [ $p, $ei ]; + } + } + AGAIN: { + foreach my $pa (@$polys) { + foreach my $eai (0..$#$pa) { + my $ear = $pa->[ ($eai+1) % @$pa ].$pa->[$eai]; + my $ebi = $edges{$ear}; + next unless $ebi; + my $pb; + ($pb, $ebi) = @$ebi; +# print "# merging $eai $ebi\n"; + splice @$pb, $ebi, 1; + splice @$pa, $eai, 1, @$pb; + @$pb = ( ); + next AGAIN; + } + } + } +# @$polys = grep { @$_ } @$polys; + } + + use Data::Dumper; + print Dumper(\%chrpolys); +} + +parsefont(); + +__DATA__ + +# 00 20 22 02 +l 00 20 22 +r 00 20 02 +L 00 22 02 +R 20 22 02 +> 00 20 22 02 11 +< 00 20 11 22 02 + +0 1 2 3 4 5 6 7 8 9 + +/#\ # ##\ ##\ # # ### /## ### /#\ /#\ +# # # # # # # # # # # # # # +# # # /#/ ### ### ##\ ##\ // >#< \## +# # # # # # # # # # # # # +\#/ # ### ##/ # ##/ \#/ # \#/ ##/ + +a b c d e f + + # # /## +/## ##\ /## /## /## # +# # # # # # # # # ### +# # # # # # # #/ # +\## ##/ \## \## ### # +