Geometric bewilderment

From: Paul Matthews <plm(at)netspace(dot)net(dot)au>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Geometric bewilderment
Date: 2009-08-19 09:29:43
Message-ID: 4A8BC607.6070306@netspace.net.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

#!/usr/bin/perl
use DBI;
use warnings;
use strict;

my $dbname = shift or die;
my ($dbh, $stm);

$dbh = DBI->connect("dbi:Pg:dbname=$dbname", "", "") or die $!;
$dbh->do(<<EOSQL) or die $!;
DROP TABLE IF EXISTS points;
CREATE TABLE points(
pointpoint point,
pointbox box
);
EOSQL

for( my $i=0; $i<1000; $i++ ) {
my $x = rand(2.0)-1.0;
my $y = rand(2.0)-1.0;
$dbh->do(<<EOSQL) or die $!;
INSERT INTO points VALUES (
Point('$x,$y'),
Box(Point('$x,$y'),Point('$x,$y'))
);
EOSQL
}

check_box_point('<<');
check_box_point('&<');
check_box_point('&&');
check_box_point('&>');
check_box_point('>>');
check_box_point('@>');
check_box_point('&<|');
check_box_point('<<|');
check_box_point('|>>');
check_box_point('|&>');

check_point_box('<<');
check_point_box('&<');
check_point_box('&&');
check_point_box('&>');
check_point_box('>>');
check_point_box('<@');
check_point_box('&<|');
check_point_box('<<|');
check_point_box('|>>');
check_point_box('|&>');

#--------------------------------------------------------------------------
# Check 'box OP point' against 'box OP box(point,point)'
#--------------------------------------------------------------------------
sub check_box_point {
my $op = shift;
print "box $op point\n";

$stm = $dbh->prepare(<<EOSQL) or die $!;
SELECT
pointpoint[0] as x,
pointpoint[1] as y
FROM
points AS p,
box(point('-0.5,-0.5'),point('0.5,0.5')) AS b
WHERE
b $op pointbox
ORDER BY
x, y;
EOSQL

$stm->execute() or die $!;
open FH, ">a.out";
while( my $ref = $stm->fetchrow_hashref() ) {
my $x = $ref->{x};
my $y = $ref->{y};
print FH "$x,$y\n";
}
close FH;

$stm = $dbh->prepare(<<EOSQL) or die $!;
SELECT
pointpoint[0] as x,
pointpoint[1] as y
FROM
points AS p,
box(point('-0.5,-0.5'),point('0.5,0.5')) AS b
WHERE
b $op pointpoint
ORDER BY
x, y;
EOSQL

$stm->execute() or die $!;
open FH, ">b.out";
while( my $ref = $stm->fetchrow_hashref() ) {
my $x = $ref->{x};
my $y = $ref->{y};
print FH "$x,$y\n";
}
close FH;

system( "tkdiff a.out b.out >/dev/null 2>&1" );
}

#--------------------------------------------------------------------------
# Check 'point OP box' against 'box(point,point) OP box'
#--------------------------------------------------------------------------
sub check_point_box {
my $op = shift;
print "point $op box\n";

$stm = $dbh->prepare(<<EOSQL) or die $!;
SELECT
pointpoint[0] as x,
pointpoint[1] as y
FROM
points AS p,
box(point('0.25,0.25'),point('0.75,0.75')) AS b
WHERE
pointbox $op b
ORDER BY
x, y;
EOSQL

$stm->execute() or die $!;
open FH, ">a.out";
while( my $ref = $stm->fetchrow_hashref() ) {
my $x = $ref->{x};
my $y = $ref->{y};
print FH "$x,$y\n";
}
close FH;

$stm = $dbh->prepare(<<EOSQL) or die $!;
SELECT
pointpoint[0] as x,
pointpoint[1] as y
FROM
points AS p,
box(point('0.25,0.25'),point('0.75,0.75')) AS b
WHERE
pointpoint $op b
ORDER BY
x, y;
EOSQL

$stm->execute() or die $!;
open FH, ">b.out";
while( my $ref = $stm->fetchrow_hashref() ) {
my $x = $ref->{x};
my $y = $ref->{y};
print FH "$x,$y\n";
}
close FH;

system( "tkdiff a.out b.out >/dev/null 2>&1" );
}

Attachment Content-Type Size
unknown_filename text/html 4.3 KB
contains.c text/x-csrc 9.7 KB
contains.sql text/x-sql 9.9 KB
test1 text/plain 3.3 KB
test2 text/plain 2.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Magnus Hagander 2009-08-19 09:30:26 Re: BUG #4961: pg_standby.exe crashes with no args
Previous Message Itagaki Takahiro 2009-08-19 08:07:13 FDW-based dblink (WIP)