From: Ian Jackson Date: Fri, 5 Feb 2016 21:24:11 +0000 (+0000) Subject: commitid: Best, initial sort-of-working implementation X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=reprap-play.git;a=commitdiff_plain;h=f4947ad0fe16b78696616f4e851f9c232d402a92 commitid: Best, initial sort-of-working implementation --- diff --git a/.gitignore b/.gitignore index a494673..d0a75d2 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ question-question.dxf question-question.eps lemon-stand.scad commitid.scad +commitid-best-test.scad diff --git a/commitid-best-test.scad.pl b/commitid-best-test.scad.pl new file mode 100755 index 0000000..73cfd8f --- /dev/null +++ b/commitid-best-test.scad.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl -w +use strict; + +our @xm = qw(4.7 6.8 10 15 22 33 47 68 100); +our @ym = qw(3.9 5.6 8.2 12 18 27 39 56); + +sub p { print @_ or die $!; } + +p "include \n"; +p "p = Commitid_pixelsz();\n"; + +my $x = 0; +foreach my $xm (@xm) { + my $y = 0; + foreach my $ym (@ym) { + p " translate([$x,$y] * p) {\n"; + p " difference(){\n"; + p " translate(-0.5*p*[1,1]) square([$xm+1,$ym+1]*p);\n"; + p " square([$xm,$ym]*p);\n"; + p " }\n"; + p " Commitid_BestCount_2D([$xm,$ym] * p);\n"; + p " }\n"; + $y += $ym + 2; + } + $x += $xm + 2; +} diff --git a/commitid.scad.pl b/commitid.scad.pl index e51318a..7506c62 100755 --- a/commitid.scad.pl +++ b/commitid.scad.pl @@ -34,6 +34,7 @@ $SIG{__WARN__} = sub { die @_; }; # $Commitid_scale if not set, we use 1.0 } together # $Commitid_depth if not set, we use xy pixel size from above / 2 # $Commitid_depth_scale if not set, we use 1.0 (multiplies depth above) +# $Commitid_max_best_scale if not set, we use 2.0 (max mult of xy in Best) # # For each form we have # @@ -377,7 +378,10 @@ sub do_git () { sub do_some_best ($$) { my ($modname, $formre) = @_; - p "module Commitid_$modname(max_sz) {\n"; + my $fullmodname = "Commitid_${modname}_2D"; + p "module $fullmodname(max_sz) {\n"; + p ' sc_max = $Commitid_max_best_scale ? $Commitid_max_best_scale : 2;'."\n"; + my @do; foreach my $f ( sort { $b->{Chars} <=> $a->{Chars} or @@ -389,8 +393,28 @@ sub do_some_best ($$) { } @forms ) { - p "// $f->{Form}\n"; + my $form = $f->{Form}; + p " sz_$form = Commitid_${form}_sz();\n"; + foreach my $rot (qw(0 1)) { + my $id = "${form}_r${rot}"; + p " sc_$id = min(sc_max"; + foreach my $xy (qw(0 1)) { + p ",max_sz[$xy]/sz_$form","[",(($xy xor $rot)+0),"]"; + } + p ");\n"; + push @do, " if (sc_$id >= 1.0) {\n"; + push @do, " scale(sc_$id)\n"; + push @do, " rotate(90) translate([0,-sz_$form"."[1]])\n" if $rot; + push @do, " Commitid_${form}_2D();\n"; + push @do, " } else"; + } } + push @do, <