1 package LaTeX::TikZ::Mod::Pattern::Lines;
8 LaTeX::TikZ::Mod::Pattern::Lines - An hatched pattern modifier.
16 our $VERSION = '0.01';
20 use LaTeX::TikZ::Tools;
23 use Any::Moose 'Util::TypeConstraints';
25 extends 'LaTeX::TikZ::Mod::Pattern';
27 enum 'LaTeX::TikZ::Mod::Pattern::Direction' => (
28 'horizontal', 'vertical', 'north east', 'north west',
33 isa => 'LaTeX::TikZ::Mod::Pattern::Direction',
34 default => 'horizontal',
43 has 'space_width' => (
49 my $W = Sub::Name::subname('WIDTH' => sub { sprintf '#WIDTH=%0.1f#', @_ });
51 my $forge_template = Sub::Name::subname('forge_template' => sub {
52 my ($direction, $line_width, $space_width) = @_;
54 my ($low_left, $up_right, $tile_size, $line_begin, $line_end);
55 my ($width, $half_width, $shadow_min, $shadow_max);
57 $width = $W->($space_width);
58 $half_width = $W->($space_width / 2);
60 $shadow_min = $W->(- $line_width);
61 $shadow_max = $W->($space_width + $line_width);
62 $line_width = $W->($line_width);
64 $low_left = "\\pgfqpoint{$shadow_min}{$shadow_min}";
65 $up_right = "\\pgfqpoint{$shadow_max}{$shadow_max}";
66 $tile_size = "\\pgfqpoint{$width}{$width}";
68 if ($direction =~ /^(?:horizontal|vertical)$/) {
70 if ($direction eq 'horizontal') {
71 $line_begin = "\\pgfqpoint{$shadow_min}{$half_width}";
72 $line_end = "\\pgfqpoint{$shadow_max}{$half_width}";
74 $line_begin = "\\pgfqpoint{$half_width}{$shadow_min}";
75 $line_end = "\\pgfqpoint{$half_width}{$shadow_max}";
78 } elsif ($direction =~ /^north (?:east|west)$/) {
80 if ($direction eq 'north east') {
81 $line_begin = "\\pgfqpoint{$shadow_min}{$shadow_min}";
82 $line_end = "\\pgfqpoint{$shadow_max}{$shadow_max}";
84 $line_begin = "\\pgfqpoint{$shadow_min}{$shadow_max}";
85 $line_end = "\\pgfqpoint{$shadow_max}{$shadow_min}";
93 \\pgfdeclarepatternformonly{#NAME#}{$low_left}{$up_right}{$tile_size}{%
94 \\pgfsetlinewidth{$line_width}
95 \\pgfpathmoveto{$line_begin}
96 \\pgfpathlineto{$line_end}
102 around 'BUILDARGS' => sub {
103 my ($orig, $class, %args);
105 confess('Can\'t specify an explicit template for a '. __PACKAGE__ .' pattern')
106 if exists $args{template};
108 my @params = qw/direction line_width space_width/;
110 my $meta = $class->meta;
112 my $attr = $meta->find_attribute_by_name($_);
113 $args{$_} = $attr->default if $attr->has_default and not exists $args{$_};
114 $attr->type_constraint->assert_valid($args{$_});
117 $args{template} = $forge_template->(@args{@params});
119 $class->$orig(%args);
122 sub tag { join '/', ref $_[0], $_[0]->direction }
125 my ($this, $other) = @_;
127 LaTeX::TikZ::Tools::numeq($this->line_width, $other->line_width) or return 0;
129 my $ratio = $other->space_width / $this->space_width;
131 return LaTeX::TikZ::Tools::numeq($ratio, int $ratio);
134 __PACKAGE__->meta->make_immutable;
138 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
140 You can contact me by mail or on C<irc.perl.org> (vincent).
144 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>.
145 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
149 You can find documentation for this module with the perldoc command.
153 =head1 COPYRIGHT & LICENSE
155 Copyright 2010 Vincent Pit, all rights reserved.
157 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
161 1; # End of LaTeX::TikZ::Mod::Pattern::Lines