| 1 | package Lego::Ldraw::Line; | ||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008004; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||
| 7 | 1 | ▶ | no warnings qw(uninitialized redefine); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 8 | use overload | ||||||||||||||||||||||||
| 9 | 1 | ▶ | '""' => \&stringify, | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 10 | 1 | '*' => \&transform; | |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 13 | 1 | ▶ | use YAML; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 14 | 1 | ▶ | use Lego::Ldraw; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 15 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 16 | 1 | ▶ | use Math::MatrixReal; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 17 | 1 | ▶ | use Math::Trig; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 18 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||
| 20 | 1 | my $line_formats = [ | |||||||||||||||||||||||
| 21 | [qw(type command)], | ||||||||||||||||||||||||
| 22 | [qw(type colour x y z a b c d e f g h i part)], | ||||||||||||||||||||||||
| 23 | [qw(type colour x1 y1 z1 x2 y2 z2)], | ||||||||||||||||||||||||
| 24 | [qw(type colour x1 y1 z1 x2 y2 z2 x3 y3 z3)], | ||||||||||||||||||||||||
| 25 | [qw(type colour x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4)], | ||||||||||||||||||||||||
| 26 | [qw(type colour x1 y1 z1 x2 y2 z2 x3 y3 z3 x4 y4 z4)] | ||||||||||||||||||||||||
| 27 | ]; | ||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||
| 29 | 1 | our $config; | |||||||||||||||||||||||
| 30 | 1 | our %descriptions; | |||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||
| 32 | ####################################################################### | ||||||||||||||||||||||||
| 33 | # Constructors | ||||||||||||||||||||||||
| 34 | ####################################################################### | ||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||
| 36 | 0 | ▶ | sub new { | ||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||
| 37 | 0 | my $proto = shift; | |||||||||||||||||||||||
| 38 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||
| 39 | 0 | my $self = {}; | |||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||
| 41 | 0 | bless ($self, $class); | |||||||||||||||||||||||
| 42 | 0 | return $self; | |||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||
| 45 | 0 | ▶ | sub new_from_string { | ||||||||||||||||||||||
|
Subroutine
new_from_string: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||
| 46 | 0 | my $self = shift->new; | |||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||
| 48 | 0 | my $line = shift; | |||||||||||||||||||||||
| 49 | 0 | for ($line) { | |||||||||||||||||||||||
| 50 | 0 | s/\s+$//; s/^\s+//; | |||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||
| 53 | 0 | my @line = split ' ', $line; | |||||||||||||||||||||||
| 54 | 0 | ▶ | @line = ($line[0], join (' ', @line[1..$#line])) unless ($line[0]); # handle comment lines | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||
| 56 | 0 | my @fields = @{$line_formats->[$line[0]]}; | |||||||||||||||||||||||
| 57 | 0 | @{$self}{@fields} = @line; | |||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||
| 59 | 0 | return $self; | |||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||
| 62 | 0 | ▶ | sub new_from_part_name { | ||||||||||||||||||||||
|
Subroutine
new_from_part_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 63 | 0 | my $self = shift; | |||||||||||||||||||||||
| 64 | 0 | my $part = shift; | |||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||
| 66 | 0 | return $self->new_from_string('1 16 0 0 0 1 0 0 0 1 0 0 0 1 ' . $part); | |||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||
| 69 | ####################################################################### | ||||||||||||||||||||||||
| 70 | # Field access functions | ||||||||||||||||||||||||
| 71 | ####################################################################### | ||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||
| 73 | 1 | ▶ | sub BEGIN { | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=10.9
| |||||||||||||||||||||||||
| 74 | #-------------------------------------------------- | ||||||||||||||||||||||||
| 75 | # Use generated functions for clarity and speed, | ||||||||||||||||||||||||
| 76 | # with exceptions... | ||||||||||||||||||||||||
| 77 | #-------------------------------------------------- | ||||||||||||||||||||||||
| 78 | 1 | my @field_list = ('colour', 'a'..'i', 'x', 'y', 'z', | |||||||||||||||||||||||
| 79 | 'x1', 'y1', 'z1', 'x2', 'y2', 'z2', | ||||||||||||||||||||||||
| 80 | 'x3', 'y3', 'z3', 'x4', 'y4', 'z4'); | ||||||||||||||||||||||||
| 81 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 82 | 1 | for my $field (@field_list) { | |||||||||||||||||||||||
| 83 | 0 | ▶ | *$field = sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||
| 84 | 0 | my $self = shift; | |||||||||||||||||||||||
| 85 | 0 | ▶ | return unless exists $self->{$field}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 86 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 87 | 0 | $self->{$field} = shift; | |||||||||||||||||||||||
| 88 | 0 | return $self->{$field}; | |||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||
| 90 | 0 | return $self->{$field}; | |||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||
| 93 | 25 | } | |||||||||||||||||||||||
| 94 | 1 | ▶ | use strict 'refs'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||
| 97 | #-------------------------------------------------- | ||||||||||||||||||||||||
| 98 | # ...because of uppercasing | ||||||||||||||||||||||||
| 99 | #-------------------------------------------------- | ||||||||||||||||||||||||
| 100 | 0 | ▶ | sub part { | ||||||||||||||||||||||
|
Subroutine
part: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||
| 101 | 0 | my $self = shift; | |||||||||||||||||||||||
| 102 | 0 | ▶ | return unless exists $self->{'part'}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 103 | 0 | my $part = $self->{part}; | |||||||||||||||||||||||
| 104 | 0 | $part =~ s/\\/\//g; | |||||||||||||||||||||||
| 105 | 0 | return lc $part; | |||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||
| 108 | 0 | ▶ | sub name { | ||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 109 | 0 | return basename(shift->part); | |||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||
| 112 | #-------------------------------------------------- | ||||||||||||||||||||||||
| 113 | # ...because it's read-only | ||||||||||||||||||||||||
| 114 | #-------------------------------------------------- | ||||||||||||||||||||||||
| 115 | 0 | ▶ | sub type { | ||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 116 | 0 | return shift->{type}; | |||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||
| 119 | #-------------------------------------------------- | ||||||||||||||||||||||||
| 120 | # ...because of spelling | ||||||||||||||||||||||||
| 121 | #-------------------------------------------------- | ||||||||||||||||||||||||
| 122 | 0 | ▶ | sub color { | ||||||||||||||||||||||
|
Subroutine
color: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 123 | 0 | shift->colour(@_); | |||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||
| 126 | ####################################################################### | ||||||||||||||||||||||||
| 127 | # other field access functions | ||||||||||||||||||||||||
| 128 | ####################################################################### | ||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||
| 130 | 0 | ▶ | sub copy { | ||||||||||||||||||||||
|
Subroutine
copy: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 131 | 0 | my $self = shift; | |||||||||||||||||||||||
| 132 | 0 | return bless { %{$self} }, ref $self; | |||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||
| 135 | 0 | ▶ | sub fields { | ||||||||||||||||||||||
|
Subroutine
fields: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 136 | 0 | return @{$line_formats->[ shift->type ]} | |||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||
| 139 | 0 | ▶ | sub model { | ||||||||||||||||||||||
|
Subroutine
model: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||
| 140 | 0 | my $self = shift; | |||||||||||||||||||||||
| 141 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 142 | 0 | $self->{model} = shift; | |||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||
| 144 | 0 | return $self->{model}; | |||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||
| 147 | 0 | ▶ | sub description { | ||||||||||||||||||||||
|
Subroutine
description: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||
| 148 | 0 | my $self = shift; | |||||||||||||||||||||||
| 149 | 0 | ▶ | return unless $self->type == 1; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||
| 151 | 0 | return $descriptions{$self->part}; | |||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||
| 155 | 0 | ▶ | sub values { | ||||||||||||||||||||||
|
Subroutine
values: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||
| 156 | 0 | my $self = shift; | |||||||||||||||||||||||
| 157 | 0 | my @fields = @_; | |||||||||||||||||||||||
| 158 | 0 | ▶ | @fields = $self->fields unless @fields; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 159 | 0 | return @{$self}{ @fields } | |||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||
| 162 | 0 | ▶ | sub coords { | ||||||||||||||||||||||
|
Subroutine
coords: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 163 | 0 | my $self = shift; | |||||||||||||||||||||||
| 164 | 0 | my @fields = grep { /^[xyz]/ } $self->fields; | |||||||||||||||||||||||
| 165 | 0 | return $self->values(@fields); | |||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||
| 168 | 0 | ▶ | sub points { | ||||||||||||||||||||||
|
Subroutine
points: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||
| 169 | 0 | my $points = shift->type; | |||||||||||||||||||||||
| 170 | 0 | ▶ | return $points > 4 ? 4 : $points; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||
| 173 | 0 | ▶ | sub transform_matrix { | ||||||||||||||||||||||
|
Subroutine
transform_matrix: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||
| 174 | 0 | my $self = shift; | |||||||||||||||||||||||
| 175 | 0 | ▶ | return unless ($self->type == 1); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||
| 177 | 0 | my @fields = grep { /^[a-ixyz]$/ } $self->fields; | |||||||||||||||||||||||
| 178 | 0 | return $self->values(@fields); | |||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||
| 181 | 0 | ▶ | sub point { | ||||||||||||||||||||||
|
Subroutine
point: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||
| 182 | 0 | my $self = shift; | |||||||||||||||||||||||
| 183 | 0 | my $point = shift; | |||||||||||||||||||||||
| 184 | 0 | ▶ | return unless my $type = $self->type; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||
| 186 | 0 | ▶ | if ($type == 1) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 187 | 0 | return $self->values(qw(x y z)); | |||||||||||||||||||||||
| 188 | } else { | ||||||||||||||||||||||||
| 189 | 0 | return $self->values(map { $_ . $point } qw(x y z)) | |||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||
| 193 | 0 | ▶ | sub format { | ||||||||||||||||||||||
|
Subroutine
format: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||
| 194 | 0 | my $self = shift; | |||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||
| 196 | 0 | my @text = $self->values; | |||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||
| 198 | 0 | for ($self->type) { | |||||||||||||||||||||||
| 199 | 0 | ▶ | /^0/ && do { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 200 | 0 | return "$self"; | |||||||||||||||||||||||
| 201 | }; | ||||||||||||||||||||||||
| 202 | 0 | ▶ | /^1/ && do { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 203 | 0 | my $string = "%d %7d"; | |||||||||||||||||||||||
| 204 | 0 | for (2..$#text-1) { | |||||||||||||||||||||||
| 205 | 0 | $string .= "% 8.2f"; | |||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||
| 207 | 0 | $string .= " %12s"; | |||||||||||||||||||||||
| 208 | 0 | return sprintf $string, @text; | |||||||||||||||||||||||
| 209 | }; | ||||||||||||||||||||||||
| 210 | 0 | my $string = "%d"; | |||||||||||||||||||||||
| 211 | 0 | for (1..$#text) { | |||||||||||||||||||||||
| 212 | 0 | $string .= "% 8.2f"; | |||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||
| 214 | 0 | return sprintf $string, @text; | |||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||
| 218 | 0 | ▶ | sub eval { | ||||||||||||||||||||||
|
Subroutine
eval: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||
| 219 | 0 | my $self = shift; | |||||||||||||||||||||||
| 220 | 0 | my $expr = shift; | |||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||
| 222 | 0 | $expr = lc $expr; | |||||||||||||||||||||||
| 223 | 0 | $expr =~ s/color/colour/g; | |||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||
| 225 | # substitute % strings with field accesses, | ||||||||||||||||||||||||
| 226 | # and while doing so check if field exists: | ||||||||||||||||||||||||
| 227 | # if it doesn't return undef | ||||||||||||||||||||||||
| 228 | 0 | ▶ | while ($expr =~ s/\%([a-z0-9]+)/\$self->{$1}/) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 229 | 0 | ▶ | return unless defined $self->$1; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||
| 232 | # substitute & strings with function calls, | ||||||||||||||||||||||||
| 233 | # and while doing so check if function exists: | ||||||||||||||||||||||||
| 234 | # if it doesn't return undef | ||||||||||||||||||||||||
| 235 | 0 | ▶ | while ($expr =~ s/\&(\w+)/\$self->$1/) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 236 | 0 | ▶ | return unless defined $self->can($1); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||
| 239 | # now we've got a full eval'uable string, and | ||||||||||||||||||||||||
| 240 | # we eval it | ||||||||||||||||||||||||
| 241 | 0 | ▶ | if (eval $expr) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 242 | 0 | return $self | |||||||||||||||||||||||
| 243 | } else { | ||||||||||||||||||||||||
| 244 | return | ||||||||||||||||||||||||
| 245 | 0 | } | |||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||
| 248 | ####################################################################### | ||||||||||||||||||||||||
| 249 | # inlining | ||||||||||||||||||||||||
| 250 | ####################################################################### | ||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||
| 252 | 0 | ▶ | sub normalize { | ||||||||||||||||||||||
|
Subroutine
normalize: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||
| 253 | 0 | my $self = shift; | |||||||||||||||||||||||
| 254 | 0 | ▶ | return unless $self->type == 1; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||
| 256 | 0 | @{$self}{qw/x y z a b c d e f g h i/} = qw/0 0 0 1 0 0 0 1 0 0 0 1/; | |||||||||||||||||||||||
| 257 | 0 | return $self; | |||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||
| 260 | 0 | ▶ | sub dir { | ||||||||||||||||||||||
|
Subroutine
dir: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||
| 261 | 0 | my $self = shift; | |||||||||||||||||||||||
| 262 | 0 | ▶ | $self->{dir} = shift if @_; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 263 | 0 | return $self->{dir}; | |||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||
| 266 | 0 | ▶ | sub partfile { | ||||||||||||||||||||||
|
Subroutine
partfile: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||
| 267 | 0 | my $self = shift; | |||||||||||||||||||||||
| 268 | 0 | ▶ | return unless $self->type == 1; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||
| 270 | 0 | my $part = $self->part; | |||||||||||||||||||||||
| 271 | return $self->config->{partfiles}->{$part} | ||||||||||||||||||||||||
| 272 | 0 | ▶ | if $self->config->{partfiles}->{$part}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||
| 274 | 0 | my $base = $self->config->{base}; | |||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||
| 276 | 0 | my @parts = @{$self->config->{parts}}; | |||||||||||||||||||||||
| 277 | 0 | @parts = map { $_ = $base . $_ . $part } @parts; | |||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||
| 279 | 0 | @parts = ('./' . $part, $self->dir . '/' . $part, @parts); | |||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||
| 281 | 0 | for (@parts) { | |||||||||||||||||||||||
| 282 | 0 | s/\\/\//g; | |||||||||||||||||||||||
| 283 | 0 | ▶ | if (-e $_) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 284 | 0 | $self->config->{partfiles}->{$part} = $_; | |||||||||||||||||||||||
| 285 | 0 | return $_; | |||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||
| 290 | 0 | ▶ | sub explode { | ||||||||||||||||||||||
|
Subroutine
explode: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||
| 291 | 0 | my $self = shift; | |||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||
| 293 | 0 | ▶ | return unless $self->type == 1; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||
| 295 | 0 | my $file = $self->partfile; | |||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||
| 297 | 0 | ▶ | return unless $file; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 298 | 0 | return Lego::Ldraw->new_from_file($file); | |||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||
| 301 | 0 | ▶ | sub traslate { | ||||||||||||||||||||||
|
Subroutine
traslate: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||
| 302 | 0 | my $self = shift; | |||||||||||||||||||||||
| 303 | 0 | my %trans; | |||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||
| 305 | 0 | ▶ | if (ref $_[0] eq 'HASH') { %trans = %{ $_[0] } } | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 306 | 0 | else { @trans{qw(x y z)} = @_ }; | |||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||
| 308 | 0 | for my $axis (keys %trans) { | |||||||||||||||||||||||
| 309 | 0 | for my $field ( grep { /^$axis/ } $self->fields ) { | |||||||||||||||||||||||
| 310 | 0 | $self->{$field} += $trans{$axis} | |||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||
| 313 | 0 | return $self; | |||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||
| 316 | 0 | ▶ | sub transform { | ||||||||||||||||||||||
|
Subroutine
transform: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||
| 317 | 0 | my $self = shift; | |||||||||||||||||||||||
| 318 | 0 | my $line = shift; | |||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||
| 320 | 0 | ▶ | return unless $self->type; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 321 | 0 | ▶ | return unless $line->type == 1; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||
| 323 | 0 | ▶ | $self->color($line->color) if $self->color == 16; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 324 | 0 | my $m = $line->_transform_matrix; | |||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||
| 326 | 0 | ▶ | if ($self->type == 1) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 327 | 0 | my $x = $self->_transform_matrix(); | |||||||||||||||||||||||
| 328 | 0 | $self->_transform_matrix($x * $m); | |||||||||||||||||||||||
| 329 | } else { | ||||||||||||||||||||||||
| 330 | 0 | for (1..$self->points) { | |||||||||||||||||||||||
| 331 | 0 | my $p = $self->_xyz_matrix(undef, $_); | |||||||||||||||||||||||
| 332 | 0 | $self->_xyz_matrix($p * $m, $_) | |||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||
| 337 | 0 | ▶ | sub rotate { | ||||||||||||||||||||||
|
Subroutine
rotate: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||
| 338 | 0 | my $self = shift; | |||||||||||||||||||||||
| 339 | 0 | my ($axis, $degrees) = @_; | |||||||||||||||||||||||
| 340 | 0 | ▶ | return unless $self->type; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||
| 342 | 0 | my $x = $self->_transform_matrix(); | |||||||||||||||||||||||
| 343 | 0 | my $r = $self->_rotate_matrix($axis, $degrees); | |||||||||||||||||||||||
| 344 | 0 | $self->_transform_matrix($x * $r); | |||||||||||||||||||||||
| 345 | 0 | return $self; | |||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||
| 348 | ####################################################################### | ||||||||||||||||||||||||
| 349 | # other stuff | ||||||||||||||||||||||||
| 350 | ####################################################################### | ||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||
| 352 | 0 | ▶ | sub stringify { | ||||||||||||||||||||||
|
Subroutine
stringify: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 353 | 0 | my $self = shift; | |||||||||||||||||||||||
| 354 | 0 | my $type = $self->type; | |||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||
| 356 | 0 | my @fields = @{$line_formats->[$self->type]}; | |||||||||||||||||||||||
| 357 | 0 | return join ' ', @{$self}{@fields}; | |||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||
| 360 | ####################################################################### | ||||||||||||||||||||||||
| 361 | # matrix calculation | ||||||||||||||||||||||||
| 362 | ####################################################################### | ||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||
| 364 | 0 | ▶ | sub _xyz_matrix { | ||||||||||||||||||||||
|
Subroutine
_xyz_matrix: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||
| 365 | 0 | my $self = shift; | |||||||||||||||||||||||
| 366 | 0 | my $matrix = shift; | |||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||
| 368 | 0 | ▶ | if ($matrix) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 369 | 0 | ▶ | my $point = $self->type == 1 ? undef : shift; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 370 | 0 | my @fields = map { $_ . $point } ('x', 'y', 'z'); | |||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||
| 372 | 0 | ▶ | $matrix->each( sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||
| 373 | 0 | my $field = shift @fields; | |||||||||||||||||||||||
| 374 | 0 | ▶ | return unless $field; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 375 | 0 | $self->$field(shift) | |||||||||||||||||||||||
| 376 | 0 | } ); | |||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||
| 378 | 0 | return $self; | |||||||||||||||||||||||
| 379 | } else { | ||||||||||||||||||||||||
| 380 | 0 | my @point = $self->point(shift); | |||||||||||||||||||||||
| 381 | 0 | my $matrix = Math::MatrixReal->new(1, 4); | |||||||||||||||||||||||
| 382 | 0 | $matrix->[0] = [ [ @point, 1 ] ]; | |||||||||||||||||||||||
| 383 | 0 | ▶ | return @point ? $matrix : undef; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||
| 387 | 0 | ▶ | sub _transform_matrix { | ||||||||||||||||||||||
|
Subroutine
_transform_matrix: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||
| 388 | 0 | my $self = shift; | |||||||||||||||||||||||
| 389 | 0 | my $matrix = shift; | |||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||
| 391 | 0 | ▶ | if ($matrix) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 392 | 0 | my @fields = (qw(a d g), undef, | |||||||||||||||||||||||
| 393 | qw(b e h), undef, | ||||||||||||||||||||||||
| 394 | qw(c f i), undef, | ||||||||||||||||||||||||
| 395 | qw(x y z), undef); | ||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||
| 397 | # update each field in order with | ||||||||||||||||||||||||
| 398 | # the matrix' value | ||||||||||||||||||||||||
| 399 | 0 | ▶ | $matrix->each( sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||
| 400 | 0 | my $field = shift @fields; | |||||||||||||||||||||||
| 401 | 0 | ▶ | return unless $field; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 402 | 0 | $self->$field(shift) | |||||||||||||||||||||||
| 403 | 0 | } ); | |||||||||||||||||||||||
| 404 | 0 | return $self; | |||||||||||||||||||||||
| 405 | } else { | ||||||||||||||||||||||||
| 406 | 0 | my $matrix = Math::MatrixReal->new(4, 4); | |||||||||||||||||||||||
| 407 | 0 | $matrix->[0] = [ | |||||||||||||||||||||||
| 408 | [ $self->values( qw(a d g) ), 0 ], | ||||||||||||||||||||||||
| 409 | [ $self->values( qw(b e h) ), 0 ], | ||||||||||||||||||||||||
| 410 | [ $self->values( qw(c f i) ), 0 ], | ||||||||||||||||||||||||
| 411 | [ $self->values( qw(x y z) ), 1 ] | ||||||||||||||||||||||||
| 412 | ]; | ||||||||||||||||||||||||
| 413 | 0 | return $matrix; | |||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||
| 417 | 0 | ▶ | sub _rotate_matrix { | ||||||||||||||||||||||
|
Subroutine
_rotate_matrix: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||
| 418 | 0 | my $self = shift; | |||||||||||||||||||||||
| 419 | 0 | my ($axis, $degrees) = @_; | |||||||||||||||||||||||
| 420 | 0 | my $rad = deg2rad($degrees); | |||||||||||||||||||||||
| 421 | 0 | my $matrix = Math::MatrixReal->new(4, 4); | |||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||
| 423 | 0 | for ($axis) { | |||||||||||||||||||||||
| 424 | 0 | ▶ | /^x$/ && do { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 425 | 0 | $matrix->[0] = [ | |||||||||||||||||||||||
| 426 | [ 1, 0, 0, 0 ], | ||||||||||||||||||||||||
| 427 | [ 0, cos($rad), sin($rad), 0 ], | ||||||||||||||||||||||||
| 428 | [ 0, -sin($rad), cos($rad), 0 ], | ||||||||||||||||||||||||
| 429 | [ 0, 0, 0, 1 ] | ||||||||||||||||||||||||
| 430 | ]; | ||||||||||||||||||||||||
| 431 | }; | ||||||||||||||||||||||||
| 432 | 0 | ▶ | /^y$/ && do { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 433 | 0 | $matrix->[0] = [ | |||||||||||||||||||||||
| 434 | [cos($rad), 0, -sin($rad), 0], | ||||||||||||||||||||||||
| 435 | [0, 1, 0, 0], | ||||||||||||||||||||||||
| 436 | [sin($rad), 0, cos($rad), 0], | ||||||||||||||||||||||||
| 437 | [0, 0, 0, 1], | ||||||||||||||||||||||||
| 438 | ]; | ||||||||||||||||||||||||
| 439 | }; | ||||||||||||||||||||||||
| 440 | 0 | ▶ | /^z$/ && do { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 441 | 0 | $matrix->[0] = [ | |||||||||||||||||||||||
| 442 | [ cos($rad), sin($rad), 0, 0 ], | ||||||||||||||||||||||||
| 443 | [ -sin($rad), cos($rad), 0, 0 ], | ||||||||||||||||||||||||
| 444 | [0, 0, 1, 0], | ||||||||||||||||||||||||
| 445 | [0, 0, 0, 1] | ||||||||||||||||||||||||
| 446 | ]; | ||||||||||||||||||||||||
| 447 | }; | ||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||
| 450 | 0 | return $matrix; | |||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||
| 455 | ############################################################### | ||||||||||||||||||||||||
| 456 | # configuration stuff | ||||||||||||||||||||||||
| 457 | ############################################################### | ||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||
| 459 | 1 | ▶ | sub INIT { | ||||||||||||||||||||||
|
Subroutine
INIT: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||
| 460 | 1 | ▶ | return if $config; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 461 | 1 | $config = do { local $/; <DATA> }; | |||||||||||||||||||||||
| 462 | 1 | $config = Load($config); | |||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||
| 464 | 1 | $config->{base} = $ENV{'LDRAWDIR'}; | |||||||||||||||||||||||
| 465 | 1 | ▶ | open DESCRIPTIONS, $config->{base} . 'parts.lst' || return; | ||||||||||||||||||||||
|
Condition50%1/2
$Lego::Ldraw::Line::config->{'base'} . 'parts.lst' || (return)
MC/DC0%0/1
$Lego::Ldraw::Line::config->{'base'} . 'parts.lst' || (return)
$Lego::Ldraw::Line::config->{'base'} . 'parts.lst'
Truth table50%1/2
A
A= $Lego::Ldraw::Line::config->{'base'} . 'parts.lst'
| |||||||||||||||||||||||||
| 466 | 1 | ▶ | while (<DESCRIPTIONS>) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 467 | 0 | chop; | |||||||||||||||||||||||
| 468 | 0 | my ($part, $description) = unpack 'A14A*', $_; | |||||||||||||||||||||||
| 469 | 0 | $descriptions{$part} = $description; | |||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||
| 473 | 0 | ▶ | sub config { | ||||||||||||||||||||||
|
Subroutine
config: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 474 | 0 | return $config; | |||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||
| 477 | 0 | ▶ | sub basedir { | ||||||||||||||||||||||
|
Subroutine
basedir: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 478 | 0 | local $_ = $config->{base}; | |||||||||||||||||||||||
| 479 | 0 | s/\/$//; | |||||||||||||||||||||||
| 480 | 0 | s/\\$//; | |||||||||||||||||||||||
| 481 | 0 | return $_; | |||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||
| 484 | 0 | ▶ | sub partsdirs { | ||||||||||||||||||||||
|
Subroutine
partsdirs: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||
| 485 | 0 | my $self = shift; | |||||||||||||||||||||||
| 486 | 0 | my @d = @{$config->{parts}}; | |||||||||||||||||||||||
| 487 | 0 | my $base = $self->basedir; | |||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||
| 489 | 0 | for (@d) { | |||||||||||||||||||||||
| 490 | 0 | ▶ | $_ = join ('/', $base, $_) | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 491 | unless /^\./; | ||||||||||||||||||||||||
| 492 | 0 | s/\/$//; | |||||||||||||||||||||||
| 493 | 0 | s/\\$//; | |||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||
| 495 | 0 | return @d; | |||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||
| 498 | 0 | ▶ | sub primitives { | ||||||||||||||||||||||
|
Subroutine
primitives: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||
| 499 | 0 | return %{$config->{primitives}} | |||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||
| 502 | ############################################################### | ||||||||||||||||||||||||
| 503 | # faster constructor for Matrix::Real | ||||||||||||||||||||||||
| 504 | ############################################################### | ||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||
| 506 | 0 | ▶ | sub Math::MatrixReal::new { | ||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||
| 507 | 0 | my ($proto, $rows, $cols) = @_; | |||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||
| 509 | 0 | ▶ | my $class = ref($proto) || $proto || 'Math::MatrixReal'; | ||||||||||||||||||||||
|
Condition0%0/5
ref $proto || $proto || 'Math::MatrixReal'
ref $proto or $proto
MC/DC0%0/2
ref $proto || $proto || 'Math::MatrixReal'
ref $proto
$proto
Truth table0%0/3
A or B
A= ref $protoB= $proto
| |||||||||||||||||||||||||
| 510 | 0 | my($i, $j, $this); | |||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||
| 512 | 0 | $this = [ [ ], $rows, $cols ]; | |||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||
| 514 | 0 | bless($this, $class); | |||||||||||||||||||||||
| 515 | 0 | return($this); | |||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||
| 518 | ############################################################### | ||||||||||||||||||||||||
| 519 | # end of faster constructor for Matrix::Real | ||||||||||||||||||||||||
| 520 | ############################################################### | ||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||
| 522 | 1 | 1; | |||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||
| 524 | __DATA__ | ||||||||||||||||||||||||