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

Definition at line 907 of file cu_geodetic.c.

References LW_FALSE, LW_PARSER_CHECK_NONE, LW_TRUE, lwgeom_free(), lwgeom_from_hexwkb(), lwgeom_from_wkt(), ptarray_contains_point_sphere(), result, LWPOLY::rings, POINT2D::x, and POINT2D::y.

Referenced by geodetic_suite_setup().

908 {
909  LWGEOM *lwg;
910  LWPOLY *poly;
911  POINT2D pt_to_test;
912  POINT2D pt_outside;
913  int result;
914 
915  /* Small polygon and huge distance between outside point and close-but-not-quite-inside point. Should return LW_FALSE. Pretty degenerate case. */
916  lwg = lwgeom_from_hexwkb("0103000020E61000000100000025000000ACAD6F91DDB65EC03F84A86D57264540CCABC279DDB65EC0FCE6926B57264540B6DEAA62DDB65EC0A79F6B63572645402E0BE84CDDB65EC065677155572645405D0B1D39DDB65EC0316310425726454082B5DB27DDB65EC060A4E12957264540798BB619DDB65EC0C393A10D57264540D4BC160FDDB65EC0BD0320EE56264540D7AC4E08DDB65EC096C862CC56264540AFD29205DDB65EC02A1F68A956264540363AFA06DDB65EC0722E418656264540B63A780CDDB65EC06E9B0064562645409614E215DDB65EC0E09DA84356264540FF71EF22DDB65EC0B48145265626454036033F33DDB65EC081B8A60C5626454066FB4546DDB65EC08A47A6F7552645409061785BDDB65EC0F05AE0E755264540D4B63772DDB65EC05C86CEDD55264540D2E4C689DDB65EC09B6EBFD95526454082E573A1DDB65EC0C90BD5DB552645401ABE85B8DDB65EC06692FCE35526454039844ECEDDB65EC04D8AF6F155264540928319E2DDB65EC0AD8D570556264540D31055F3DDB65EC02D618F1D56264540343B7A01DEB65EC0EB70CF3956264540920A1A0CDEB65EC03B00515956264540911BE212DEB65EC0E43A0E7B56264540E3F69D15DEB65EC017E4089E562645408D903614DEB65EC0F0D42FC1562645402191B80EDEB65EC0586870E35626454012B84E05DEB65EC09166C80357264540215B41F8DDB65EC08F832B21572645408392F7E7DDB65EC01138C13A57264540F999F0D4DDB65EC0E4A9C14F57264540AC3FB8BFDDB65EC0EED6875F57264540D3DCFEA8DDB65EC04F6C996957264540ACAD6F91DDB65EC03F84A86D57264540", LW_PARSER_CHECK_NONE);
917  poly = (LWPOLY*)lwg;
918  pt_to_test.x = -122.819436560680316;
919  pt_to_test.y = 42.2702301207017328;
920  pt_outside.x = 120.695136159150778;
921  pt_outside.y = 40.6920926049588516;
922  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
923  CU_ASSERT_EQUAL(result, LW_FALSE);
924  lwgeom_free(lwg);
925 
926  /* Point on ring between vertexes case */
927  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
928  poly = (LWPOLY*)lwg;
929  pt_to_test.x = 1.1;
930  pt_to_test.y = 1.05;
931  pt_outside.x = 1.2;
932  pt_outside.y = 1.05;
933  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
934  CU_ASSERT_EQUAL(result, LW_TRUE);
935  lwgeom_free(lwg);
936 
937  /* Simple containment case */
938  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
939  poly = (LWPOLY*)lwg;
940  pt_to_test.x = 1.05;
941  pt_to_test.y = 1.05;
942  pt_outside.x = 1.2;
943  pt_outside.y = 1.15;
944  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
945  CU_ASSERT_EQUAL(result, LW_TRUE);
946  lwgeom_free(lwg);
947 
948  /* Less Simple containment case. */
949  /* Interior point quite close to boundary and stab line going through bottom edge vertex */
950  /* This breaks the "extend-it" trick of handling vertex crossings */
951  /* It should also break the "lowest end" trick. */
952  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.0, 1.05 0.95, 1.0 1.0))", LW_PARSER_CHECK_NONE);
953  poly = (LWPOLY*)lwg;
954  pt_to_test.x = 1.05;
955  pt_to_test.y = 1.00;
956  pt_outside.x = 1.05;
957  pt_outside.y = 0.5;
958  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
959  CU_ASSERT_EQUAL(result, LW_TRUE);
960  lwgeom_free(lwg);
961 
962  /* Simple noncontainment case */
963  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
964  poly = (LWPOLY*)lwg;
965  pt_to_test.x = 1.05;
966  pt_to_test.y = 1.15;
967  pt_outside.x = 1.2;
968  pt_outside.y = 1.2;
969  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
970  CU_ASSERT_EQUAL(result, LW_FALSE);
971  lwgeom_free(lwg);
972 
973  /* Harder noncontainment case */
974  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
975  poly = (LWPOLY*)lwg;
976  pt_to_test.x = 1.05;
977  pt_to_test.y = 0.9;
978  pt_outside.x = 1.2;
979  pt_outside.y = 1.05;
980  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
981  CU_ASSERT_EQUAL(result, LW_FALSE);
982  lwgeom_free(lwg);
983 
984  /* Harder containment case */
985  lwg = lwgeom_from_wkt("POLYGON((0 0, 0 2, 1 2, 0 3, 2 3, 0 4, 3 5, 0 6, 6 10, 6 1, 0 0))", LW_PARSER_CHECK_NONE);
986  poly = (LWPOLY*)lwg;
987  pt_to_test.x = 1.0;
988  pt_to_test.y = 1.0;
989  pt_outside.x = 1.0;
990  pt_outside.y = 10.0;
991  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
992  CU_ASSERT_EQUAL(result, LW_TRUE);
993  lwgeom_free(lwg);
994 
995  /* Point on ring at first vertex case */
996  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
997  poly = (LWPOLY*)lwg;
998  pt_to_test.x = 1.0;
999  pt_to_test.y = 1.0;
1000  pt_outside.x = 1.2;
1001  pt_outside.y = 1.05;
1002  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
1003  CU_ASSERT_EQUAL(result, LW_TRUE);
1004  lwgeom_free(lwg);
1005 
1006  /* Point on ring at vertex case */
1007  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
1008  poly = (LWPOLY*)lwg;
1009  pt_to_test.x = 1.0;
1010  pt_to_test.y = 1.1;
1011  pt_outside.x = 1.2;
1012  pt_outside.y = 1.05;
1013  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
1014  CU_ASSERT_EQUAL(result, LW_TRUE);
1015  lwgeom_free(lwg);
1016 
1017  /* Co-linear crossing case for point-in-polygon test, should return LW_TRUE */
1018  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.2, 1.2 1.2, 1.2 1.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
1019  poly = (LWPOLY*)lwg;
1020  pt_to_test.x = 1.1;
1021  pt_to_test.y = 1.05;
1022  pt_outside.x = 1.1;
1023  pt_outside.y = 1.3;
1024  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
1025  CU_ASSERT_EQUAL(result, LW_TRUE);
1026  lwgeom_free(lwg);
1027 
1028  /* Co-linear grazing case for point-in-polygon test, should return LW_FALSE */
1029  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.2, 1.2 1.2, 1.2 1.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
1030  poly = (LWPOLY*)lwg;
1031  pt_to_test.x = 1.0;
1032  pt_to_test.y = 0.0;
1033  pt_outside.x = 1.0;
1034  pt_outside.y = 2.0;
1035  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
1036  CU_ASSERT_EQUAL(result, LW_FALSE);
1037  lwgeom_free(lwg);
1038 
1039  /* Grazing case for point-in-polygon test, should return LW_FALSE */
1040  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 2.0, 1.5 1.5, 1.0 1.0))", LW_PARSER_CHECK_NONE);
1041  poly = (LWPOLY*)lwg;
1042  pt_to_test.x = 1.5;
1043  pt_to_test.y = 1.0;
1044  pt_outside.x = 1.5;
1045  pt_outside.y = 2.0;
1046  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
1047  CU_ASSERT_EQUAL(result, LW_FALSE);
1048  lwgeom_free(lwg);
1049 
1050  /* Grazing case at first point for point-in-polygon test, should return LW_FALSE */
1051  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 2.0 3.0, 2.0 0.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
1052  poly = (LWPOLY*)lwg;
1053  pt_to_test.x = 1.0;
1054  pt_to_test.y = 0.0;
1055  pt_outside.x = 1.0;
1056  pt_outside.y = 2.0;
1057  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
1058  CU_ASSERT_EQUAL(result, LW_FALSE);
1059  lwgeom_free(lwg);
1060 
1061  /* Outside multi-crossing case for point-in-polygon test, should return LW_FALSE */
1062  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.2, 1.2 1.2, 1.2 1.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
1063  poly = (LWPOLY*)lwg;
1064  pt_to_test.x = 0.99;
1065  pt_to_test.y = 0.99;
1066  pt_outside.x = 1.21;
1067  pt_outside.y = 1.21;
1068  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
1069  CU_ASSERT_EQUAL(result, LW_FALSE);
1070  lwgeom_free(lwg);
1071 
1072  /* Inside multi-crossing case for point-in-polygon test, should return LW_TRUE */
1073  lwg = lwgeom_from_wkt("POLYGON((1.0 1.0, 1.0 1.1, 1.1 1.1, 1.1 1.2, 1.2 1.2, 1.2 1.0, 1.0 1.0))", LW_PARSER_CHECK_NONE);
1074  poly = (LWPOLY*)lwg;
1075  pt_to_test.x = 1.11;
1076  pt_to_test.y = 1.11;
1077  pt_outside.x = 1.21;
1078  pt_outside.y = 1.21;
1079  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
1080  CU_ASSERT_EQUAL(result, LW_TRUE);
1081  lwgeom_free(lwg);
1082 
1083  /* Point on vertex of ring */
1084  lwg = lwgeom_from_wkt("POLYGON((-9 50,51 -11,-10 50,-9 50))", LW_PARSER_CHECK_NONE);
1085  poly = (LWPOLY*)lwg;
1086  pt_to_test.x = -10.0;
1087  pt_to_test.y = 50.0;
1088  pt_outside.x = -10.2727799838316134;
1089  pt_outside.y = -16.9370033133329976;
1090  result = ptarray_contains_point_sphere(poly->rings[0], &pt_outside, &pt_to_test);
1091  CU_ASSERT_EQUAL(result, LW_TRUE);
1092  lwgeom_free(lwg);
1093 
1094 }
void lwgeom_free(LWGEOM *geom)
Definition: lwgeom.c:1006
LWGEOM * lwgeom_from_wkt(const char *wkt, const char check)
Definition: lwin_wkt.c:844
char ** result
Definition: liblwgeom.h:218
#define LW_PARSER_CHECK_NONE
Definition: liblwgeom.h:1706
double x
Definition: liblwgeom.h:284
int ptarray_contains_point_sphere(const POINTARRAY *pa, const POINT2D *pt_outside, const POINT2D *pt_to_test)
This routine returns LW_TRUE if the stabline joining the pt_outside and pt_to_test crosses the ring a...
Definition: lwgeodetic.c:3201
#define LW_FALSE
Definition: liblwgeom.h:52
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
POINTARRAY ** rings
Definition: liblwgeom.h:413
double y
Definition: liblwgeom.h:284
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: