| 1 | package SVG::Estimate::Role::MakePolygon; | ||
| 2 | $SVG::Estimate::Role::MakePolygon::VERSION = '1.0111'; | ||
| 3 | use strict; | ||
| 4 | use Moo::Role; | ||
| 5 | use Image::SVG::Transform; | ||
| 6 | use SVG::Estimate::Polygon; | ||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | SVG::Estimate::Role::MakePolygon - Approximate shapes that are hard to estimate | ||
| 11 | |||
| 12 | =head1 VERSION | ||
| 13 | |||
| 14 | version 1.0111 | ||
| 15 | |||
| 16 | =head1 METHODS | ||
| 17 | |||
| 18 | =head2 make_polygon ( $args ) | ||
| 19 | |||
| 20 | Class method. | ||
| 21 | |||
| 22 | Make an SVG::Estimate::Polygon out of a set of point approximating the consumer's shape. | ||
| 23 | |||
| 24 | Requires that the consumer provide a C<this_point> method. | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | sub make_polygon { | ||
| 29 | my ($class, $args) = @_; | ||
| 30 | my @points; | ||
| 31 | for (my $t = 0.0; $t <= 1.0; $t += 1/12) { | ||
| 32 | my $point = $class->this_point($args, $t); | ||
| 33 | $point = $args->{transformer}->transform($point); | ||
| 34 | push @points, $point; | ||
| 35 | } | ||
| 36 | my $polygon_points = join ' ', map { join ',', @{ $_ } } @points; | ||
| 37 | ##Have to send in an empty transform object | ||
| 38 | my $littleT = Image::SVG::Transform->new(); | ||
| 39 | return SVG::Estimate::Polygon->new(points => $polygon_points, transformer => $littleT, start_point => $args->{start_point}, ); | ||
| 40 | } | ||
| 41 | |||
| 42 | |||
| 43 | 1; |