PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ 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_gserialized1.c.

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);
756 CU_ASSERT(lwgeom_has_orientation(geom,LW_CLOCKWISE));
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 ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
762 lwfree(out_ewkt);
763 lwgeom_free(geom);
764
765 /* clockwise, fine as is */
766 geom = lwgeom_from_wkt("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))", LW_PARSER_CHECK_NONE);
767 CU_ASSERT(lwgeom_has_orientation(geom,LW_CLOCKWISE));
769 CU_ASSERT(lwgeom_has_orientation(geom,LW_CLOCKWISE));
770 in_ewkt = "POLYGON((0 0,0 10,10 10,10 0,0 0))";
771 out_ewkt = lwgeom_to_ewkt(geom);
772 if (strcmp(in_ewkt, out_ewkt))
773 fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
774 ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
775 lwfree(out_ewkt);
776 lwgeom_free(geom);
777
778 /* counterclockwise shell (must be reversed), mixed-wise holes */
779 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);
781 CU_ASSERT(lwgeom_has_orientation(geom,LW_CLOCKWISE));
782 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))";
783 out_ewkt = lwgeom_to_ewkt(geom);
784 if (strcmp(in_ewkt, out_ewkt))
785 fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
786 ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
787 lwfree(out_ewkt);
788 lwgeom_free(geom);
789
790 /* clockwise shell (fine), mixed-wise holes, so not oriented */
791 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);
792 /* fix it and then it is oriented */
794 CU_ASSERT(lwgeom_has_orientation(geom,LW_CLOCKWISE));
795 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))";
796 out_ewkt = lwgeom_to_ewkt(geom);
797 if (strcmp(in_ewkt, out_ewkt))
798 fprintf(stderr, "\nExp: %s\nObt: %s\n", in_ewkt, out_ewkt);
799 ASSERT_STRING_EQUAL(in_ewkt, out_ewkt);
800 lwfree(out_ewkt);
801 lwgeom_free(geom);
802
803 /* clockwise narrow ring, fine as-is */
804 /* NOTE: this is a narrow ring, see ticket #1302 */
805 in_ewkt = "0103000000010000000500000000917E9BA468294100917E9B8AEA2841C976BE1FA4682941C976BE9F8AEA2841B39ABE1FA46829415ACCC29F8AEA284137894120A4682941C976BE9F8AEA284100917E9BA468294100917E9B8AEA2841";
809 CU_ASSERT(lwgeom_has_orientation(geom,LW_CLOCKWISE));
810
813 CU_ASSERT(lwgeom_same(geom, geom2));
814 lwgeom_free(geom);
815 lwgeom_free(geom2);
816}
#define ASSERT_STRING_EQUAL(o, e)
char lwgeom_same(const LWGEOM *lwgeom1, const LWGEOM *lwgeom2)
geom1 same as geom2 iff
Definition lwgeom.c:619
int lwgeom_has_orientation(const LWGEOM *lwgeom, int orientation)
Tests that geometry is oriented LW_CLOCKWISE or LW_COUNTERCLOCKWISE.
Definition lwgeom.c:93
void lwgeom_free(LWGEOM *geom)
Definition lwgeom.c:1246
#define LW_PARSER_CHECK_NONE
Definition liblwgeom.h:2149
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an allocated string.
Definition lwgeom.c:593
void lwfree(void *mem)
Definition lwutil.c:248
LWGEOM * lwgeom_from_hexwkb(const char *hexwkb, const char check)
Definition lwin_wkb.c:866
void lwgeom_force_clockwise(LWGEOM *lwgeom)
Definition lwgeom.c:73
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition lwin_wkt.c:940
#define LW_CLOCKWISE
Constants for orientation checking and forcing.
#define LW_COUNTERCLOCKWISE

References ASSERT_STRING_EQUAL, LW_CLOCKWISE, LW_COUNTERCLOCKWISE, LW_PARSER_CHECK_NONE, lwfree(), lwgeom_force_clockwise(), lwgeom_free(), lwgeom_from_hexwkb(), lwgeom_from_wkt(), lwgeom_has_orientation(), lwgeom_same(), and lwgeom_to_ewkt().

Referenced by gserialized1_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: