File Coverage

blib/lib/CAD/Format/STL/part.pm
Criterion Covered Total %
statement 28 28 100.0
branch 5 6 83.3
condition 1 3 33.3
subroutine 7 7 100.0
pod 2 2 100.0
total 43 46 93.4


line stmt bran cond sub pod time code
1             package CAD::Format::STL::part;
2             $VERSION = v0.2.1;
3              
4 3     3   11 use warnings;
  3         8  
  3         72  
5 3     3   14 use strict;
  3         4  
  3         71  
6 3     3   19 use Carp;
  3         11  
  3         168  
7              
8             =head1 NAME
9              
10             CAD::Format::STL::part - guts of the STL object
11              
12             =head1 SYNOPSIS
13              
14             See L
15              
16             =cut
17              
18 3     3   3212 use Class::Accessor::Classy;
  3         33525  
  3         28  
19             rw 'name';
20             lw 'facets';
21 3     3   716 no Class::Accessor::Classy;
  3         6  
  3         17  
22              
23             =head1 Constructor
24              
25             =head2 new
26              
27             my $part = CAD::Format::STL::part->new($name, @facets);
28              
29             =cut
30              
31             sub new {
32 4     4 1 10 my $package = shift;
33 4         11 my ($name, @facets) = @_;
34              
35 4   33     28 my $class = ref($package) || $package;
36 4 50       25 my $self = {
37             name => (defined($name) ? $name : 'CAD::Format::STL part'),
38             facets => [],
39             };
40 4         16 bless($self, $class);
41              
42 4 100       20 $self->add_facets(@facets) if(@facets);
43              
44 4         21 return($self);
45             } # end subroutine new definition
46             ########################################################################
47              
48             =head2 add_facets
49              
50             $self->add_facets(@facets);
51              
52             Facets are stored with the normal vector, followed by vertices.
53             Typically, a single facet is a triangle and the normal is [0,0,0]
54             (meaning that it should be calculated by the user if needed.)
55              
56             [0,0,0], [0,0,0],[0,1,0],[1,1,0]
57              
58             =cut
59              
60             sub add_facets {
61 15     15 1 2152 my $self = shift;
62 15         34 my (@facets) = @_;
63              
64 15         28 foreach my $facet (@facets) {
65 48         304 my @pts = @$facet;
66 48 100       131 my $n = ((scalar(@pts) == 3) ? [0,0,0] : shift(@pts));
67 48         1388 $self->SUPER::add_facets([$n, @pts]);
68             }
69             } # end subroutine add_facets definition
70             ########################################################################
71              
72             =head1 AUTHOR
73              
74             Eric Wilhelm @
75              
76             http://scratchcomputing.com/
77              
78             =head1 BUGS
79              
80             If you found this module on CPAN, please report any bugs or feature
81             requests through the web interface at L. I will be
82             notified, and then you'll automatically be notified of progress on your
83             bug as I make changes.
84              
85             If you pulled this development version from my /svn/, please contact me
86             directly.
87              
88             =head1 COPYRIGHT
89              
90             Copyright (C) 2007 Eric L. Wilhelm, All Rights Reserved.
91              
92             =head1 NO WARRANTY
93              
94             Absolutely, positively NO WARRANTY, neither express or implied, is
95             offered with this software. You use this software at your own risk. In
96             case of loss, no person or entity owes you anything whatsoever. You
97             have been warned.
98              
99             =head1 LICENSE
100              
101             This program is free software; you can redistribute it and/or modify it
102             under the same terms as Perl itself.
103              
104             =cut
105              
106             # vi:ts=2:sw=2:et:sta
107             1;