PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_arc_arc()

static void test_lw_dist2d_arc_arc ( void  )
static

Definition at line 795 of file cu_measures.c.

796 {
797  /* lw_dist2d_arc_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3,
798  const POINT2D *B1, const POINT2D *B2, const POINT2D *B3,
799  DISTPTS *dl) */
800  DISTPTS dl;
801  POINT2D A1, A2, A3, B1, B2, B3;
802  int rv;
803 
804  /* Ticket #4326 */
806  A1.x = -1.0; A1.y = 4.0;
807  A2.x = 0.0; A2.y = 5.0;
808  A3.x = 1.0; A3.y = 4.0;
809  B1.x = 1.0; B1.y = 6.0;
810  B2.x = 6.0; B2.y = 1.0;
811  B3.x = 9.0; B3.y = 7.0;
812  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
813  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
814  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.0475666, 0.000001);
815 
816  /* Unit semicircle at 0,0 */
817  B1.x = -1; B1.y = 0;
818  B2.x = 0 ; B2.y = 1;
819  B3.x = 1 ; B3.y = 0;
820 
821  /* Arc above the unit semicircle */
823  A1.x = -1; A1.y = 3;
824  A2.x = 0 ; A2.y = 2;
825  A3.x = 1 ; A3.y = 3;
826  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
827  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
828  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
829 
830  /* Arc grazes the unit semicircle */
832  A1.x = -1; A1.y = 2;
833  A2.x = 0 ; A2.y = 1;
834  A3.x = 1 ; A3.y = 2;
835  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
836  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
837  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
838 
839  /* Circles intersect, but arcs do not */
841  A1.x = -1; A1.y = 1;
842  A2.x = 0; A2.y = 2;
843  A3.x = 1; A3.y = 1;
844  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
845  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
846  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2)-1, 0.000001);
847 
848  /* Circles and arcs intersect */
850  A1.x = -1; A1.y = 1;
851  A2.x = 0; A2.y = 0;
852  A3.x = 1; A3.y = 1;
853  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
854  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
855  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
856 
857  /* Concentric: and fully parallel */
859  A1.x = -2.0; A1.y = 0.0;
860  A2.x = 0.0; A2.y = 2.0;
861  A3.x = 2.0; A3.y = 0.0;
862  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
863  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
864  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
865 
866  /* Concentric: with A fully included in B's range */
868  A1.x = -0.5 / sqrt(2.0); A1.y = 0.5 / sqrt(2.0);
869  A2.x = 0.0; A2.y = 0.5;
870  A3.x = 0.5 / sqrt(2.0); A3.y = 0.5 / sqrt(2.0);
871  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
872  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
873  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
874 
875  /* Concentric: with A partially included in B's range */
877  A1.x = -0.5 / sqrt(2.0); A1.y = -0.5 / sqrt(2.0);
878  A2.x = -0.5; A2.y = 0.0;
879  A3.x = -0.5 / sqrt(2.0); A3.y = 0.5 / sqrt(2.0);
880  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
881  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
882  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
883 
884  /* Concentric: with A and B without parallel segments */
886  A1.x = -0.5 / sqrt(2.0); A1.y = -0.5 / sqrt(2.0);
887  A2.x = 0.0; A2.y = -0.5;
888  A3.x = 0.5 / sqrt(2.0); A3.y = -0.5 / sqrt(2.0);
889  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
890  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
891  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.736813, 0.000001);
892 
893  /* Concentric: Arcs are the same */
895  A1.x = -1.0; A1.y = 0.0;
896  A2.x = 0.0; A2.y = 1.0;
897  A3.x = 1.0; A3.y = 0.0;
898  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
899  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
900  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.0, 0.000001);
901 
902  /* Check different orientations */
903  B1.x = -10.0; B1.y = 0.0;
904  B2.x = 0.0 ; B2.y = 10.0;
905  B3.x = 10.0 ; B3.y = 0.0;
906 
908  A1.x = -22.0; A1.y = 0.0;
909  A2.x = -17.0; A2.y = -5.0;
910  A3.x = -12.0; A3.y = 0.0;
911  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
912  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
913  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 2.0, 0.000001);
914 
916  A1.x = -19.0; A1.y = 0.0;
917  A2.x = -14.0; A2.y = -5.0;
918  A3.x = - 9.0; A3.y = 0.0;
919  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
920  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
921  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
922 
924  A1.x = -9.0; A1.y = 0.0;
925  A2.x = -4.0; A2.y = -5.0;
926  A3.x = 1.0; A3.y = 0.0;
927  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
928  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
929  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
930 
932  A1.x = -1.0; A1.y = 0.0;
933  A2.x = 4.0; A2.y = -5.0;
934  A3.x = 9.0; A3.y = 0.0;
935  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
936  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
937  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
938 
940  A1.x = 1.0; A1.y = 0.0;
941  A2.x = 6.0; A2.y = -5.0;
942  A3.x = 11.0; A3.y = 0.0;
943  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
944  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
945  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
946 
948  A1.x = 11.0; A1.y = 0.0;
949  A2.x = 16.0; A2.y = -5.0;
950  A3.x = 21.0; A3.y = 0.0;
951  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
952  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
953  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
954 
955 
957  A1.x = -15.0; A1.y = -6.0;
958  A2.x = -10.0; A2.y = -1.0;
959  A3.x = - 5.0; A3.y = -6.0;
960  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
961  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
962  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
963 
965  A1.x = -5.0; A1.y = 0.0;
966  A2.x = 0.0; A2.y = 5.0;
967  A3.x = 5.0; A3.y = 0.0;
968  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
969  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
970  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 5.0, 0.000001);
971 
973  A1.x = -5.0; A1.y = 0.0;
974  A2.x = 0.0; A2.y = -5.0;
975  A3.x = 5.0; A3.y = 0.0;
976  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
977  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
978  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 5.0, 0.000001);
979 
980 }
#define LW_SUCCESS
Definition: liblwgeom.h:80
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:67
int lw_dist2d_arc_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3, const POINT2D *B1, const POINT2D *B2, const POINT2D *B3, DISTPTS *dl)
Definition: measures.c:1497
#define DIST_MIN
Definition: measures.h:44
double distance
Definition: measures.h:51
Structure used in distance-calculations.
Definition: measures.h:50
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331

References DIST_MIN, DISTPTS::distance, lw_dist2d_arc_arc(), lw_dist2d_distpts_init(), LW_SUCCESS, POINT2D::x, and POINT2D::y.

Referenced by measures_suite_setup().

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