Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Max Maischein
committed
Jun 4, 2011
1 parent
dca1632
commit d48428e
Showing
12 changed files
with
437 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TO DO: | ||
|
||
0.01 20110603 | ||
. Released on an unsuspecting world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.gitignore | ||
bin/random-poissondisc.pl | ||
Changes | ||
lib/Random/PoissonDisc.pm | ||
Makefile.PL | ||
MANIFEST This list of files | ||
MANIFEST.skip | ||
README | ||
t/01-random-unit-vector.t | ||
t/99-changes.t | ||
t/99-examples.t | ||
t/99-manifest.t | ||
t/99-pod.t | ||
t/99-todo.t | ||
t/99-unix-text.t | ||
t/99-versions.t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.cvsignore$ | ||
^.git/ | ||
^.lwpcookies | ||
^.releaserc | ||
^blib/ | ||
^Random-PoissonDisc-.* | ||
CVS/ | ||
^pm_to_blib | ||
.tar.gz$ | ||
.old$ | ||
^Makefile$ | ||
^cvstest$ | ||
^blibdirs$ | ||
.bak$ | ||
^cover_db/ | ||
^db/ | ||
^documents/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
NAME | ||
Random::PoissonDisc - distribute points aesthetically in R^n | ||
|
||
SYNOPSIS | ||
my $points = Random::PoissonDisc->points( | ||
dimensions => [100,100], | ||
r => $r, | ||
); | ||
print join( ",", @$_),"\n" | ||
for @$points; | ||
|
||
This module allows relatively fast (O(N)) generation of random points in | ||
*n*-dimensional space with a distance of at least `r' between each | ||
other. This distribution results in aesthetic so called "blue noise". | ||
|
||
The algorithm was adapted from a sketch by Robert Bridson in | ||
http://www.cs.ubc.ca/~rbridson/docs/bridson-siggraph07-poissondisk.pdf. | ||
|
||
DATA REPRESENTATION | ||
All vectors (or points) are represented as anonymous arrays of numbers. | ||
All have the same dimension as the cardinality of the `dimensions' array | ||
passed in the `->points' method. | ||
|
||
USER INTERFACE | ||
`Random::PoissonDisc->points( %options )' | ||
Returns a reference to an array of points. | ||
|
||
Acceptable options are: | ||
|
||
* `<r'> - minimum distance between points. | ||
|
||
Default is 10 units. | ||
|
||
* `<dimensions'> - number of dimensions and respective value range as | ||
an arrayref. | ||
|
||
Default is | ||
|
||
[ 100, 100 ] | ||
|
||
meaning all points will be in R^2 , with each coordinate in the | ||
range [0, 100). | ||
|
||
* `<candidates'> - Number of candidates to inspect before deciding | ||
that no ew neighbours can be placed around a point. | ||
|
||
Default is 30. | ||
|
||
This number may or may not need to be tweaked if you go further up | ||
in dimensionality beyond 3 dimensions. The more candidates you | ||
inspect the longer the algorithm will run for generating a number of | ||
points. | ||
|
||
In the algorithm description, this constant is named *k*. | ||
|
||
INTERNAL SUBROUTINES | ||
These subroutines are used for the algorithm. If you want to port this | ||
module to PDL or any other vector library, you will likely have to | ||
rewrite these. | ||
|
||
`rnd( $low, $high )' | ||
print rnd( 0, 1 ); | ||
|
||
Returns a uniform distributed random number in `[ $low, $high )'. | ||
|
||
`grid_coords( $grid_size, $point )' | ||
Returns the string representing the coordinates of the grid cell in | ||
which `$point' falls. | ||
|
||
`norm( @vector )' | ||
print norm( 1,1 ); # 1.4142 | ||
|
||
Returns the Euclidean length of the vector, passed in as array. | ||
|
||
`vdist( $l, $r )' | ||
print vdist( [1,0], [0,1] ); # 1.4142 | ||
|
||
Returns the Euclidean distance between two points (or vectors) | ||
|
||
`neighbour_points( $size, $point, $grid )' | ||
my @neighbours = neighbour_points( $size, $p, \%grid ) | ||
|
||
Returns the points from the grid that have a distance between 0 and 2r | ||
around `$point'. These points are the candidates to check when trying to | ||
insert a new random point into the space. | ||
|
||
`random_unit_vector( $dimensions )' | ||
print join ",", @{ random_unit_vector( 2 ) }; | ||
|
||
Returns a vector of unit lenght poiting in a random uniform distributed | ||
*n*-dimensional direction angle and returns a unit vector pointing in | ||
that direction | ||
|
||
The algorithm used is outlined in Knuth, _The Art of Computer | ||
Programming_, vol. 2, 3rd. ed., section 3.4.1.E.6. but has not been | ||
verified formally or mathematically by the module author. | ||
|
||
TODO | ||
The module does not use PDL or any other vector library. | ||
|
||
REPOSITORY | ||
The public repository of this module is | ||
http://github.com/Corion/random-poissondisc. | ||
|
||
SUPPORT | ||
The public support forum of this module is http://perlmonks.org/. | ||
|
||
BUG TRACKER | ||
Please report bugs in this module via the RT CPAN bug queue at | ||
https://rt.cpan.org/Public/Dist/Display.html?Name=Random-PoissonDisc or | ||
via mail to random-poissondisc@rt.cpan.org. | ||
|
||
AUTHOR | ||
Max Maischein `corion@cpan.org' | ||
|
||
COPYRIGHT (c) | ||
Copyright 2011 by Max Maischein `corion@cpan.org'. | ||
|
||
LICENSE | ||
This module is released under the same terms as Perl itself. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!perl -w | ||
use warnings; | ||
use strict; | ||
use File::Find; | ||
use Test::More tests => 2; | ||
|
||
=head1 PURPOSE | ||
This test ensures that the Changes file | ||
mentions the current version and that a | ||
release date is mentioned as well | ||
=cut | ||
|
||
my $module = 'WWW::Mechanize::Firefox'; | ||
|
||
(my $file = $module) =~ s!::!/!g; | ||
require "$file.pm"; | ||
|
||
my $version = sprintf '%0.2f', $module->VERSION; | ||
diag "Checking for version " . $version; | ||
|
||
my $changes = do { local $/; open my $fh, 'Changes' or die $!; <$fh> }; | ||
|
||
ok $changes =~ /^(.*$version.*)$/m, "We find version $version"; | ||
my $changes_line = $1; | ||
ok $changes_line =~ /$version\s+20\d{6}/, "We find a release date on the same line" | ||
or diag $changes_line; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!perl -w | ||
|
||
use warnings; | ||
use strict; | ||
use Test::More; | ||
use File::Find; | ||
|
||
plan 'no_plan'; | ||
|
||
sub check { | ||
return if (! m{\.pl \z}xms); | ||
my $output = `"$^X" -c $_ 2>&1`; | ||
like( $output, qr/$_ syntax OK/, "$_ compiles" ) | ||
} | ||
|
||
find({wanted => \&check, no_chdir => 1}, 'examples'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use strict; | ||
use Test::More; | ||
|
||
# Check that MANIFEST and MANIFEST.skip are sane : | ||
|
||
use File::Find; | ||
use File::Spec; | ||
|
||
my @files = qw( MANIFEST MANIFEST.skip ); | ||
plan tests => scalar @files * 4 | ||
+1 # MANIFEST existence check | ||
; | ||
|
||
for my $file (@files) { | ||
ok(-f $file, "$file exists"); | ||
open F, "<$file" | ||
or die "Couldn't open $file : $!"; | ||
my @lines = <F>; | ||
is_deeply([grep(/^$/, @lines)],[], "No empty lines in $file"); | ||
is_deeply([grep(/^\s+$/, @lines)],[], "No whitespace-only lines in $file"); | ||
is_deeply([grep(/^\s*\S\s+$/, @lines)],[],"No trailing whitespace on lines in $file"); | ||
|
||
if ($file eq 'MANIFEST') { | ||
chomp @lines; | ||
is_deeply([grep { s/\s.*//; ! -f } @lines], [], "All files in $file exist") | ||
or do { diag "$_ is mentioned in $file but doesn't exist on disk" for grep { ! -f } @lines }; | ||
}; | ||
|
||
close F; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use Test::More; | ||
|
||
# Check our Pod | ||
# The test was provided by Andy Lester, | ||
# who stole it from Brian D. Foy | ||
# Thanks to both ! | ||
|
||
use File::Spec; | ||
use File::Find; | ||
use strict; | ||
|
||
eval { | ||
require Test::Pod; | ||
Test::Pod->import; | ||
}; | ||
|
||
my @files; | ||
|
||
if ($@) { | ||
plan skip_all => "Test::Pod required for testing POD"; | ||
} | ||
elsif ($Test::Pod::VERSION < 0.95) { | ||
plan skip_all => "Test::Pod 0.95 required for testing POD"; | ||
} | ||
else { | ||
my $blib = File::Spec->catfile(qw(blib lib)); | ||
find(\&wanted, grep { -d } ($blib, 'bin')); | ||
plan tests => scalar @files; | ||
foreach my $file (@files) { | ||
pod_file_ok($file); | ||
} | ||
} | ||
|
||
sub wanted { | ||
push @files, $File::Find::name if /\.p(l|m|od)$/; | ||
} |
Oops, something went wrong.