The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

SVG::Estimate - Estimates the length of all the vectors in an SVG file.

VERSION

version 1.0107

SYNOPSIS

 my $se = SVG::Estimate->new(
    file_path   => '/path/to/file.svg',
 );

 $se->estimate; # performs all the calculations

 my $length = $se->length;

DESCRIPTION

SVG::Estimate is a suite of modules that allow you to accurately estimate the length of the vectors inside of a Scalable Vector Graphics (SVG) file. It is only an estimate because we lack the math to give absolutely precise lengths of really complex curves in a time-efficient manner. Therefore, we take guesses in some cases, though those guesses are still quite accurate (to within about 0.1%). In a battery of tests against our own equipment, our measurements were more accurate than those provided by the equipment itself.

This is highly useful for any 2 dimensional CNC machines that use vector files to create tool paths, as you may want to know how long a job will take to quote your customer.

INHERITANCE

This class consumes SVG::Estimate::Role::Round.

METHODS

new(properties)

Constructor.

properties

A hash of properties for this class.

file_path

The path to the SVG file.

summarize

Have each parse SVG object emit its starting coordinates, ending coordinates, travel length, shape length and total length, all in pixels.

length()

Returns the length in user units (pixels) of the SVG. This is equivalent of adding travel_length and shape_length together. NOTE: The number of user units within any given element could be variable depending upon how the vector was specified and how the SVG editor exports its documents. For example, if you have a line that is 1 inch long in Adobe Illustrator it will export that as 72 user units, and a 1 inch line in Inkscape will export that as 90 user units.

travel_length()

Returns the length of tool travel in user units that a toolhead would have to move to get into position for the next shape.

shape_length()

Returns the length of the vectors (in user units) that make up the shapes in this document.

shape_count()

The count of all the shapes in this document.

cursor()

Returns a point (an array ref with 2 values) of where the toolhead will be at the end of estimation.

min_x()

Returns the left most x value of the bounding box for this document.

max_x()

Returns the right most x value of the bounding box for this document.

min_y()

Returns the top most y value of the bounding box for this document.

max_y()

Returns the bottom most y value of the bounding box for this document.

read_svg()

Reads in the SVG document specified by file_path in the constructor.

estimate()

Performs all the calculations on this document. NOTE: before estimate() is run, none of the measurements will produce valid values.

sum(elements)

This is used by estimate to do calculations on the various elements of the document. It recurses over a list of elements. This method is likely only useful to you if you want to evaluate only a section of a document.

elements

An array reference of SVG elements as parsed by XML::Hash::LX.

parse_params ( in )

Removes the - added to attributes by XML::Hash::LX and returns a hash with the fixed paramter names.

in

A hash reference of parameters from XML::Hash::LX with the preceeding - on each key.

PREREQS

Moo Math::Trig Image::SVG::Path Image::SVG::Transform Clone List::Util List::MoreUtils Ouch Test::More File::Slurp XML::LibXML XML::Hash::LX

SUPPORT

Repository

http://github.com/rizen/SVG-Estimate

Bug Reports

http://github.com/rizen/SVG-Estimate/issues

AUTHOR

This module was created by JT Smith <jt_at_plainblack_dot_com> and Colin Kuskie <colink_at_plainblack_dot_com>.

LEGAL

SVG::Estimate is Copyright 2016 Plain Black Corporation (http://www.plainblack.com) and is licensed under the same terms as Perl itself.