PostGIS  2.3.8dev-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 746 of file cu_libgeom.c.

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

Referenced by libgeom_suite_setup().

747 {
748  LWGEOM *geom;
749  LWGEOM *geom2;
750  char *in_ewkt, *out_ewkt;
751 
752  /* counterclockwise, must be reversed */
753  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
755  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
756  out_ewkt = lwgeom_to_ewkt(geom);
757  if (strcmp(in_ewkt, out_ewkt))
758  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
759  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
760  lwfree(out_ewkt);
761  lwgeom_free(geom);
762 
763  /* clockwise, fine as is */
764  geom = lwgeom_from_wkt("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", LW_PARSER_CHECK_NONE);
766  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
767  out_ewkt = lwgeom_to_ewkt(geom);
768  if (strcmp(in_ewkt, out_ewkt))
769  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
770  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
771  lwfree(out_ewkt);
772  lwgeom_free(geom);
773 
774  /* counterclockwise shell (must be reversed), mixed-wise holes */
775  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);
777  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))";
778  out_ewkt = lwgeom_to_ewkt(geom);
779  if (strcmp(in_ewkt, out_ewkt))
780  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
781  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
782  lwfree(out_ewkt);
783  lwgeom_free(geom);
784 
785  /* clockwise shell (fine), mixed-wise holes */
786  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);
788  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))";
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  /* clockwise narrow ring, fine as-is */
797  /* NOTE: this is a narrow ring, see ticket #1302 */
798  in_ewkt = "0103000000010000000500000000917E9BA468294100917E9B8AEA2841C976BE1FA4682941C976BE9F8AEA2841B39ABE1FA46829415ACCC29F8AEA284137894120A4682941C976BE9F8AEA284100917E9BA468294100917E9B8AEA2841";
799  geom = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
800  geom2 = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
801  lwgeom_force_clockwise(geom2);
802 
805  CU_ASSERT( lwgeom_same(geom, geom2) );
806  lwgeom_free(geom);
807  lwgeom_free(geom2);
808 }
void lwfree(void *mem)
Definition: lwutil.c:242
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:482
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1063
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1985
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:508
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:790
Here is the call graph for this function:
Here is the caller graph for this function: