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