Taffeta/Graphics/Polygon.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 52 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use Renard::Incunabula::Common::Setup;
2 package Intertangle::Taffeta::Graphics::Polygon;
3 # ABSTRACT: A segmented shape made up of points
4 $Intertangle::Taffeta::Graphics::Polygon::VERSION = '0.001';
5 use Moo;
6  
7 extends qw(Intertangle::Taffeta::Graphics);
8  
9 use Renard::Incunabula::Common::Types qw(ArrayRef);
10 use Intertangle::Yarn::Types qw(Point);
11 use Intertangle::Taffeta::Types qw(CairoContext SVG);
12  
13 use List::AllUtils qw(minmax);
14  
15 has points => (
16 is => 'ro',
17 isa => ArrayRef[Point],
18 required => 1,
19 coerce => 1,
20 );
21  
22 method _build_size() {
23 my ($min_x, $max_x) = minmax map { $_->x } @{ $self->points };
24 my ($min_y, $max_y) = minmax map { $_->y } @{ $self->points };
25  
26 Intertangle::Yarn::Graphene::Size->new(
27 width => $max_x - $min_x,
28 height => $max_y - $min_y,
29 );
30 }
31  
32 method cairo_path( (CairoContext) $cr ) {
33 my @pts = @{ $self->points };
34 $cr->move_to( $pts[0]->x, $pts[0]->y );
35 for my $pt_idx (1..@pts-1) {
36 $cr->line_to(
37 $pts[$pt_idx]->x,
38 $pts[$pt_idx]->y,
39 );
40 }
41 }
42  
43 method render_svg( (SVG) $svg ) {
44 my $path = $svg->get_path(
45 x => [ map { $_->x } @{ $self->points } ],
46 y => [ map { $_->y } @{ $self->points } ],
47 -type => 'polygon',
48 );
49  
50 $svg->polygon(
51 %$path,
52 $self->svg_style_parameter,
53 $self->svg_transform_parameter,
54 );
55 }
56  
57 with qw(
58 Intertangle::Taffeta::Graphics::Role::WithBounds
59 Intertangle::Taffeta::Graphics::Role::WithFill
60 Intertangle::Taffeta::Graphics::Role::WithTransform
61 Intertangle::Taffeta::Graphics::Role::WithStroke
62 Intertangle::Taffeta::Graphics::Role::CairoRenderable::WithCairoPath
63 Intertangle::Taffeta::Graphics::Role::SVGRenderable
64 Intertangle::Taffeta::Graphics::Role::SVGRenderable::Style
65 Intertangle::Taffeta::Graphics::Role::SVGRenderable::Transform
66 );
67  
68 1;
69  
70 __END__