PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_lwgeom_force_clockwise()

static void test_lwgeom_force_clockwise ( void  )
static

use same check instead of strcmp to account for difference in endianness

Definition at line 766 of file cu_libgeom.c.

References LW_PARSER_CHECK_NONE, lwfree(), lwgeom_force_clockwise(), lwgeom_free(), lwgeom_from_hexwkb(), lwgeom_from_wkt(), lwgeom_is_clockwise(), lwgeom_same(), and lwgeom_to_ewkt().

Referenced by libgeom_suite_setup().

767 {
768  LWGEOM *geom;
769  LWGEOM *geom2;
770  char *in_ewkt, *out_ewkt;
771 
772  /* counterclockwise, must be reversed */
773  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
774  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
776  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
777  out_ewkt = lwgeom_to_ewkt(geom);
778  if (strcmp(in_ewkt, out_ewkt))
779  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
780  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
781  lwfree(out_ewkt);
782  lwgeom_free(geom);
783 
784  /* clockwise, fine as is */
785  geom = lwgeom_from_wkt("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", LW_PARSER_CHECK_NONE);
786  CU_ASSERT_TRUE(lwgeom_is_clockwise(geom));
788  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
789  out_ewkt = lwgeom_to_ewkt(geom);
790  if (strcmp(in_ewkt, out_ewkt))
791  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
792  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
793  lwfree(out_ewkt);
794  lwgeom_free(geom);
795 
796  /* counterclockwise shell (must be reversed), mixed-wise holes */
797  geom = lwgeom_from_wkt("POLYGON((0 0,10 0,10 10,0 10,0 0),(2 2,2 4,4 2,2 2),(6 2,8 2,8 4,6 2))", LW_PARSER_CHECK_NONE);
798  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
800  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,2 4,2 2),(6 2,8 2,8 4,6 2))";
801  out_ewkt = lwgeom_to_ewkt(geom);
802  if (strcmp(in_ewkt, out_ewkt))
803  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
804  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
805  lwfree(out_ewkt);
806  lwgeom_free(geom);
807 
808  /* clockwise shell (fine), mixed-wise holes */
809  geom = lwgeom_from_wkt("POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,2 4,2 2),(6 2,8 4,8 2,6 2))", LW_PARSER_CHECK_NONE);
810  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
812  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0),(2 2,4 2,2 4,2 2),(6 2,8 2,8 4,6 2))";
813  out_ewkt = lwgeom_to_ewkt(geom);
814  if (strcmp(in_ewkt, out_ewkt))
815  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
816  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
817  lwfree(out_ewkt);
818  lwgeom_free(geom);
819 
820  /* clockwise narrow ring, fine as-is */
821  /* NOTE: this is a narrow ring, see ticket #1302 */
822  in_ewkt = "0103000000010000000500000000917E9BA468294100917E9B8AEA2841C976BE1FA4682941C976BE9F8AEA2841B39ABE1FA46829415ACCC29F8AEA284137894120A4682941C976BE9F8AEA284100917E9BA468294100917E9B8AEA2841";
823  geom = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
824  geom2 = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
825  lwgeom_force_clockwise(geom2);
826 
829  CU_ASSERT( lwgeom_same(geom, geom2) );
830  lwgeom_free(geom);
831  lwgeom_free(geom2);
832 }
void lwfree(void *mem)
Definition: lwutil.c:244
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:518
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
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:36
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:544
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:797
int lwgeom_is_clockwise(LWGEOM *lwgeom)
Check clockwise orientation on LWGEOM polygons.
Definition: lwgeom.c:64
Here is the call graph for this function:
Here is the caller graph for this function: