| 1 | # Copyright 2017, 2018, 2019, 2020, 2021 Kevin Ryde | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # This file is part of Graph-Maker-Other. | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # This file is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 6 | # under the terms of the GNU General Public License as published by the Free | ||||||||||||||||||||||||||||
| 7 | # Software Foundation; either version 3, or (at your option) any later | ||||||||||||||||||||||||||||
| 8 | # version. | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | # This file is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||
| 11 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||||||||||||||||||||||||||
| 12 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||||||||||||||||||||||||||
| 13 | # for more details. | ||||||||||||||||||||||||||||
| 14 | # | ||||||||||||||||||||||||||||
| 15 | # You should have received a copy of the GNU General Public License along | ||||||||||||||||||||||||||||
| 16 | # with Graph-Maker-Other. See the file COPYING. If not, see | ||||||||||||||||||||||||||||
| 17 | # <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | package Graph::Maker::GosperIsland; | ||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use 5.004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Graph::Maker; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use vars '$VERSION','@ISA'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 1 | $VERSION = 19; | |||||||||||||||||||||||||||
| 26 | 1 | @ISA = ('Graph::Maker'); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 7 | ▶ | sub _default_graph_maker { | ||||||||||||||||||||||||||
|
Subroutine
_default_graph_maker: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 7 | require Graph; | |||||||||||||||||||||||||||
| 31 | 7 | return Graph->new(@_); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 7 | ▶ | sub _make_graph { | ||||||||||||||||||||||||||
|
Subroutine
_make_graph: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 34 | 7 | my ($params) = @_; | |||||||||||||||||||||||||||
| 35 | 7 | ▶ | my $graph_maker = delete($params->{'graph_maker'}) || \&_default_graph_maker; | ||||||||||||||||||||||||||
|
Condition50%1/2
delete $params->{'graph_maker'} || \&Graph::Maker::GosperIsland::_default_graph_maker
MC/DC0%0/1
delete $params->{'graph_maker'} || \&Graph::Maker::GosperIsland::_default_graph_maker
delete $params->{'graph_maker'}
Truth table50%1/2
A
A= delete $params->{'graph_maker'}
| |||||||||||||||||||||||||||||
| 36 | 7 | return $graph_maker->(%$params); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 12 | ▶ | sub _mul { | ||||||||||||||||||||||||||
|
Subroutine
_mul: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 40 | 12 | my ($x,$y) = @_; | |||||||||||||||||||||||||||
| 41 | 12 | return ((5*$x - 3*$y)/2, ($x+5*$y)/2); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 4320 | ▶ | sub _add { | ||||||||||||||||||||||||||
|
Subroutine
_add: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 4320 | my ($v, $ax,$ay) = @_; | |||||||||||||||||||||||||||
| 45 | 4320 | my ($x,$y) = split /,/, $v; | |||||||||||||||||||||||||||
| 46 | 4320 | $x += $ax; | |||||||||||||||||||||||||||
| 47 | 4320 | $y += $ay; | |||||||||||||||||||||||||||
| 48 | 4320 | return "$x,$y"; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 2160 | ▶ | sub _rotate_plus60 { | ||||||||||||||||||||||||||
|
Subroutine
_rotate_plus60: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 2160 | my ($x, $y) = @_; | |||||||||||||||||||||||||||
| 52 | 2160 | return (($x-3*$y)/2, # rotate +60 | |||||||||||||||||||||||||||
| 53 | ($x+$y)/2); | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | my @level_0 = ('2,0', '1,1', '-1,1', '-2,0', '-1,-1', '1,-1'); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 7 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=9 SCAR=22.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 7 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 7 | ▶ | my $level = delete($params{'level'}) || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
delete $params{'level'} || 0
MC/DC100%1/1
delete $params{'level'} || 0
delete $params{'level'}
Truth table100%2/2
A
A= delete $params{'level'}
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 7 | my $graph = _make_graph(\%params); | |||||||||||||||||||||||||||
| 64 | 7 | $graph->set_graph_attribute (name => "Gosper Island $level"); | |||||||||||||||||||||||||||
| 65 | 7 | $graph->set_graph_attribute (vertex_name_type_xy => 1); | |||||||||||||||||||||||||||
| 66 | 7 | $graph->set_graph_attribute (vertex_name_type_xy_triangular => 1); | |||||||||||||||||||||||||||
| 67 | 7 | ▶ | my $multiedged = $graph->is_countedged || $graph->is_multiedged; | ||||||||||||||||||||||||||
|
Condition100%3/3
$graph->is_countedged || $graph->is_multiedged
MC/DC100%2/2
$graph->is_countedged || $graph->is_multiedged
$graph->is_countedged
$graph->is_multiedged
Truth table100%3/3
A || B
A= $graph->is_countedgedB= $graph->is_multiedged
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 7 | $graph->add_cycle(@level_0); | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($graph->is_directed) { $graph->add_cycle(reverse @level_0); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 7 | my $cx = 3; | |||||||||||||||||||||||||||
| 73 | 7 | my $cy = 1; | |||||||||||||||||||||||||||
| 74 | 7 | foreach my $i (1 .. $level) { | |||||||||||||||||||||||||||
| 75 | 12 | foreach my $edge ($graph->edges) { | |||||||||||||||||||||||||||
| 76 | 360 | foreach (1 .. 6) { | |||||||||||||||||||||||||||
| 77 | 2160 | my ($u,$v) = @$edge; | |||||||||||||||||||||||||||
| 78 | 2160 | $u = _add($u, $cx,$cy); | |||||||||||||||||||||||||||
| 79 | 2160 | $v = _add($v, $cx,$cy); | |||||||||||||||||||||||||||
| 80 | 2160 | ▶ | if (! $multiedged || ! $graph->has_edge($u,$v)) { # no duplicates | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$multiedged and $graph->has_edge($u, $v)
MC/DC100%2/2
$multiedged and $graph->has_edge($u, $v)
$multiedged
$graph->has_edge($u, $v)
Truth table100%3/3
A and B
A= $multiedgedB= $graph->has_edge($u, $v)
| |||||||||||||||||||||||||||||
| 81 | 2064 | $graph->add_edge($u,$v); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | 2160 | ($cx,$cy) = _rotate_plus60($cx,$cy); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | 12 | ($cx,$cy) = _mul($cx,$cy); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 7 | return $graph; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | Graph::Maker->add_factory_type('Gosper_island' => __PACKAGE__); | |||||||||||||||||||||||||||
| 92 | 1 | 1; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||