From: Vincent Pit Date: Tue, 1 Feb 2011 13:20:52 +0000 (+0100) Subject: Introduce LaTeX::TikZ::Mod::Scale X-Git-Tag: rt87282~14 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=0fb9961e1a5172180e428b49f67e2120835c9e3c;p=perl%2Fmodules%2FLaTeX-TikZ.git Introduce LaTeX::TikZ::Mod::Scale --- diff --git a/MANIFEST b/MANIFEST index d8f33ed..bfb95b9 100644 --- a/MANIFEST +++ b/MANIFEST @@ -19,6 +19,7 @@ lib/LaTeX/TikZ/Mod/Pattern.pm lib/LaTeX/TikZ/Mod/Pattern/Dots.pm lib/LaTeX/TikZ/Mod/Pattern/Lines.pm lib/LaTeX/TikZ/Mod/Raw.pm +lib/LaTeX/TikZ/Mod/Scale.pm lib/LaTeX/TikZ/Mod/Width.pm lib/LaTeX/TikZ/Point.pm lib/LaTeX/TikZ/Point/Math/Complex.pm diff --git a/lib/LaTeX/TikZ.pm b/lib/LaTeX/TikZ.pm index 1d2306c..69a55c8 100644 --- a/lib/LaTeX/TikZ.pm +++ b/lib/LaTeX/TikZ.pm @@ -268,6 +268,13 @@ Layers can also be directly applied to sets with the C<< ->layer >> method. ->mod(Tikz->pattern(class => 'Dots')) ->layer('top'); +=head3 C<< Tikz->scale($factor) >> + +Creates a L object that scales the sets onto which it apply by the given C<$factor>. + + my $circle_of_radius_2 = Tikz->circle(0 => 1) + ->mod(Tikz->scale(2)); + =head3 C<< Tikz->width($line_width) >> Creates a L object that sets the line width to C<$line_width> when applied. diff --git a/lib/LaTeX/TikZ/Interface.pm b/lib/LaTeX/TikZ/Interface.pm index b735828..21f7cd6 100644 --- a/lib/LaTeX/TikZ/Interface.pm +++ b/lib/LaTeX/TikZ/Interface.pm @@ -86,6 +86,7 @@ sub load { require LaTeX::TikZ::Mod::Clip; # clip require LaTeX::TikZ::Mod::Layer; # layer + require LaTeX::TikZ::Mod::Scale; # scale require LaTeX::TikZ::Mod::Width; # width require LaTeX::TikZ::Mod::Color; # color require LaTeX::TikZ::Mod::Fill; # fill diff --git a/lib/LaTeX/TikZ/Mod/Scale.pm b/lib/LaTeX/TikZ/Mod/Scale.pm new file mode 100644 index 0000000..51c79e9 --- /dev/null +++ b/lib/LaTeX/TikZ/Mod/Scale.pm @@ -0,0 +1,109 @@ +package LaTeX::TikZ::Mod::Scale; + +use strict; +use warnings; + +=head1 NAME + +LaTeX::TikZ::Mod::Scale - A modifier that scales a TikZ set tree. + +=head1 VERSION + +Version 0.02 + +=cut + +our $VERSION = '0.02'; + +use LaTeX::TikZ::Interface; + +use LaTeX::TikZ::Tools; + +use Any::Moose; + +=head1 RELATIONSHIPS + +This class consumes the L role, and as such implements the L, L, L and L methods. + +=cut + +with 'LaTeX::TikZ::Mod'; + +=head1 ATTRIBUTES + +=head2 C + +=cut + +has 'scale' => ( + is => 'ro', + isa => 'Num', + required => 1, +); + +=head1 METHODS + +=head2 C + +=cut + +sub tag { ref $_[0] } + +=head2 C + +=cut + +sub covers { LaTeX::TikZ::Tools::numeq($_[0]->scale, $_[1]->scale) } + +=head2 C + +=cut + +sub declare { } + +=head2 C + +=cut + +sub apply { sprintf 'scale=%0.3f', $_[0]->scale } + +LaTeX::TikZ::Interface->register( + scale => sub { + shift; + + __PACKAGE__->new(scale => $_[0]); + }, +); + +__PACKAGE__->meta->make_immutable; + +=head1 SEE ALSO + +L, L. + +=head1 AUTHOR + +Vincent Pit, C<< >>, L. + +You can contact me by mail or on C (vincent). + +=head1 BUGS + +Please report any bugs or feature requests to C, or through the web interface at L. +I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc LaTeX::TikZ + +=head1 COPYRIGHT & LICENSE + +Copyright 2011 Vincent Pit, all rights reserved. + +This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. + +=cut + +1; # End of LaTeX::TikZ::Mod::Scale diff --git a/t/00-load.t b/t/00-load.t index 061b3bb..e8ec3aa 100644 --- a/t/00-load.t +++ b/t/00-load.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 35; +use Test::More tests => 36; BEGIN { use_ok( 'LaTeX::TikZ' ); @@ -22,6 +22,7 @@ BEGIN { use_ok( 'LaTeX::TikZ::Mod::Pattern::Dots' ); use_ok( 'LaTeX::TikZ::Mod::Pattern::Lines' ); use_ok( 'LaTeX::TikZ::Mod::Raw' ); + use_ok( 'LaTeX::TikZ::Mod::Scale' ); use_ok( 'LaTeX::TikZ::Mod::Width' ); use_ok( 'LaTeX::TikZ::Point' ); use_ok( 'LaTeX::TikZ::Point::Math::Complex' ); diff --git a/t/01-api.t b/t/01-api.t index 3e2f354..6e96183 100644 --- a/t/01-api.t +++ b/t/01-api.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 5 + 22 + 12; +use Test::More tests => 5 + 23 + 12; use LaTeX::TikZ; @@ -35,7 +35,7 @@ my @methods = qw< point line polyline closed_polyline rectangle circle arc arrow raw_mod clip layer - width color fill pattern + scale width color fill pattern >; for (@methods) { diff --git a/t/20-mod.t b/t/20-mod.t index c2c54f8..191c150 100644 --- a/t/20-mod.t +++ b/t/20-mod.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 20 + 2 * 22; +use Test::More tests => 23 + 2 * 24; use LaTeX::TikZ; @@ -50,6 +50,33 @@ eval { }; like $@, failed_valid('LaTeX::TikZ::Mod'), 'trying to use a non LTM mod croaks'; +my $scale = eval { + Tikz->scale(2); +}; +is $@, '', 'creating a scale mod doesn\'t croak'; + +$foo2 = eval { + Tikz->raw('foo') + ->mod($scale); +}; +is $@, '', 'applying a scale mod doesn\'t croak'; + +check $foo2, 'a raw set with a scale mod', <<'RES'; +\draw [scale=2.000] foo ; +RES + +$foo2 = eval { + Tikz->union( + Tikz->raw('foo') + ->mod($scale), + )->mod(Tikz->scale(4)); +}; +is $@, '', 'applying two scale mods doesn\'t croak'; + +check $foo2, 'a union of a raw set with two scale mods', <<'RES'; +\draw [scale=4.000] foo ; +RES + my $width = eval { Tikz->width(25); }; diff --git a/t/92-pod-coverage.t b/t/92-pod-coverage.t index 98b3e1f..bb340b6 100644 --- a/t/92-pod-coverage.t +++ b/t/92-pod-coverage.t @@ -15,7 +15,7 @@ my $min_pc = 0.18; eval "use Pod::Coverage $min_pc"; plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" if $@; -plan tests => 35; +plan tests => 36; my $moose_private = { also_private => [ qr/^BUILD$/, qr/^DEMOLISH$/ ] }; @@ -37,6 +37,7 @@ pod_coverage_ok( 'LaTeX::TikZ::Mod::Pattern' ); pod_coverage_ok( 'LaTeX::TikZ::Mod::Pattern::Dots' ); pod_coverage_ok( 'LaTeX::TikZ::Mod::Pattern::Lines' ); pod_coverage_ok( 'LaTeX::TikZ::Mod::Raw' ); +pod_coverage_ok( 'LaTeX::TikZ::Mod::Scale' ); pod_coverage_ok( 'LaTeX::TikZ::Mod::Width' ); pod_coverage_ok( 'LaTeX::TikZ::Point' ); pod_coverage_ok( 'LaTeX::TikZ::Point::Math::Complex' );