chiark / gitweb /
commitid: Best, initial sort-of-working implementation
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 5 Feb 2016 21:24:11 +0000 (21:24 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 5 Feb 2016 21:24:11 +0000 (21:24 +0000)
.gitignore
commitid-best-test.scad.pl [new file with mode: 0755]
commitid.scad.pl

index a4946739cf6821c85464d5d4c661842555de3eb1..d0a75d2ff4234af4e9e8ec77c39a277603dc8e70 100644 (file)
@@ -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 (executable)
index 0000000..73cfd8f
--- /dev/null
@@ -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 <commitid.scad>\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;
+}
index e51318aaf26ba755d3be754fd6a867f64770898f..7506c621ab74a8c8885fb57ae3479f352eb25271 100755 (executable)
@@ -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, <<END;
+ {
+  echo("$fullmodname could not fit anything in", max_sz);
+ }
+END
+    p $_ foreach @do;
     p "}\n";
 }