Re: Distance from point to box

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Distance from point to box
Date: 2014-07-30 12:06:02
Message-ID: alpine.DEB.2.10.1407301402570.12870@sto
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


> double dx = 0.0, dy = 0.0;
>
> if (point->x < box->low.x)
> dx = box->low.x - point->x;
> if (point->x > box->high.x)
> dx = point->x - box->high.x;
> if (point->y < box->low.y)
> dy = box->low.y - point->y;
> if (point->y > box->high.y)
> dy = point->y - box->high.y;
> return HYPOT(dx, dy);
>
> I feel myself quite tangled.
> Could anybody clarify it for me? Did I miss something? Thanks.

ISTM that you miss the projection on the segment if dx=0 or dy=0.

--
Fabien.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2014-07-30 13:28:25 Re: Distance from point to box
Previous Message Alexander Korotkov 2014-07-30 11:42:15 Distance from point to box