From: Paul Ramsey Date: Mon, 14 Sep 2009 18:33:54 +0000 (+0000) Subject: Crib index penalty tweak from pgsphere. X-Git-Tag: 1.5.0b1~511 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=06568b44d1279afd38f36d02890e232a71314377;p=postgis Crib index penalty tweak from pgsphere. git-svn-id: http://svn.osgeo.org/postgis/trunk@4497 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/liblwgeom.h b/liblwgeom/liblwgeom.h index 86230b99f..b16609ab9 100644 --- a/liblwgeom/liblwgeom.h +++ b/liblwgeom/liblwgeom.h @@ -39,12 +39,14 @@ #define INTEGRITY_CHECKS 1 /* - * Floating point comparitors. - */ +** Floating point comparitors. +*/ #define FP_TOLERANCE 1e-12 +#define FP_ZERO(A) (fabs(A) <= FP_TOLERANCE) #define FP_MAX(A, B) (((A) > (B)) ? (A) : (B)) #define FP_MIN(A, B) (((A) < (B)) ? (A) : (B)) -#define FP_EQUALS(A, B) (fabs((A)-(B)) < FP_TOLERANCE) +#define FP_EQUALS(A, B) (fabs((A)-(B)) <= FP_TOLERANCE) +#define FP_NEQUALS(A, B) (fabs((A)-(B)) > FP_TOLERANCE) #define FP_LT(A, B) (((A) + FP_TOLERANCE) < (B)) #define FP_LTEQ(A, B) (((A) - FP_TOLERANCE) <= (B)) #define FP_GT(A, B) (((A) - FP_TOLERANCE) > (B)) @@ -54,6 +56,10 @@ #define FP_CONTAINS_INCL(A, X, B) (FP_LTEQ(A, X) && FP_LTEQ(X, B)) #define FP_CONTAINS_EXCL(A, X, B) (FP_LT(A, X) && FP_LT(X, B)) #define FP_CONTAINS(A, X, B) FP_CONTAINS_EXCL(A, X, B) + +/* +** Utility true and false defines. +*/ #define LW_TRUE 1 #define LW_FALSE 0 diff --git a/postgis/geography_gist.c b/postgis/geography_gist.c index 723329239..2e764595a 100644 --- a/postgis/geography_gist.c +++ b/postgis/geography_gist.c @@ -830,6 +830,16 @@ Datum geography_gist_penalty(PG_FUNCTION_ARGS) size_union = gidx_union_volume(gbox_index_orig, gbox_index_new); size_orig = gidx_volume(gbox_index_orig); *result = size_union - size_orig; + + /* All things being equal, we prefer to expand small boxes rather than large boxes. */ + if( FP_ZERO(*result) ) + if( FP_ZERO(size_orig) ) + *result = 0.0; + else + *result = 1.0 - (1.0/(1.0 + size_orig)); + else + *result += 1; + POSTGIS_DEBUGF(4, "[GIST] union size (%f), original size (%f), penalty (%f)", size_union, size_orig, *result); PG_RETURN_POINTER(result); }