PostGIS  2.5.1dev-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_is_clockwise(), 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);
754  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
756  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
757  out_ewkt = lwgeom_to_ewkt(geom);
758  if (strcmp(in_ewkt, out_ewkt))
759  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
760  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
761  lwfree(out_ewkt);
762  lwgeom_free(geom);
763 
764  /* clockwise, fine as is */
765  geom = lwgeom_from_wkt("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", LW_PARSER_CHECK_NONE);
766  CU_ASSERT_TRUE(lwgeom_is_clockwise(geom));
768  in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
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  /* counterclockwise shell (must be reversed), mixed-wise holes */
777  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);
778  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
780  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))";
781  out_ewkt = lwgeom_to_ewkt(geom);
782  if (strcmp(in_ewkt, out_ewkt))
783  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
784  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
785  lwfree(out_ewkt);
786  lwgeom_free(geom);
787 
788  /* clockwise shell (fine), mixed-wise holes */
789  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);
790  CU_ASSERT_FALSE(lwgeom_is_clockwise(geom));
792  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))";
793  out_ewkt = lwgeom_to_ewkt(geom);
794  if (strcmp(in_ewkt, out_ewkt))
795  fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
796  CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
797  lwfree(out_ewkt);
798  lwgeom_free(geom);
799 
800  /* clockwise narrow ring, fine as-is */
801  /* NOTE: this is a narrow ring, see ticket #1302 */
802  in_ewkt = "0103000000010000000500000000917E9BA468294100917E9B8AEA2841C976BE1FA4682941C976BE9F8AEA2841B39ABE1FA46829415ACCC29F8AEA284137894120A4682941C976BE9F8AEA284100917E9BA468294100917E9B8AEA2841";
803  geom = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
804  geom2 = lwgeom_from_hexwkb(in_ewkt, LW_PARSER_CHECK_NONE);
805  lwgeom_force_clockwise(geom2);
806 
809  CU_ASSERT( lwgeom_same(geom, geom2) );
810  lwgeom_free(geom);
811  lwgeom_free(geom2);
812 }
void lwfree(void *mem)
Definition: lwutil.c:244
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an alloced string.
Definition: lwgeom.c:556
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1144
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:904
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:2004
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Force Right-hand-rule on LWGEOM polygons.
Definition: lwgeom.c:37
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition: lwgeom.c:582
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition: lwin_wkb.c:789
int lwgeom_is_clockwise(LWGEOM *lwgeom)
Ensure the outer ring is clockwise oriented and all inner rings are counter-clockwise.
Definition: lwgeom.c:65
Here is the call graph for this function:
Here is the caller graph for this function: