]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blob - lib/LaTeX/TikZ/Set/Circle.pm
070cac62cbe335eba304243ad170b53744344338
[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.03
13
14 =cut
15
16 our $VERSION = '0.03';
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 Mouse;
26 use Mouse::Util::TypeConstraints;
27
28 =head1 RELATIONSHIPS
29
30 This class consumes the L<LaTeX::TikZ::Set::Path> role, and as such implements the L</path> method.
31
32 =cut
33
34 with 'LaTeX::TikZ::Set::Path';
35
36 =head1 ATTRIBUTES
37
38 =head2 C<center>
39
40 A L<LaTeX::TikZ::Set::Point> object describing the center of the circle.
41
42 =cut
43
44 has 'center' => (
45  is       => 'ro',
46  isa      => 'LaTeX::TikZ::Set::Point',
47  required => 1,
48  coerce   => 1,
49 );
50
51 =head2 C<radius>
52
53 The radius of the circle as a non-negative real number.
54
55 =cut
56
57 has 'radius' => (
58  is       => 'ro',
59  isa      => subtype('Num' => where { LaTeX::TikZ::Tools::numcmp($_, 0) > 0 }),
60  required => 1,
61 );
62
63 =head1 METHODS
64
65 =head2 C<path>
66
67 =cut
68
69 sub path {
70  my $set  = shift;
71  my $tikz = $_[0];
72
73  $set->center->path(@_) . ' circle (' . $tikz->len($set->radius) . ')';
74 }
75
76 =head2 C<begin>
77
78 =cut
79
80 sub begin { $_[0]->center->begin }
81
82 =head2 C<end>
83
84 =cut
85
86 sub end { $_[0]->center->end }
87
88 LaTeX::TikZ::Interface->register(
89  circle => sub {
90   shift;
91
92   __PACKAGE__->new(center => $_[0], radius => $_[1]);
93  },
94 );
95
96 LaTeX::TikZ::Functor->default_rule(
97  (__PACKAGE__) => sub {
98   my ($functor, $set, @args) = @_;
99   $set->new(
100    center => $set->center->$functor(@args),
101    radius => $set->radius,
102   );
103  }
104 );
105
106 __PACKAGE__->meta->make_immutable;
107
108 =head1 SEE ALSO
109
110 L<LaTeX::TikZ>, L<LaTeX::TikZ::Set>, L<LaTeX::TikZ::Set::Path>.
111
112 =head1 AUTHOR
113
114 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
115
116 You can contact me by mail or on C<irc.perl.org> (vincent).
117
118 =head1 BUGS
119
120 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>.
121 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
122
123 =head1 SUPPORT
124
125 You can find documentation for this module with the perldoc command.
126
127     perldoc LaTeX::TikZ
128
129 =head1 COPYRIGHT & LICENSE
130
131 Copyright 2010,2011,2012,2013,2014,2015 Vincent Pit, all rights reserved.
132
133 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
134
135 =cut
136
137 1; # End of LaTeX::TikZ::Set::Circle