Math-Polygon-Tree

 view release on metacpan or  search on metacpan

t/contains_rough.t  view on Meta::CPAN

#!/usr/bin/perl

use 5.010;
use strict;
use warnings;
use utf8;

use Test::More;

use Math::Polygon::Tree;


our @TESTS = (
    [
        box => [[61.3124124,56.7182618],[61.4764193,56.7182618],[61.4764193,56.7834254],[61.3124124,56.7834254]],
        [
            [[
                [61.4257797,56.8012777],
                [61.430064,56.793951],
                [61.4301352,56.7934636],
                [61.4294233,56.7922744],
                [61.4244314,56.7877143],
                [61.4176514,56.7814138],
                [61.4168334,56.7800624],
                [61.416783,56.7797039],
                [61.4169592,56.7793936],
                [61.4166194,56.779166],
                [61.4165313,56.7780973],
                [61.4169718,56.7768354],
                [61.4180887,56.7740825],
                [61.4336248,56.7824644],
                [61.4289583,56.799911],
                [61.4257797,56.8012777],
            ]],
            undef, 'crosses'
        ],
    ],
    [
        pp => [[0,0],[4,0],[4,2],[2,3],[0,3]],
        [ [[[1,1],[2,2]]], 1, 'inside' ],
        [ [[[1,1],[2,2]]], 1, 'inside and touch boundary' ],
        [ [[[5,5],[6,6]]], 0, 'outside' ],
        [ [[[1,1],[3,2.2]]], undef, 'doubt' ],
        [ [[[1,1],[3,2.2]], inaccurate=>1], 1, 'inaccurate' ],
    ],
    [
        poly_file => \*DATA,
        [ [[[35.2284227,54.7442032],[35.2280966,54.7442021],[35.2280953,54.7443255],[35.2284214,54.7443267]]],
            , 1, 'inside' ],
        [ [[[35.2209694,54.7197187],[35.2229855,54.7201828],[35.2237598,54.7198791],[35.2216122,54.7190521],[35.2209694,54.7197187]]],
            , undef, 'doubt' ],
    ],
);


for my $item ( @TESTS ) {
    my ($case, $contour, @tests) = @$item;
    my $t = Math::Polygon::Tree->new($contour, {prepare_rough=>1});

    for my $test ( @tests ) { 
        my ($in, $expected, $name) = @$test;
        my $got = $t->contains_polygon_rough(@$in);
        is( $got, $expected, "$case: $name" );
    }
}


done_testing();



__DATA__
city

1
   35.2113957   54.7512731 
   35.2174137   54.7534097 
   35.2188157   54.7536475 
   35.2206193   54.7535706 
   35.2219572   54.7535626 
   35.2238047   54.7538698 
   35.2272283   54.7547773 
   35.2301853   54.7552213 
   35.2321415   54.7554494 
   35.2323299   54.7553213 
   35.2324926   54.7552228 
   35.2325652   54.755199  
   35.2326535   54.7551889 
   35.232679    54.7551707 
   35.2326892   54.7551215 
   35.2326552   54.7550503 
   35.2325646   54.7549873 
   35.2325636   54.7549525 
   35.2325985   54.7549347 
   35.2327227   54.7547756 
   35.2327987   54.7547303 
   35.232958    54.7547289 
   35.2330806   54.7547515 
   35.2331518   54.7547549 
   35.233186    54.7547388 
   35.2331934   54.7547077 
   35.2331468   54.7546525 
   35.2331395   54.754603  
   35.2329678   54.7545124 
   35.2329458   54.7544657 
   35.2329997   54.7543794 
   35.233012    54.7543271 
   35.2329825   54.7542988 
   35.2330306   54.7542327 
   35.2331198   54.7542309 
   35.2331934   54.7542606 
   35.2332816   54.754395  
   35.2334925   54.7544049 
   35.23362     54.7544063 
   35.2336788   54.7543865 
   35.2337107   54.7543469 
   35.2337475   54.7542479 
   35.2338038   54.75418   



( run in 0.659 second using v1.01-cache-2.11-cpan-df04353d9ac )