PostGIS  2.2.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 745 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().

746 {
747  LWGEOM *geom;
748  LWGEOM *geom2;
749  char *in_ewkt, *out_ewkt;
750 
751  /* counterclockwise, must be reversed */
752  geom = lwgeom_from_wkt("POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))", LW_PARSER_CHECK_NONE);
754  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
755  out_ewkt = lwgeom_to_ewkt(geom);
756  if (strcmp(in_ewkt, out_ewkt))
757  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
758  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
759  lwfree(out_ewkt);
760  lwgeom_free(geom);
761 
762  /* clockwise, fine as is */
763  geom = lwgeom_from_wkt("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", LW_PARSER_CHECK_NONE);
765  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
766  out_ewkt = lwgeom_to_ewkt(geom);
767  if (strcmp(in_ewkt, out_ewkt))
768  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
769  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
770  lwfree(out_ewkt);
771  lwgeom_free(geom);
772 
773  /* counterclockwise shell (must be reversed), mixed-wise holes */
774  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);
776  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))";
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 shell (fine), mixed-wise holes */
785  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);
787  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))";
788  out_ewkt = lwgeom_to_ewkt(geom);
789  if (strcmp(in_ewkt, out_ewkt))
790  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
791  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
792  lwfree(out_ewkt);
793  lwgeom_free(geom);
794 
795  /* clockwise narrow ring, fine as-is */
796  /* NOTE: this is a narrow ring, see ticket #1302 */
797  in_ewkt = "0103000000010000000500000000917E9BA468294100917E9B8AEA2841C976BE1FA4682941C976BE9F8AEA2841B39ABE1FA46829415ACCC29F8AEA284137894120A4682941C976BE9F8AEA284100917E9BA468294100917E9B8AEA2841";
798  geom = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
799  geom2 = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
800  lwgeom_force_clockwise(geom2);
801 
804  CU_ASSERT( lwgeom_same(geom, geom2) );
805  lwgeom_free(geom);
806  lwgeom_free(geom2);
807 }
void lwfree(void *mem)
Definition: lwutil.c:214
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:469
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1050
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:890
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1869
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:495
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:779
Here is the call graph for this function:
Here is the caller graph for this function: