| 1 | package Math::Geometry::Construction::Draw::SVG; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | extends 'Math::Geometry::Construction::Draw'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use 5.008008; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | C<Math::Geometry::Construction::Draw::SVG> - SVG output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | Version 0.021 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | our $VERSION = '0.021'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ########################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # Generate Output # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ########################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 11 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 11 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 11 | my $bg = delete $args->{background}; # modifies given hash! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | delete $args->{transform}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 11 | $self->_output(SVG->new(%$args)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 11 | $self->_set_background($bg, %$args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 11 | ▶ | sub _set_background { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_background: called CC=6 SCAR=34.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 11 | my ($self, $color, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 11 | ▶ | return if(!$color); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if(ref($color) eq 'ARRAY' and @$color == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $color eq "ARRAY" and @$color == 3
MC/DC0%0/2
ref $color eq "ARRAY" and @$color == 3
ref $color eq "ARRAY"
@$color == 3
Truth table0%0/3
A and B
A= ref $color eq "ARRAY"B= @$color == 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $color = sprintf('rgb(%d, %d, %d)', @$color); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $x = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $y = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $w = $args{width}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $h = $args{height}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if($args{viewBox}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $wsp = qr/\s+|\s*\,\s*/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if($args{viewBox} =~ /^\s*(.*)$wsp(.*)$wsp(.*)$wsp(.*?)\s*$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ($x, $y, $w, $h) = ($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | else { warn "Failed to parse viewBox attribute.\n" } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $self->output->rect('x' => $x, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 'y' => $y, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | width => $w, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | height => $h, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | stroke => 'none', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | fill => $color); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 17 | ▶ | sub process_style { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_style: called CC=5 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 17 | my ($self, $element, %style) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 17 | ▶ | while(my ($key, $value) = each(%style)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 29 | ▶ | if($value and ref($value) eq 'ARRAY' and @$value == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$value and ref $value eq "ARRAY" and @$value == 3
$value and ref $value eq "ARRAY"
MC/DC0%0/3
$value and ref $value eq "ARRAY" and @$value == 3
$value
ref $value eq "ARRAY"
@$value == 3
Truth table25%1/4
A and B and C
A= $valueB= ref $value eq "ARRAY"C= @$value == 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $style{$key} = sprintf('rgb(%d, %d, %d)', @$value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 17 | return %style; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 3 | ▶ | sub line { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
line: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 3 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | $args{style} = {$self->process_style('line', %{$args{style}})} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | ▶ | if($args{style}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | ($args{x1}, $args{y1}) = $self->transform_coordinates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ($args{x1}, $args{y1}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ($args{x2}, $args{y2}) = $self->transform_coordinates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | ($args{x2}, $args{y2}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | $self->output->line(%args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 13 | ▶ | sub circle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
circle: called CC=9 SCAR=33.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 13 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 13 | $args{style} = {$self->process_style('circle', %{$args{style}})} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 13 | ▶ | if($args{style}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ($args{cx}, $args{cy}) = $self->transform_coordinates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 13 | ($args{cx}, $args{cy}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 13 | $args{rx} = $self->transform_x_length($args{r}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 13 | $args{ry} = $self->transform_y_length($args{r}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 13 | delete $args{r}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 13 | ▶ | if(defined($args{x1}) and defined($args{y1}) and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $args{"x1"} and defined $args{"y1"} and defined $args{"x2"} and defined $args{"y2"}
defined $args{"x1"} and defined $args{"y1"} and defined $args{"x2"}
defined $args{"x1"} and defined $args{"y1"}
MC/DC0%0/4
defined $args{"x1"} and defined $args{"y1"} and defined $args{"x2"} and defined $args{"y2"}
defined $args{"x1"}
defined $args{"y1"}
defined $args{"x2"}
defined $args{"y2"}
Truth table20%1/5
A and B and C and D
A= defined $args{"x1"}B= defined $args{"y1"}C= defined $args{"x2"}D= defined $args{"y2"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | defined($args{x2}) and defined($args{y2})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | my @boundary = $self->is_flipped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | ? ([$self->transform_coordinates($args{x2}, $args{y2})], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | [$self->transform_coordinates($args{x1}, $args{y1})]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | : ([$self->transform_coordinates($args{x1}, $args{y1})], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | [$self->transform_coordinates($args{x2}, $args{y2})]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my @phi = map { atan2($boundary[$_]->[1] - $args{cy}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $boundary[$_]->[0] - $args{cx}) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | (0, 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $delta_phi = $phi[1] - $phi[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $delta_phi += 6.28318530717959 if($delta_phi < 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | my $large = $delta_phi > 3.14159265358979 ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | $args{d} = sprintf('M%f %f A%f %f %d %d %f %f', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | @{$boundary[0]}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | $args{rx}, $args{ry}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | $large, 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | @{$boundary[1]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | delete(@args{'cx', 'cy', 'rx', 'ry', 'x1', 'y1', 'x2', 'y2'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $self->output->path(%args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 13 | delete(@args{'x1', 'y1', 'x2', 'y2'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 13 | $self->output->ellipse(%args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | sub text { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
text: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | $args{style} = {$self->process_style('text', %{$args{style}})} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | if($args{style}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | ($args{x}, $args{y}) = $self->transform_coordinates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | ($args{x}, $args{y}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | my $data = delete $args{text}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | my $text = $self->output->text(%args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | $text->cdata($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||