PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ test_gbox_same_2d()

static void test_gbox_same_2d ( void  )
static

Definition at line 1057 of file cu_gserialized1.c.

1058{
1059 LWGEOM* g1 = lwgeom_from_wkt("LINESTRING(0 0, 1 1)", LW_PARSER_CHECK_NONE);
1060 LWGEOM* g2 = lwgeom_from_wkt("LINESTRING(0 0, 0 1, 1 1)", LW_PARSER_CHECK_NONE);
1061 LWGEOM* g3 = lwgeom_from_wkt("LINESTRING(0 0, 1 1.000000000001)", LW_PARSER_CHECK_NONE);
1062
1063 lwgeom_add_bbox(g1);
1064 lwgeom_add_bbox(g2);
1065 lwgeom_add_bbox(g3);
1066
1067 CU_ASSERT_TRUE(gbox_same_2d(g1->bbox, g2->bbox));
1068 CU_ASSERT_FALSE(gbox_same_2d(g1->bbox, g3->bbox));
1069
1070 /* Serializing a GBOX with precise coordinates renders the boxes not strictly equal,
1071 * but still equal according to gbox_same_2d_float.
1072 */
1073 GSERIALIZED* s3 = gserialized1_from_lwgeom(g3, NULL);
1074 GBOX s3box;
1075 gserialized1_read_gbox_p(s3, &s3box);
1076
1077 CU_ASSERT_FALSE(gbox_same_2d(g3->bbox, &s3box));
1078 CU_ASSERT_TRUE(gbox_same_2d_float(g3->bbox, &s3box));
1079
1080 /* The serialized box equals itself by either the exact or closest-float compares */
1081 CU_ASSERT_TRUE(gbox_same_2d(&s3box, &s3box));
1082 CU_ASSERT_TRUE(gbox_same_2d_float(&s3box, &s3box));
1083
1084 lwgeom_free(g1);
1085 lwgeom_free(g2);
1086 lwgeom_free(g3);
1087 lwfree(s3);
1088}
int gbox_same_2d(const GBOX *g1, const GBOX *g2)
Check if 2 given GBOX are the same in x and y.
Definition gbox.c:179
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 gbox.c:187
GSERIALIZED * gserialized1_from_lwgeom(LWGEOM *geom, size_t *size)
Allocate a new GSERIALIZED from an LWGEOM.
static int gserialized1_read_gbox_p(const GSERIALIZED *g, GBOX *gbox)
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2149
void lwfree(void *mem)
Definition lwutil.c:248
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:940
void lwgeom_add_bbox(LWGEOM *lwgeom)
Compute a bbox if not already computed.
Definition lwgeom.c:723
GBOX * bbox
Definition liblwgeom.h:458

References LWGEOM::bbox, gbox_same_2d(), gbox_same_2d_float(), gserialized1_from_lwgeom(), gserialized1_read_gbox_p(), LW_PARSER_CHECK_NONE, lwfree(), lwgeom_add_bbox(), lwgeom_free(), and lwgeom_from_wkt().

Referenced by gserialized1_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: