PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_gbox_same_2d()

void test_gbox_same_2d ( void  )

Definition at line 1077 of file cu_libgeom.c.

References LWGEOM::bbox, gbox_same_2d(), gbox_same_2d_float(), gserialized_from_lwgeom(), gserialized_read_gbox_p(), LW_PARSER_CHECK_NONE, lwfree(), lwgeom_add_bbox(), lwgeom_free(), lwgeom_from_wkt(), and test_gserialized_peek_gbox_p_no_box_when_empty().

Referenced by libgeom_suite_setup(), and test_lwgeom_scale().

1078 {
1079  LWGEOM* g1 = lwgeom_from_wkt("LINESTRING(0 0, 1 1)", LW_PARSER_CHECK_NONE);
1080  LWGEOM* g2 = lwgeom_from_wkt("LINESTRING(0 0, 0 1, 1 1)", LW_PARSER_CHECK_NONE);
1081  LWGEOM* g3 = lwgeom_from_wkt("LINESTRING(0 0, 1 1.000000000001)", LW_PARSER_CHECK_NONE);
1082 
1083  lwgeom_add_bbox(g1);
1084  lwgeom_add_bbox(g2);
1085  lwgeom_add_bbox(g3);
1086 
1087  CU_ASSERT_TRUE(gbox_same_2d(g1->bbox, g2->bbox));
1088  CU_ASSERT_FALSE(gbox_same_2d(g1->bbox, g3->bbox));
1089 
1090  /* Serializing a GBOX with precise coordinates renders the boxes not strictly equal,
1091  * but still equal according to gbox_same_2d_float.
1092  */
1093  GSERIALIZED* s3 = gserialized_from_lwgeom(g3, NULL);
1094  GBOX s3box;
1095  gserialized_read_gbox_p(s3, &s3box);
1096 
1097  CU_ASSERT_FALSE(gbox_same_2d(g3->bbox, &s3box));
1098  CU_ASSERT_TRUE(gbox_same_2d_float(g3->bbox, &s3box));
1099 
1100  /* The serialized box equals itself by either the exact or closest-float compares */
1101  CU_ASSERT_TRUE(gbox_same_2d(&s3box, &s3box));
1102  CU_ASSERT_TRUE(gbox_same_2d_float(&s3box, &s3box));
1103 
1104  lwgeom_free(g1);
1105  lwgeom_free(g2);
1106  lwgeom_free(g3);
1107  lwfree(s3);
1108 }
int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
Pull a GBOX from the header of a GSERIALIZED, if one is available.
Definition: g_serialized.c:416
GBOX * bbox
Definition: liblwgeom.h:398
void lwfree(void *mem)
Definition: lwutil.c:244
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1099
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2013
int gbox_same_2d(const GBOX *g1, const GBOX *g2)
Check if 2 given GBOX are the same in x and y.
Definition: g_box.c:191
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition: lwgeom.c:648
GSERIALIZED * gserialized_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
int gbox_same_2d_float(const GBOX *g1, const GBOX *g2)
Check if two given GBOX are the same in x and y, or would round to the same GBOX in x and if serializ...
Definition: g_box.c:199
Here is the call graph for this function:
Here is the caller graph for this function: