pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: emre@hasegeli.com
Cc: PostgreSQL Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Line intersection point is wrong
Date: Sun, 19 Jun 2016 16:42:24 -0400
Message-ID: <19816.1466368944@sss.pgh.pa.us> (raw)
In-Reply-To: <CAE2gYzzXG4BW7JoBhMFhgYoQxutkz-1CyDqMp5QPtXdE7BY2ww@mail.gmail.com>
References: <CAE2gYzw_-z=V2kh8QqFjenu=8MJXzOP44wRW=AzzeamrmTT1=Q@mail.gmail.com>
	<14750.1466353137@sss.pgh.pa.us>
	<CAE2gYzyi_XkC4YdBj3E+a+7xYfOg0AR=sZsSCEWuYNFVmp+fCw@mail.gmail.com>
	<9953.1466360251@sss.pgh.pa.us>
	<CAE2gYzxrfOaje7D6vWJvs0FnmFE4MEEcfyb=O6EDzgzC64GzxA@mail.gmail.com>
	<18081.1466367402@sss.pgh.pa.us>
	<CAE2gYzzXG4BW7JoBhMFhgYoQxutkz-1CyDqMp5QPtXdE7BY2ww@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Emre Hasegeli <emre@hasegeli.com> writes:
>> You haven't done anything to exclude the possibility that l1->B is zero,
>> so you could be getting zero-divide in the y calculation.

> Ah, yes.  We can use l2 when l1->B is zero.

After working out the algebra by hand, I think the attached is correct
(and it does pass the regression tests, yay).  I also made the
line_parallel and line_perp tests more symmetric and zero-divide-free.

			regards, tom lane

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

fix-parallel-perp-and-intersect.patch (text/x-diff, 2.2K) download diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c index 657bcee..ce796c7 100644 *** a/src/backend/utils/adt/geo_ops.c --- b/src/backend/utils/adt/geo_ops.c *************** line_parallel(PG_FUNCTION_ARGS) *** 1108,1117 **** LINE *l1 = PG_GETARG_LINE_P(0); LINE *l2 = PG_GETARG_LINE_P(1); ! if (FPzero(l1->B)) PG_RETURN_BOOL(FPzero(l2->B)); ! PG_RETURN_BOOL(FPeq(l2->A, l1->A * (l2->B / l1->B))); } Datum --- 1108,1119 ---- LINE *l1 = PG_GETARG_LINE_P(0); LINE *l2 = PG_GETARG_LINE_P(1); ! if (FPzero(l1->A)) /* horizontal? */ ! PG_RETURN_BOOL(FPzero(l2->A)); ! if (FPzero(l1->B)) /* vertical? */ PG_RETURN_BOOL(FPzero(l2->B)); ! PG_RETURN_BOOL(FPeq(l2->A * l1->B, l1->A * l2->B)); } Datum *************** line_perp(PG_FUNCTION_ARGS) *** 1120,1131 **** LINE *l1 = PG_GETARG_LINE_P(0); LINE *l2 = PG_GETARG_LINE_P(1); ! if (FPzero(l1->A)) PG_RETURN_BOOL(FPzero(l2->B)); ! else if (FPzero(l1->B)) PG_RETURN_BOOL(FPzero(l2->A)); ! PG_RETURN_BOOL(FPeq(((l1->A * l2->B) / (l1->B * l2->A)), -1.0)); } Datum --- 1122,1133 ---- LINE *l1 = PG_GETARG_LINE_P(0); LINE *l2 = PG_GETARG_LINE_P(1); ! if (FPzero(l1->A)) /* horizontal? */ PG_RETURN_BOOL(FPzero(l2->B)); ! if (FPzero(l1->B)) /* vertical? */ PG_RETURN_BOOL(FPzero(l2->A)); ! PG_RETURN_BOOL(FPeq(l2->A * l1->B, -(l1->A * l2->B))); } Datum *************** line_interpt_internal(LINE *l1, LINE *l2 *** 1233,1250 **** if (FPzero(l1->B)) /* l1 vertical? */ { ! x = l1->C; ! y = (l2->A * x + l2->C); } else if (FPzero(l2->B)) /* l2 vertical? */ { ! x = l2->C; ! y = (l1->A * x + l1->C); } else { ! x = (l1->C - l2->C) / (l2->A - l1->A); ! y = (l1->A * x + l1->C); } result = point_construct(x, y); --- 1235,1252 ---- if (FPzero(l1->B)) /* l1 vertical? */ { ! x = -(l1->C / l1->A); ! y = -(l2->A * x + l2->C) / l2->B; } else if (FPzero(l2->B)) /* l2 vertical? */ { ! x = -(l2->C / l2->A); ! y = -(l1->A * x + l1->C) / l1->B; } else { ! x = (l1->B * l2->C - l2->B * l1->C) / (l1->A * l2->B - l2->A * l1->B); ! y = -(l1->A * x + l1->C) / l1->B; } result = point_construct(x, y);

view thread (13+ messages)  latest in thread

Message-ID: <19816.1466368944@sss.pgh.pa.us>
Permalink:  ../19816.1466368944@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19816.1466368944@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, emre@hasegeli.com
  Subject: Re: Line intersection point is wrong
  In-Reply-To: <19816.1466368944@sss.pgh.pa.us>
  References: <CAE2gYzw_-z=V2kh8QqFjenu=8MJXzOP44wRW=AzzeamrmTT1=Q@mail.gmail.com> <14750.1466353137@sss.pgh.pa.us> <CAE2gYzyi_XkC4YdBj3E+a+7xYfOg0AR=sZsSCEWuYNFVmp+fCw@mail.gmail.com> <9953.1466360251@sss.pgh.pa.us> <CAE2gYzxrfOaje7D6vWJvs0FnmFE4MEEcfyb=O6EDzgzC64GzxA@mail.gmail.com> <18081.1466367402@sss.pgh.pa.us> <CAE2gYzzXG4BW7JoBhMFhgYoQxutkz-1CyDqMp5QPtXdE7BY2ww@mail.gmail.com> <19816.1466368944@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox