PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_pt_ptarrayarc()

static void test_lw_dist2d_pt_ptarrayarc ( void  )
static

Definition at line 912 of file cu_measures.c.

References DIST_MIN, DISTPTS::distance, lw_dist2d_distpts_init(), lw_dist2d_pt_ptarrayarc(), LW_SUCCESS, lwgeom_as_lwline(), lwgeom_from_text(), lwline_free(), LWLINE::points, POINT2D::x, and POINT2D::y.

Referenced by measures_suite_setup().

913 {
914  /* lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl) */
915  DISTPTS dl;
916  int rv;
917  LWLINE *lwline;
918  POINT2D P;
919 
920  /* Unit semi-circle above X axis */
921  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 0, 0 1, 1 0)"));
922 
923  /* Point at origin */
924  P.x = P.y = 0;
926  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
927  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
928  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
929 
930  /* Point above arc on Y axis */
931  P.y = 2;
933  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
934  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
935  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
936 
937  /* Point 45 degrees off arc, 2 radii from center */
938  P.y = P.x = 2 * cos(M_PI_4);
940  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
941  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
942  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
943 
944  /* Four unit semi-circles surrounding the 2x2 box around origin */
945  lwline_free(lwline);
946  lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(-1 -1, -2 0, -1 1, 0 2, 1 1, 2 0, 1 -1, 0 -2, -1 -1)"));
947 
948  /* Point at origin */
949  P.x = P.y = 0;
951  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
952  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
953  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0), 0.000001);
954 
955  /* Point on box edge */
956  P.x = -1; P.y = 0;
958  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
959  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
960  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
961 
962  /* Point within a semicircle lobe */
963  P.x = -1.5; P.y = 0;
965  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
966  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
967  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
968 
969  /* Point outside a semicircle lobe */
970  P.x = -2.5; P.y = 0;
972  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
973  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
974  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
975 
976  /* Point outside a semicircle lobe */
977  P.y = -2.5; P.x = 0;
979  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
980  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
981  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
982 
983  /* Point outside a semicircle lobe */
984  P.y = 2; P.x = 1;
986  rv = lw_dist2d_pt_ptarrayarc(&P, lwline->points, &dl);
987  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
988  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2.0)-1.0, 0.000001);
989 
990  /* Clean up */
991  lwline_free(lwline);
992 }
#define LW_SUCCESS
Definition: liblwgeom.h:80
void lwline_free(LWLINE *line)
Definition: lwline.c:76
static LWGEOM * lwgeom_from_text(const char *str)
Definition: cu_measures.c:25
double x
Definition: liblwgeom.h:328
#define DIST_MIN
Definition: measures.h:44
int lw_dist2d_pt_ptarrayarc(const POINT2D *p, const POINTARRAY *pa, DISTPTS *dl)
Search all the arcs of pointarray to see which one is closest to p1 Returns minimum distance between ...
Definition: measures.c:1079
double y
Definition: liblwgeom.h:328
LWLINE * lwgeom_as_lwline(const LWGEOM *lwgeom)
Definition: lwgeom.c:138
double distance
Definition: measures.h:51
Structure used in distance-calculations.
Definition: measures.h:49
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:67
POINTARRAY * points
Definition: liblwgeom.h:422
Here is the call graph for this function:
Here is the caller graph for this function: