Math-Geometry-Voronoi
view release on metacpan or search on metacpan
lib/Math/Geometry/Voronoi.pm view on Meta::CPAN
Returns an array ref containing arrays of vertices in the output
diagram. These are the points which connect edges running along the
lines. The data by index:
0: the x value
1: the y value
=head2 edges
Returns an array ref containing arrays of edges in the output diagram.
An edge is defined as a segment of a line running between two
vertices. The data by index:
0: the index of the line
1: the index of vertex 1
2: the index of vertex 2
Either 1 or 2 can be -1 meaning "infinite".
=head2 polygons
@polys = $geo->polygons();
This method attempts to assemble polygons from non-infinite edges in
the diagram. This part of the code is written in Perl and is of my
own invention. I needed this facility in order to color the diagrams
created by this module. It seems to work reasonably well for my uses
but I'm sure it's nowhere near the quality of Steve Fortune's code!
Feedback welcome.
This method returns a reference to an array containing first a point
index and then a list of vertex coordinates. The point is the point
inside the polygon and the vertices are in drawing order for the
closed polygon surrounding the point. For example:
@polys = ( $point_index, [$lat1, $lon1], [$lat2, $lon2], ... );
One optional parameter is available - normalize_vertices. This option
is necessary because the algorithm used needs to match up points from
one edge to another and doing that with floating point numbers
requires some kind of normalization (otherwise 1.1 != 1.10001). For
example, if your coordinates are on an integer grid you might do:
@polys = $geo->polygons(normalize_vertices => sub { int($_[0]) });
Or if you're using floating point and your coordinates are useful down
to 2 decimal places:
@polys = $geo->polygons(normalize_vertices => sub { sprintf("%.2f", $_[0]) });
The point is to produce coordinates in a format where they will
compare as equal textually, side-stepping the problem of comparing
floats numerically.
=head1 TODO
Possible projects, if you're in the mood to help out:
- Add the ability to combine polygons based on a mapping of
same-type points. Map overlays get cluttered by internal lines
with you're coloring multiple polygons the same. All edges
connect exactly two polygons, so this should be relatively easy.
Sadly, my limited math skills have thwarted me on this one - I
spent several days but ultimately couldn't get it working reliably
on all possible shapes.
- Remove the need for the normalize_vertices option to polygons(),
somehow (fuzzy matching?).
- Setup a site where people can play with the module visually and
see purty colors. Could be an excuse to play with the new canvas
stuff in modern browsers.
- Add tests that actually examine the output for sanity. So far the
tests just look at the format and range of the output data - to
see if it's actually doing a decent diagram I look at graphical
output.
=head1 AUTHOR
Sam Tregar <sam@tregar.com>
=head1 COPYRIGHT AND LICENSE
As far as I can tell the underlying C code used here never had a
license attached to it, or if it did I couldn't find any trace of it.
If this worries you please contact Steve and Derek through the links
above.
The Perl and XS code in this library is free software; you can
redistribute it and/or modify it under the same terms as Perl itself,
either Perl version 5.8.5 or, at your option, any later version of
Perl 5 you may have available.
=cut
( run in 2.353 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )