1 package LaTeX::TikZ::Set::Rectangle;
8 LaTeX::TikZ::Set::Rectangle - A set object representing a rectangle.
16 our $VERSION = '0.01';
18 use LaTeX::TikZ::Set::Point;
20 use LaTeX::TikZ::Interface;
21 use LaTeX::TikZ::Functor;
25 with 'LaTeX::TikZ::Set::Op';
29 isa => 'LaTeX::TikZ::Set::Point',
36 isa => 'LaTeX::TikZ::Set::Point',
54 $set->from->path(@_) . ' rectangle ' . $set->to->path(@_);
57 my $meta = __PACKAGE__->meta;
58 my $tc1 = $meta->find_attribute_by_name('from')->type_constraint;
59 my $tc2 = $meta->find_attribute_by_name('to')->type_constraint;
61 around 'BUILDARGS' => sub {
65 if (@_ == 2 and $tc1->check($_[0]) and $tc2->check($_[1])) {
70 width => $to->x - $from->x,
71 height => $to->y - $from->y,
75 if (not exists $args{to} and exists $args{from}) {
76 confess(<<' MSG') unless exists $args{width} and exists $args{height};
77 Attributes 'width' and 'height' are required when 'to' was not given
79 $args{from} = $tc1->coerce($args{from});
80 $meta->find_attribute_by_name($_)->type_constraint->assert_valid($args{$_})
81 for qw/from width height/;
82 my $p = $args{from}->point;
83 $args{to} = LaTeX::TikZ::Point->new(
84 x => $p->x + $args{width},
85 y => $p->y + $args{height},
94 LaTeX::TikZ::Interface->register(
99 my $is_relative = !blessed($q) && ref($q) eq 'HASH';
103 ($is_relative ? (map +($_ => $q->{$_}), qw/width height/) : (to => $q)),
108 LaTeX::TikZ::Functor->default_rule(
109 (__PACKAGE__) => sub {
110 my ($functor, $set, @args) = @_;
111 $set->new(map { $_ => $set->$_->$functor(@args) } qw/from to/)
115 __PACKAGE__->meta->make_immutable;
119 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
121 You can contact me by mail or on C<irc.perl.org> (vincent).
125 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>.
126 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
130 You can find documentation for this module with the perldoc command.
134 =head1 COPYRIGHT & LICENSE
136 Copyright 2010 Vincent Pit, all rights reserved.
138 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
142 1; # End of LaTeX::TikZ::Set::Rectangle