Ну коль все просто, тогда так:
PolygonTree.pl
#!/usr/bin/perl -w
use PolygonTree;
my @poly;
while (<STDIN>) {
chop;
if ($_ eq '') {
last;
} else {
push @poly, [split];
};
};
# создаём объект
my $bound = PolygonTree->new(\@poly);
$|++; # включаем autoflush чтобы вывод отдавался сразу
while (<STDIN>) {
chop;
# проверяем вхождение
if ($bound->contains([split])) {
print "Y\n";
} else {
print "N\n";
};
};
PolygonTree.php
<?php
class PolygonTree {
private $pipes;
function __construct($poly) {
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$this->process = proc_open('./PolygonTree.pl', $descriptorspec, $this->pipes);
foreach ($poly as $p) {
fwrite($this->pipes[0], join(' ', $p) . "\n");
};
fputs($this->pipes[0], "\n");
}
function contains($point) {
fputs($this->pipes[0], join(' ', $point). "\n");
$r = fgets($this->pipes[1]);
return substr($r, 0, 1) == 'Y'? True : False;
}
function __destruct() {
fclose($this->pipes[0]);
fclose($this->pipes[1]);
fclose($this->pipes[2]);
}
}
$pt = new PolygonTree(array(
array(1,1),
array(1,2),
array(2,2),
array(2,1),
array(1,1)
));
var_dump($pt->contains(array(0.5,0.5)));
var_dump($pt->contains(array(1.5,1.5)));
?>
В виндах могут быть проблемы из за другого переноса строк и в proc_open, может быть по другому надо будет написать.
Что будет по производительности - непонятно.
liosha, в строку 25 вроде как закралась синтаксическая ошибка: unless $chain_ref->[0] ~~ $chain_ref->[-1];
Наверное вместо ~~ имелось ввиду == ? Мой перл такого оператора не знает.
Еще у GPC лицензия плохая, не совместимая с GPL. А с geos-ом, на котором я так понимаю postgis бегает мутить никто не пробовал?