Graphics::Grid::UnitArithmetic - Expression created from Graphics::Grid::Unit objects
version 0.001
use Graphics::Grid::UnitArithmetic; use Graphics::Grid::Unit; my $ua1 = Graphics::Grid::UnitArithmetic->new( node => '+', children => [ Graphics::Grid::Unit->new( [ 1, 2, 3 ], "cm" ), Graphics::Grid::Unit->new(0.5), ], ); my $ua2 = Graphics::Grid::UnitArithmetic->new( Graphics::Grid::Unit->new(0.1, "npc") ); my $ua3 = $ua1 - $ua2; my $ua4 = $ua1 * 2; # or use the function interface use Graphics::Grid::Functions qw(:all); my $ua = unit(2, 'inches') * 2;
You would mostly never directly use this class. See Graphics::Grid::Unit for unit arithmetic on unit objects.
This class Graphics::Grid::UnitArithmetic represents arithmetic on Graphics::Grid::Unit objects. It provides a way to create a unit-like value that combines both relative and absolute values.
Supported operators are +, -, and *. A plus or minus operation requires both its binary operands are consumers of Graphics::Grid::UnitLike. The multiply operation requires one of its operands is consumer of Graphics::Grid::UnitLike, the other a number or array ref of numbers.
+
-
*
It can be one of the followings,
A number or an array ref of numbers. If a single number is given it will be coerced to an array ref that contains the number. This is used for operands of multiplications.
One of "+", "-", "*". In this case the children attr should contain the operands.
"+"
"-"
"*"
children
A Graphics::Grid::Unit object. This is used for operands of plus and minus.
When the object represents an arithmetic operation, this children attribute has the operands.
Number of effective values in the object.
This is an alias of elems().
elems()
This method returns an object of the same Graphics::Grid::UnitArithmetic class. The returned object represents the data at given index, and has at only one value at each node.
# $ua1 has 3 elems: 1cm+0.5npc, 2cm+0.5npc, 3cm+0.5npc my $ua1 = Graphics::Grid::UnitArithmetic->new( node => '+', children => [ Graphics::Grid::Unit->new( [ 1, 2, 3 ], "cm" ), Graphics::Grid::Unit->new(0.5), ], ); # $ua2 has only 2cm+0.5npc my $ua2 = $u1->at(1);
$idx is applied like wrap-indexing. So below is same as above.
$idx
my $ua3 = $ua1->at(4);
Slice by indices.
Returns a string representing the object.
Sum the effective unit vector in a unit object.
Append two UnitLike objects. If both are Graphics::Grid::Unit objects, this method would return a Graphics::Grid::Unit object. Otherwise, it would return a Graphics::Grid::UnitList object.
Insert another UnitLike object after index $after. Insert before first element if after is a negative value.
$after
after
Checks if the object is a Graphics::Grid::Unit.
Checks if the object is an array ref of numbers.
Check is the object is an arithmetic operation. It is equivalent to !($obj-≥is_unit() or $obj-≥is_number()).
!($obj-≥is_unit() or $obj-≥is_number())
Try to reduce the tree by evaluating arithmetics. Returns a new Graphics::Grid::UnitArithmetic or Graphics::Grid::Unit object.
Graphics::Grid
Graphics::Grid::UnitLike
Graphics::Grid::Unit
Forest::Tree
Stephan Loyd <sloyd@cpan.org>
This software is copyright (c) 2018-2023 by Stephan Loyd.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Graphics::Grid, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Graphics::Grid
CPAN shell
perl -MCPAN -e shell install Graphics::Grid
For more information on module installation, please visit the detailed CPAN module installation guide.