- #3845, Gracefully handle short-measure issue
- #3871, Performance tweak for geometry cmp function
- #3879, Division by zero in some arc cases
+ - #3878, Single defn of signum in header
PostGIS 2.4.0
2017/09/30
p->lon = rad2deg(p->lon);
}
-static void test_signum(void)
-{
- CU_ASSERT_EQUAL(signum(-5.0),-1);
- CU_ASSERT_EQUAL(signum(5.0),1);
-}
-
-
static void test_sphere_direction(void)
{
GEOGRAPHIC_POINT s, e;
PG_ADD_TEST(suite, test_sphere_direction);
PG_ADD_TEST(suite, test_sphere_project);
PG_ADD_TEST(suite, test_lwgeom_area_sphere);
- PG_ADD_TEST(suite, test_signum);
PG_ADD_TEST(suite, test_gbox_from_spherical_coordinates);
PG_ADD_TEST(suite, test_gserialized_get_gbox_geocentric);
PG_ADD_TEST(suite, test_clairaut);
}
}
+void test_signum_macro(void);
+void test_signum_macro(void)
+{
+ CU_ASSERT_EQUAL(SIGNUM(-5.0),-1);
+ CU_ASSERT_EQUAL(SIGNUM( 5.0), 1);
+ CU_ASSERT_EQUAL(SIGNUM( 0.0), 0);
+ CU_ASSERT_EQUAL(SIGNUM(10) * 5, 5);
+ CU_ASSERT_EQUAL(SIGNUM(-10) * 5, -5);
+}
+
/*
** Used by test harness to register the tests in this file.
*/
PG_ADD_TEST(suite, test_gserialized_peek_gbox_p_gets_correct_box);
PG_ADD_TEST(suite, test_gserialized_peek_gbox_p_fails_for_unsupported_cases);
PG_ADD_TEST(suite, test_gbox_same_2d);
+ PG_ADD_TEST(suite, test_signum_macro);
}
#define SIZE_GET(varsize) (((varsize) >> 2) & 0x3FFFFFFF)
#define SIZE_SET(varsize, size) (((varsize) & 0x00000003)|(((size) & 0x3FFFFFFF) << 2 ))
+/**
+* Macro that returns:
+* -1 if n < 0,
+* 1 if n > 0,
+* 0 if n == 0
+*/
+#define SIGNUM(n) (((n) > 0) - ((n) < 0))
+
/**
* Tolerance used to determine equality.
*/
LWPOLY* lwpoly_simplify(const LWPOLY *ipoly, double dist, int preserve_collapsed);
LWCOLLECTION* lwcollection_simplify(const LWCOLLECTION *igeom, double dist, int preserve_collapsed);
-/*
-* Computational geometry
-*/
-int signum(double n);
-
/*
* The possible ways a pair of segments can interact. Returned by lw_segment_intersects
*/
#include "lwgeom_log.h"
#include <ctype.h> /* for tolower */
-
-/**
-* Returns -1 if n < 0.0 and 1 if n > 0.0
-*/
-int signum(double n)
-{
- if( n < 0 ) return -1;
- if( n > 0 ) return 1;
- return 0;
-}
-
int
p4d_same(const POINT4D *p1, const POINT4D *p2)
{
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
{
double side = ( (q->x - p1->x) * (p2->y - p1->y) - (p2->x - p1->x) * (q->y - p1->y) );
- if ( side == 0.0 )
- return 0;
- else
- return signum(side);
+ return SIGNUM(side);
}
/**
int crosses_dateline(const GEOGRAPHIC_POINT *s, const GEOGRAPHIC_POINT *e)
{
- double sign_s = signum(s->lon);
- double sign_e = signum(e->lon);
+ double sign_s = SIGNUM(s->lon);
+ double sign_e = SIGNUM(e->lon);
double ss = fabs(s->lon);
double ee = fabs(e->lon);
if ( sign_s == sign_e )
}
/* Over the pole, we need normalize latitude and do this calculation in latitude */
- if ( FP_EQUALS( slon, M_PI ) && ( signum(g.start.lon) != signum(g.end.lon) || FP_EQUALS(dlon, M_PI) ) )
+ if ( FP_EQUALS( slon, M_PI ) && ( SIGNUM(g.start.lon) != SIGNUM(g.end.lon) || FP_EQUALS(dlon, M_PI) ) )
{
LWDEBUG(4, "over the pole...");
/* Antipodal, everything (or nothing?) is inside */
}
/* Dateline crossing, flip everything to the opposite hemisphere */
- else if ( slon > M_PI && ( signum(g.start.lon) != signum(g.end.lon) ) )
+ else if ( slon > M_PI && ( SIGNUM(g.start.lon) != SIGNUM(g.end.lon) ) )
{
LWDEBUG(4, "crosses dateline, flip longitudes...");
if ( g.start.lon > 0.0 )
double c_dist = sphere_distance(a, b);
double hca = sphere_direction(c, a, b_dist);
double hcb = sphere_direction(c, b, a_dist);
- double sign = signum(hcb-hca);
+ double sign = SIGNUM(hcb-hca);
double ss = (a_dist + b_dist + c_dist) / 2.0;
double E = tan(ss/2.0)*tan((ss-a_dist)/2.0)*tan((ss-b_dist)/2.0)*tan((ss-c_dist)/2.0);
return 4.0 * atan(sqrt(fabs(E))) * sign;
*/
double z_to_latitude(double z, int top)
{
- double sign = signum(z);
+ double sign = SIGNUM(z);
double tlat = acos(z);
LWDEBUGF(4, "inputs: z(%.8g) sign(%.8g) tlat(%.8g)", z, sign, tlat);
if (FP_IS_ZERO(z))
#define deg2rad(d) (M_PI * (d) / 180.0)
#define rad2deg(r) (180.0 * (r) / M_PI)
-/**
-* Ape a java function
-*/
-#define signum(a) ((a) < 0 ? -1 : ((a) > 0 ? 1 : (a)))
-
/**
* Bitmask elements for edge_intersects() return value.
LWDEBUGF(4, "tE %.12g", tE);
ratio = (bE + tE)/tE;
- sign = signum(B.lon - A.lon);
+ sign = SIGNUM(B.lon - A.lon);
return (baseArea + topArea / ratio) * sign;
}
/* Get the raw min/max values for the latitudes */
ptarray_calculate_gbox_cartesian(pa, &gbox2d);
- if ( signum(gbox2d.ymin) != signum(gbox2d.ymax) )
+ if ( SIGNUM(gbox2d.ymin) != SIGNUM(gbox2d.ymax) )
lwerror("ptarray_area_spheroid: cannot handle ptarray that crosses equator");
/* Geodetic bbox < 0.0 implies geometry is entirely in southern hemisphere */