Render/Viewport/Clipped.pm

filter: Statementstmt 95.4% 42 / 44 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 5 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 82.4% 61 / 74 CC 7 SCAR 14.7
CC
7
Cov
86%
new
8.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.3
↑ Summary Render/Renderer/SVG.pm »
1 # Encoding and name #_{
2  
3 =encoding utf8
4 =head1 NAME
5  
6 Geo::OSM::Render::Viewport::Clipped - Use a clipped L<<viewport | Geo::OSM::Render::Viewport >> to create a map.
7  
8 =cut
9 package Geo::OSM::Render::Viewport::Clipped;
10 #_}
11 #_{ use …
12 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Geo::OSM::Render::Viewport;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 our @ISA = qw(Geo::OSM::Render::Viewport);
19  
20 #_}
21 3 our $VERSION = 0.01;
22 #_{ Synopsis
23  
24 =head1 SYNOPSIS
25  
26 This class derives from L<<Geo::OSM::Render::Viewporrt>>.
27  
28 =cut
29 #_}
30 #_{ Overview
31  
32 =head1 OVERVIEW
33  
34 See L<Geo::OSM::Render::Viewport/OVERVIEW>.
35  
36 =cut
37  
38 #_}
39 #_{ Methods
40 #_{ POD
41 =head1 METHODS
42 =cut
43 #_}
44 3 ▶sub new { #_{
Subroutine new: called CC=7 SCAR=21.0
Pod documented
45 #_{ POD
46  
47 =head2 new
48  
49 my $proj = Geo::OSM::Render::Viewport::Clipped->new(
50 x_of_map_0 => $x_left ,
51 x_of_map_width => $x_right ,
52 y_of_map_0 => $y_bottom,
53 y_of_map_height => $y_top
54 );
55  
56 =cut
57  
58 #_}
59  
60 3 my $class = shift;
61 3 my $self = $class->SUPER::new();
62 3 my %opts = @_;
63  
64 3 ▶ $self->{x_of_map_0 } = delete $opts{x_of_map_0 } // croak 'x_of_map_0 not given';
Condition50%1/2
delete $opts{"x_of_map_0"} // croak("x_of_map_0 not given")
l!l
30
MC/DC0%0/1
delete $opts{"x_of_map_0"} // croak("x_of_map_0 not given")
delete $opts{"x_of_map_0"}
Truth table50%1/2
A
A= delete $opts{"x_of_map_0"}
Aresult
11
00
65 3 ▶ $self->{x_of_map_width } = delete $opts{x_of_map_width } // croak 'x_of_map_width not given';
Condition50%1/2
delete $opts{"x_of_map_width"} // croak("x_of_map_width not given")
l!l
30
MC/DC0%0/1
delete $opts{"x_of_map_width"} // croak("x_of_map_width not given")
delete $opts{"x_of_map_width"}
Truth table50%1/2
A
A= delete $opts{"x_of_map_width"}
Aresult
11
00
66 3 ▶ $self->{y_of_map_0 } = delete $opts{y_of_map_0 } // croak 'y_of_map_0 not given';
Condition50%1/2
delete $opts{"y_of_map_0"} // croak("y_of_map_0 not given")
l!l
30
MC/DC0%0/1
delete $opts{"y_of_map_0"} // croak("y_of_map_0 not given")
delete $opts{"y_of_map_0"}
Truth table50%1/2
A
A= delete $opts{"y_of_map_0"}
Aresult
11
00
67 3 ▶ $self->{y_of_map_height} = delete $opts{y_of_map_height } // croak 'y_of_map_height not given';
Condition50%1/2
delete $opts{"y_of_map_height"} // croak("y_of_map_height not given")
l!l
30
MC/DC0%0/1
delete $opts{"y_of_map_height"} // croak("y_of_map_height not given")
delete $opts{"y_of_map_height"}
Truth table50%1/2
A
A= delete $opts{"y_of_map_height"}
Aresult
11
00
68  
69 3 ▶ my $max_width_height = delete $opts{max_width_height} // croak 'max_width_height not given';
Condition50%1/2
delete $opts{"max_width_height"} // croak("max_width_height not given")
l!l
30
MC/DC0%0/1
delete $opts{"max_width_height"} // croak("max_width_height not given")
delete $opts{"max_width_height"}
Truth table50%1/2
A
A= delete $opts{"max_width_height"}
Aresult
11
00
70  
71 3 $self->{diff_width } = $self->{x_of_map_width } - $self->{x_of_map_0};
72 3 $self->{diff_height} = $self->{y_of_map_height} - $self->{y_of_map_0};
73  
74 3 ▶ if (abs($self->{diff_width}) > abs($self->{diff_height})) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $self->{'diff_width'} > abs $self->{'diff_height'}) { } 3 0 3
75 3 $self->{map_width } = $max_width_height;
76 3 $self->{map_height} = $max_width_height / abs($self->{diff_width}) * abs($self->{diff_height});
77 }
78 else {
79 0 $self->{map_height} = $max_width_height;
80 0 $self->{map_width } = $max_width_height / abs($self->{diff_height}) * abs($self->{diff_width });
81 }
82  
83  
84 3 return $self;
85  
86 } #_}
87 14 ▶sub x_y_to_map_x_y { #_{
Subroutine x_y_to_map_x_y: called CC=1 SCAR=0.0
Pod documented
88 #_{ POD
89  
90 =head2 x_y_to_map_x_y
91  
92 my ($map_x, $map_y) = $projection->x_y_to_map_x_y($x, $y);
93  
94 =cut
95  
96 #_}
97  
98 14 my $self = shift;
99 14 my $x = shift;
100 14 my $y = shift;
101  
102 14 my $map_x = ( $x - $self->{x_of_map_0} ) / $self->{diff_width } * $self->map_width;
103 14 my $map_y = ( $y - $self->{y_of_map_0} ) / $self->{diff_height} * $self->map_height;
104  
105 14 return ($map_x, $map_y);
106  
107 } #_}
108 16 ▶sub map_width { #_{
Subroutine map_width: called CC=1 SCAR=0.0
Pod documented
109 #_{ POD
110  
111 =head2 map_width
112  
113 Returns the width of the map.
114  
115 =cut
116  
117 #_}
118 16 my $self = shift;
119 16 return abs($self->{map_width});
120 } #_}
121 16 ▶sub map_height { #_{
Subroutine map_height: called CC=1 SCAR=0.0
Pod documented
122 #_{ POD
123  
124 =head2 map_height
125  
126 Returns the height of the map.
127  
128 =cut
129  
130 #_}
131 16 my $self = shift;
132 16 return abs($self->{map_height});
133 } #_}
134 #_}
135 #_{ POD: Author
136  
137 =head1 AUTHOR
138  
139 René Nyffenegger <rene.nyffenegger at adp-gmbh.ch>
140  
141 =cut
142  
143 #_}
144 #_{ POD: Copyright and License
145  
146 =head1 COPYRIGHT AND LICENSE
147 Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved.
148  
149 This program is free software; you can redistribute it and/or modify it
150 under the terms of the the Artistic License (2.0). You may obtain a
151 copy of the full license at: L<http://www.perlfoundation.org/artistic_license_2_0>
152 =cut
153  
154 #_}
155 #_{ POD: Source Code
156  
157 =head1 Source Code
158  
159 The source code is on L<< github|https://github.com/ReneNyffenegger/perl-Geo-OSM-Render >>. Meaningful pull requests are welcome.
160  
161 =cut
162  
163 #_}
164  
165 3 'tq84';
↑ Summary Render/Renderer/SVG.pm »