simplify paths produced by graphplay
authorShiar <shiar@shiar.org>
Wed, 6 Feb 2008 21:39:30 +0000 (22:39 +0100)
committerShiar <shiar@shiar.org>
Thu, 7 Feb 2008 23:14:24 +0000 (00:14 +0100)
Only keep first and last entries for identical values. In other words,
horizontal lines will not have each pixel specified, but only the two
corners. This already results in significantly smaller files (test case
went from 1.8MB to 1.5MB, and to just 130kB for unit graphs!). The same
thing should be done for sloped lines, but this is not as obviously
simple.

graphplay

index d6baebfe517f1102a120bc8d6061948739f7ffd7..9956168612fe29ce5ba3903b1eda95d3a109189e 100755 (executable)
--- a/graphplay
+++ b/graphplay
@@ -54,6 +54,22 @@ for my $input (@ARGV) {
                }
        }
 
+       for (0 .. 2) {
+               my $line = $lines[$_][$player];
+               my $start;
+               my $lasty;
+               for (my $i = 1; $i <= $#$line; $i++) {
+                       defined $line->[$i] or next;
+                       if ($line->[$i][1] == $line->[$i - 1][1]) {
+                               $start = $i unless defined $start;
+                       } elsif (defined $start) {
+                               delete @$line[$start .. $i-2];
+                               undef $start;
+                       }
+               }
+               delete @$line[$start .. $#$line-2] if defined $start; # or -1
+       }
+
        $player++;
 }