]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ/Set/Circle.pm
Remove magic LaTeX::TikZ::Interface->import
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Set / Circle.pm
1 package LaTeX::TikZ::Set::Circle;
2
3 use strict;
4 use warnings;
5
6 =head1 NAME
7
8 LaTeX::TikZ::Set::Circle - A set object representing a circle.
9
10 =head1 VERSION
11
12 Version 0.01
13
14 =cut
15
16 our $VERSION = '0.01';
17
18 use LaTeX::TikZ::Set::Point;
19
20 use LaTeX::TikZ::Interface;
21 use LaTeX::TikZ::Functor;
22
23 use LaTeX::TikZ::Tools;
24
25 use Any::Moose;
26 use Any::Moose 'Util::TypeConstraints';
27
28 with 'LaTeX::TikZ::Set::Op';
29
30 has 'center' => (
31  is       => 'ro',
32  isa      => 'LaTeX::TikZ::Set::Point',
33  required => 1,
34  coerce   => 1,
35 );
36
37 subtype 'LaTeX::TikZ::Set::Circle::Radius'
38      => as 'Num'
39      => where { LaTeX::TikZ::Tools::numcmp($_, 0) >= 1 }
40      => message { "$_ isn't a non-negative real number" };
41
42 has 'radius' => (
43  is       => 'ro',
44  isa      => 'LaTeX::TikZ::Set::Circle::Radius',
45  required => 1,
46 );
47
48 sub path {
49  my $set  = shift;
50  my $tikz = $_[0];
51
52  $set->center->path(@_) . ' circle (' . $tikz->len($set->radius) . ')';
53 }
54
55 LaTeX::TikZ::Interface->register(
56  circle => sub {
57   shift;
58
59   __PACKAGE__->new(center => $_[0], radius => $_[1]);
60  },
61 );
62
63 LaTeX::TikZ::Functor->default_rule(
64  (__PACKAGE__) => sub {
65   my ($functor, $set, @args) = @_;
66   $set->new(
67    center => $set->center->$functor(@args),
68    radius => $set->radius,
69   );
70  }
71 );
72
73 __PACKAGE__->meta->make_immutable;
74
75 =head1 AUTHOR
76
77 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
78
79 You can contact me by mail or on C<irc.perl.org> (vincent).
80
81 =head1 BUGS
82
83 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>.
84 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
85
86 =head1 SUPPORT
87
88 You can find documentation for this module with the perldoc command.
89
90     perldoc LaTeX::TikZ
91
92 =head1 COPYRIGHT & LICENSE
93
94 Copyright 2010 Vincent Pit, all rights reserved.
95
96 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
97
98 =cut
99
100 1; # End of LaTeX::TikZ::Set::Circle