PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_lwgeom_force_clockwise ( void  )
static

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

Definition at line 737 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().

738 {
739  LWGEOM *geom;
740  LWGEOM *geom2;
741  char *in_ewkt, *out_ewkt;
742 
743  /* counterclockwise, must be reversed */
744  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
746  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
747  out_ewkt = lwgeom_to_ewkt(geom);
748  if (strcmp(in_ewkt, out_ewkt))
749  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
750  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
751  lwfree(out_ewkt);
752  lwgeom_free(geom);
753 
754  /* clockwise, fine as is */
755  geom = lwgeom_from_wkt("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", LW_PARSER_CHECK_NONE);
757  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
758  out_ewkt = lwgeom_to_ewkt(geom);
759  if (strcmp(in_ewkt, out_ewkt))
760  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
761  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
762  lwfree(out_ewkt);
763  lwgeom_free(geom);
764 
765  /* counterclockwise shell (must be reversed), mixed-wise holes */
766  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);
768  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))";
769  out_ewkt = lwgeom_to_ewkt(geom);
770  if (strcmp(in_ewkt, out_ewkt))
771  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
772  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
773  lwfree(out_ewkt);
774  lwgeom_free(geom);
775 
776  /* clockwise shell (fine), mixed-wise holes */
777  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);
779  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))";
780  out_ewkt = lwgeom_to_ewkt(geom);
781  if (strcmp(in_ewkt, out_ewkt))
782  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
783  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
784  lwfree(out_ewkt);
785  lwgeom_free(geom);
786 
787  /* clockwise narrow ring, fine as-is */
788  /* NOTE: this is a narrow ring, see ticket #1302 */
789  in_ewkt = "0103000000010000000500000000917E9BA468294100917E9B8AEA2841C976BE1FA4682941C976BE9F8AEA2841B39ABE1FA46829415ACCC29F8AEA284137894120A4682941C976BE9F8AEA284100917E9BA468294100917E9B8AEA2841";
790  geom = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
791  geom2 = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
792  lwgeom_force_clockwise(geom2);
793 
796  CU_ASSERT( lwgeom_same(geom, geom2) );
797  lwgeom_free(geom);
798  lwgeom_free(geom2);
799 }
void lwfree(void *mem)
Definition: lwutil.c:190
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:425
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:23
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:451
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:753

Here is the call graph for this function:

Here is the caller graph for this function: