blib/lib/Graphics/Primitive/Path.pm

filter: Statementstmt 80.0% 68 / 85 Branchbran 70.0% 7 / 10 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 78.2% 18 / 23 Podpod 100% 10 / 10 totaltotal 78.9% 109 / 138 CC 8 SCAR 6.9
CC
8
Cov
78%
ellipse
6.0
line_to
3.0
move_to
3.0
CRAP 2.0
« blib/lib/Graphics/Primitive/Image.pm ↑ Summary blib/lib/Graphics/Primitive/Component.pm »
1 package Graphics::Primitive::Path;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use MooseX::Storage;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 with 'MooseX::Clone';
6 2 with Storage (format => 'JSON', io => 'File');
7  
8 2 ▶use Geometry::Primitive::Arc;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Geometry::Primitive::Bezier;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Geometry::Primitive::Ellipse;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Geometry::Primitive::Line;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Geometry::Primitive::Rectangle;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 has 'current_point' => (
15 is => 'rw',
16 isa => 'Geometry::Primitive::Point',
17 traits => [qw(Clone)],
18 4 ▶ default => sub { Geometry::Primitive::Point->new(x => 0, y => 0) },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 2 clearer => 'clear_current_point'
20 );
21 has 'contiguous' => (
22 isa => 'Str',
23 is => 'rw',
24 4 ▶ default => sub { 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 2 );
26 has 'hints' => (
27 is => 'rw',
28 isa => 'ArrayRef[HashRef]',
29 traits => [qw(Array Clone)],
30 4 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 2 handles => {
32 add_hint => 'push',
33 get_hint => 'get',
34 }
35 );
36 has 'primitives' => (
37 is => 'rw',
38 isa => 'ArrayRef',
39 traits => [qw(Array Clone)],
40 4 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
41 2 handles => {
42 add_primitive => 'push',
43 clear_primitives => 'clear',
44 primitive_count => 'count',
45 get_primitive => 'get'
46 }
47 );
48  
49 6 ▶after('add_primitive', sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
50 6 my ($self, $prim) = @_;
51  
52 6 my %hint = (
53 contiguous => 0
54 );
55 6 my $new_end = $prim->point_end->clone;
56  
57 6 ▶ if($self->contiguous) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->contiguous) { } 3 3 6
58 # If we are contiguous we can pass that hint to the backend. The
59 # Cairo driver needs to know this to avoid creating a sub-path
60 3 $hint{contiguous} = 1;
61 } else {
62 # We weren't contiguous for this hint, but we WILL be if move_to
63 # isn't used. Set it now so we don't have to later.
64 3 $self->contiguous(1);
65 }
66 6 $self->add_hint(\%hint);
67  
68 6 $self->current_point($new_end);
69 2 });
70  
71 1 ▶sub arc {
Subroutine arc: called CC=2 SCAR=7.0
Pod documented
72 1 my ($self, $radius, $start, $end, $line_to) = @_;
73  
74 1 my $arc = Geometry::Primitive::Arc->new(
75 origin => $self->current_point->clone,
76 radius => $radius, angle_start => $start, angle_end => $end
77 );
78  
79 1 ▶ unless($line_to) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line_to) 1 0 1
80 1 $self->line_to($arc->point_start);
81 }
82  
83 1 $self->add_primitive($arc);
84 }
85  
86 0 ▶sub ellipse {
Subroutine ellipse: not called CC=2 SCAR=17.9
Pod documented
87 0 my ($self, $width, $height, $line_to) = @_;
88  
89 0 my $ell = Geometry::Primitive::Ellipse->new(
90 origin => $self->current_point->clone,
91 width => $width, height => $height
92 );
93  
94 0 ▶ unless($line_to) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line_to) 0 0 0
95 0 $self->line_to($ell->point_start);
96 }
97  
98 0 $self->add_primitive($ell);
99 }
100  
101 1 ▶sub close_path {
Subroutine close_path: called CC=1 SCAR=0.0
Pod documented
102 1 my ($self) = @_;
103  
104 1 $self->line_to($self->get_primitive(0)->point_start->clone);
105 }
106  
107 0 ▶sub curve_to {
Subroutine curve_to: not called CC=1 SCAR=6.9
Pod documented
108 0 my ($self, $c1, $c2, $end) = @_;
109  
110 0 $self->add_primitive(Geometry::Primitive::Bezier->new(
111 start => $self->current_point->clone,
112 control1 => $c1,
113 control2 => $c2,
114 end => $end
115 ));
116 }
117  
118 5 ▶sub line_to {
Subroutine line_to: called CC=3 SCAR=11.0
Pod documented
119 5 my ($self, $x, $y) = @_;
120  
121 5 my $point;
122 5 ▶ if(!ref($x) && defined($y)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $x and defined $y) { } 2 3 5
Condition66%2/3
not ref $x and defined $y
!ll&&!rl&&r
302
MC/DC50%1/2
not ref $x and defined $y
not ref $x defined $y
Truth table66%2/3
not(A) and B
A= not ref $xB= defined $y
ABresult
0X0
100
111
123 # This allows the user to pass in $x and $y as scalars, which
124 # easier sometimes.
125 2 $point = Geometry::Primitive::Point->new(x => $x, y => $y);
126 } else {
127 3 $point = $x->clone;
128 }
129  
130 5 $self->add_primitive(Geometry::Primitive::Line->new(
131 start => $self->current_point->clone,
132 end => $point
133 ));
134 }
135  
136 5 ▶sub move_to {
Subroutine move_to: called CC=3 SCAR=11.0
Pod documented
137 5 my ($self, $x, $y) = @_;
138  
139 5 my $point;
140 5 ▶ if(!ref($x) && defined($y)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $x and defined $y) { } 4 1 5
Condition66%2/3
not ref $x and defined $y
!ll&&!rl&&r
104
MC/DC50%1/2
not ref $x and defined $y
not ref $x defined $y
Truth table66%2/3
not(A) and B
A= not ref $xB= defined $y
ABresult
0X0
100
111
141 # This allows the user to pass in $x and $y as scalars, which
142 # easier sometimes.
143 4 $point = Geometry::Primitive::Point->new(x => $x, y => $y);
144 } else {
145 1 $point = $x;
146 }
147  
148 # Move to effectively creates a new path, so we are no longer contiguous.
149 # This mainly serves as a backend hint.
150 5 $self->contiguous(0);
151 5 $self->current_point($point);
152 }
153  
154 0 ▶sub rectangle {
Subroutine rectangle: not called CC=1 SCAR=6.9
Pod documented
155 0 my ($self, $width, $height) = @_;
156  
157 0 $self->add_primitive(Geometry::Primitive::Rectangle->new(
158 origin => $self->current_point,
159 width => $width,
160 height => $height
161 ));
162 }
163  
164 0 ▶sub rel_curve_to {
Subroutine rel_curve_to: not called CC=1 SCAR=6.9
Pod documented
165 0 my ($self, $x1, $y1, $x2, $y2, $x3, $y3) = @_;
166 0 my $curr = $self->current_point;
167 0 $self->curve_to(
168 Geometry::Primitive::Point->new(
169 x => $curr->x + $x1, y => $curr->y + $y1
170 ),
171 Geometry::Primitive::Point->new(
172 x => $curr->x + $x2, y => $curr->y + $y2
173 ),
174 Geometry::Primitive::Point->new(
175 x => $curr->x + $x3, y => $curr->y + $y3
176 )
177 );
178 }
179  
180 0 ▶sub rel_line_to {
Subroutine rel_line_to: not called CC=1 SCAR=6.9
Pod documented
181 0 my ($self, $x, $y) = @_;
182  
183 # FIXME Relative hinting?
184 0 my $point = $self->current_point->clone;
185 0 $point->x($point->x + $x);
186 0 $point->y($point->y + $y);
187  
188 0 $self->add_primitive(Geometry::Primitive::Line->new(
189 start => $self->current_point->clone,
190 end => $point
191 ));
192 }
193  
194 1 ▶sub rel_move_to {
Subroutine rel_move_to: called CC=1 SCAR=0.0
Pod documented
195 1 my ($self, $x, $y) = @_;
196  
197 1 my $point = $self->current_point->clone;
198 1 $self->move_to($point->x + $x, $point->y + $y);
199 }
200  
201 2 __PACKAGE__->meta->make_immutable;
202  
203 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
204 2 1;
205  
206 __END__
« blib/lib/Graphics/Primitive/Image.pm ↑ Summary blib/lib/Graphics/Primitive/Component.pm »