1 package LaTeX::TikZ::Mod::Pattern::Dots;
8 LaTeX::TikZ::Mod::Pattern::Dots - A dotted pattern modifier.
16 our $VERSION = '0.01';
21 use Any::Moose 'Util::TypeConstraints';
23 extends 'LaTeX::TikZ::Mod::Pattern';
27 isa => subtype('Num' => where { LaTeX::TikZ::Tools::numcmp($_, 0) >= 0 }),
31 has 'space_width' => (
33 isa => subtype('Num' => where { LaTeX::TikZ::Tools::numcmp($_, 0) >= 0 }),
37 my $W = Sub::Name::subname('WIDTH' => sub { sprintf '#WIDTH=%0.1f#', @_ });
39 my $forge_template = Sub::Name::subname('forge_template' => sub {
40 my ($dot_width, $space_width) = @_;
42 my ($low_left, $up_right, $tile_size, $center);
43 my ($width, $half_width, $shadow_min, $shadow_max);
45 $width = $W->($space_width);
46 $half_width = $W->($space_width / 2);
48 $shadow_min = $W->(- $dot_width);
49 $shadow_max = $W->($space_width + $dot_width);
50 $dot_width = $W->($dot_width);
52 $low_left = "\\pgfqpoint{$shadow_min}{$shadow_min}";
53 $up_right = "\\pgfqpoint{$shadow_max}{$shadow_max}";
54 $center = "\\pgfqpoint{$half_width}{$half_width}";
55 $tile_size = "\\pgfqpoint{$width}{$width}";
58 "\\pgfdeclarepatternformonly{#NAME#}{$low_left}{$up_right}{$tile_size}{",
59 "\\pgfpathcircle{$center}{$dot_width}",
65 around 'BUILDARGS' => sub {
66 my ($orig, $class, %args) = @_;
68 confess('Can\'t specify an explicit template for a '. __PACKAGE__ .' pattern')
69 if exists $args{template};
71 my @params = qw/dot_width space_width/;
73 my $meta = $class->meta;
75 my $attr = $meta->find_attribute_by_name($_);
76 $args{$_} = $attr->default if $attr->has_default and not exists $args{$_};
77 $attr->type_constraint->assert_valid($args{$_});
80 $args{template} = $forge_template->(@args{@params});
85 __PACKAGE__->meta->make_immutable;
89 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
91 You can contact me by mail or on C<irc.perl.org> (vincent).
95 Please report any bugs or feature requests to C<bug-latex-tikz at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=LaTeX-TikZ>.
96 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
100 You can find documentation for this module with the perldoc command.
104 =head1 COPYRIGHT & LICENSE
106 Copyright 2010 Vincent Pit, all rights reserved.
108 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
112 1; # End of LaTeX::TikZ::Mod::Pattern::Dots