1 package LaTeX::TikZ::Set::Rectangle;
8 LaTeX::TikZ::Set::Rectangle - A set object representing a rectangle.
16 our $VERSION = '0.03';
18 use LaTeX::TikZ::Set::Point;
20 use LaTeX::TikZ::Interface;
21 use LaTeX::TikZ::Functor;
27 This class consumes the L<LaTeX::TikZ::Set::Path> role, and as such implements the L</path> method.
31 with 'LaTeX::TikZ::Set::Path';
37 The first corner of the rectangle, as a L<LaTeX::TikZ::Set::Point> object.
43 isa => 'LaTeX::TikZ::Set::Point',
50 The opposite endpoint of the rectangle, also as a L<LaTeX::TikZ::Set::Point> object.
56 isa => 'LaTeX::TikZ::Set::Point',
63 The algebraic width of the rectangle.
74 The algebraic height of the rectangle.
92 $set->from->path(@_) . ' rectangle ' . $set->to->path(@_);
99 sub begin { $_[0]->from->begin }
105 sub end { $_[0]->to->end }
107 my $meta = __PACKAGE__->meta;
108 my $tc1 = $meta->find_attribute_by_name('from')->type_constraint;
109 my $tc2 = $meta->find_attribute_by_name('to')->type_constraint;
111 around 'BUILDARGS' => sub {
115 if (@_ == 2 and $tc1->check($_[0]) and $tc2->check($_[1])) {
116 my ($from, $to) = @_;
120 width => $to->x - $from->x,
121 height => $to->y - $from->y,
125 if (not exists $args{to} and exists $args{from}) {
126 confess(<<' MSG') unless exists $args{width} and exists $args{height};
127 Attributes 'width' and 'height' are required when 'to' was not given
129 $args{from} = $tc1->coerce($args{from});
130 $meta->find_attribute_by_name($_)->type_constraint->assert_valid($args{$_})
131 for qw<from width height>;
132 my $p = $args{from}->point;
133 $args{to} = LaTeX::TikZ::Point->new(
134 x => $p->x + $args{width},
135 y => $p->y + $args{height},
144 LaTeX::TikZ::Interface->register(
149 my $is_relative = !blessed($q) && ref($q) eq 'HASH';
153 ($is_relative ? (map +($_ => $q->{$_}), qw<width height>) : (to => $q)),
158 LaTeX::TikZ::Functor->default_rule(
159 (__PACKAGE__) => sub {
160 my ($functor, $set, @args) = @_;
161 $set->new(map { $_ => $set->$_->$functor(@args) } qw<from to>)
165 __PACKAGE__->meta->make_immutable;
169 L<LaTeX::TikZ>, L<LaTeX::TikZ::Set::Path>.
173 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
175 You can contact me by mail or on C<irc.perl.org> (vincent).
179 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>.
180 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
184 You can find documentation for this module with the perldoc command.
188 =head1 COPYRIGHT & LICENSE
190 Copyright 2010,2011,2012,2013,2014,2015 Vincent Pit, all rights reserved.
192 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
196 1; # End of LaTeX::TikZ::Set::Rectangle