Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WEXTK-0008Qa-0D for pgsql-bugs@arkaria.postgresql.org; Sat, 15 Feb 2014 05:07:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WEXTJ-0005ff-GR for pgsql-bugs@arkaria.postgresql.org; Sat, 15 Feb 2014 05:07:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WEXTI-0005fL-Pa for pgsql-bugs@postgresql.org; Sat, 15 Feb 2014 05:07:24 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WEXTG-0002Il-18 for pgsql-bugs@postgresql.org; Sat, 15 Feb 2014 05:07:24 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1WEXTE-0002ua-Ej; Sat, 15 Feb 2014 00:07:20 -0500 Date: Sat, 15 Feb 2014 00:07:20 -0500 From: Bruce Momjian To: Tom Lane Cc: Josef Grahn , pgsql-bugs@postgresql.org Subject: Re: Bad behaviour on some geometric operations on degenerate polygons Message-ID: <20140215050720.GE15047@momjian.us> References: <20140215045525.GC15047@momjian.us> <1550.1392440409@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="mSxgbZZZvrAyzONB" Content-Disposition: inline In-Reply-To: <1550.1392440409@sss.pgh.pa.us> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --mSxgbZZZvrAyzONB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Feb 15, 2014 at 12:00:09AM -0500, Tom Lane wrote: > Bruce Momjian writes: > > What is odd however, is that we allow _explicit_ creation of zero-radius > > circles: > > > test=> SELECT circle '<(1,1),0>'; > > circle > > ----------- > > <(1,1),0> > > (1 row) > > > so why do we prevent the conversion of single-point polygons to circles > > with zero radius? I don't know. > > Maybe we should rethink that. What you've done here seems like a kluge. Yes, it would be much easier to allow the zero-radius circles. The attached smaller patch allows all the cases to work: test=> SELECT @@ polygon '((1, 1))'; ?column? ---------- (1,1) (1 row) test=> SELECT point(polygon '((1, 1))'); point ------- (1,1) (1 row) test=> SELECT circle(polygon '((1, 1))'); circle ----------- <(1,1),0> (1 row) -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --mSxgbZZZvrAyzONB Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="geo2.diff" diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c new file mode 100644 index 0a68be6..e8fbe4e *** a/src/backend/utils/adt/geo_ops.c --- b/src/backend/utils/adt/geo_ops.c *************** poly_circle(PG_FUNCTION_ARGS) *** 5165,5171 **** CIRCLE *circle; int i; ! if (poly->npts < 2) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cannot convert empty polygon to circle"))); --- 5165,5171 ---- CIRCLE *circle; int i; ! if (poly->npts < 1) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("cannot convert empty polygon to circle"))); *************** poly_circle(PG_FUNCTION_ARGS) *** 5188,5198 **** circle->radius += point_dt(&poly->p[i], &circle->center); circle->radius /= poly->npts; - if (FPzero(circle->radius)) - ereport(ERROR, - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), - errmsg("cannot convert empty polygon to circle"))); - PG_RETURN_CIRCLE_P(circle); } --- 5188,5193 ---- --mSxgbZZZvrAyzONB Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --mSxgbZZZvrAyzONB--