PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_arc_arc()

static void test_lw_dist2d_arc_arc ( void  )
static

Definition at line 743 of file cu_measures.c.

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().

744 {
745  /* lw_dist2d_arc_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3,
746  const POINT2D *B1, const POINT2D *B2, const POINT2D *B3,
747  DISTPTS *dl) */
748  DISTPTS dl;
749  POINT2D A1, A2, A3, B1, B2, B3;
750  int rv;
751 
752  /* Unit semicircle at 0,0 */
753  B1.x = -1; B1.y = 0;
754  B2.x = 0 ; B2.y = 1;
755  B3.x = 1 ; B3.y = 0;
756 
757  /* Arc above the unit semicircle */
759  A1.x = -1; A1.y = 3;
760  A2.x = 0 ; A2.y = 2;
761  A3.x = 1 ; A3.y = 3;
762  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
763  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
764  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
765 
766  /* Arc grazes the unit semicircle */
768  A1.x = -1; A1.y = 2;
769  A2.x = 0 ; A2.y = 1;
770  A3.x = 1 ; A3.y = 2;
771  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
772  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
773  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
774 
775  /* Circles intersect, but arcs do not */
777  A1.x = -1; A1.y = 1;
778  A2.x = 0; A2.y = 2;
779  A3.x = 1; A3.y = 1;
780  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
781  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
782  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2)-1, 0.000001);
783 
784  /* Circles and arcs intersect */
786  A1.x = -1; A1.y = 1;
787  A2.x = 0; A2.y = 0;
788  A3.x = 1; A3.y = 1;
789  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
790  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
791  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
792 
793  /* Concentric: and fully parallel */
795  A1.x = -2.0; A1.y = 0.0;
796  A2.x = 0.0; A2.y = 2.0;
797  A3.x = 2.0; A3.y = 0.0;
798  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
799  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
800  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
801 
802  /* Concentric: with A fully included in B's range */
804  A1.x = -0.5 / sqrt(2.0); A1.y = 0.5 / sqrt(2.0);
805  A2.x = 0.0; A2.y = 0.5;
806  A3.x = 0.5 / sqrt(2.0); A3.y = 0.5 / sqrt(2.0);
807  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
808  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
809  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
810 
811  /* Concentric: with A partially included in B's range */
813  A1.x = -0.5 / sqrt(2.0); A1.y = -0.5 / sqrt(2.0);
814  A2.x = -0.5; A2.y = 0.0;
815  A3.x = -0.5 / sqrt(2.0); A3.y = 0.5 / sqrt(2.0);
816  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
817  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
818  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
819 
820  /* Concentric: with A and B without parallel segments */
822  A1.x = -0.5 / sqrt(2.0); A1.y = -0.5 / sqrt(2.0);
823  A2.x = 0.0; A2.y = -0.5;
824  A3.x = 0.5 / sqrt(2.0); A3.y = -0.5 / sqrt(2.0);
825  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
826  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
827  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.736813, 0.000001);
828 
829  /* Concentric: Arcs are the same */
831  A1.x = -1.0; A1.y = 0.0;
832  A2.x = 0.0; A2.y = 1.0;
833  A3.x = 1.0; A3.y = 0.0;
834  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
835  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
836  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.0, 0.000001);
837 
838  /* Check different orientations */
839  B1.x = -10.0; B1.y = 0.0;
840  B2.x = 0.0 ; B2.y = 10.0;
841  B3.x = 10.0 ; B3.y = 0.0;
842 
844  A1.x = -22.0; A1.y = 0.0;
845  A2.x = -17.0; A2.y = -5.0;
846  A3.x = -12.0; A3.y = 0.0;
847  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
848  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
849  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 2.0, 0.000001);
850 
852  A1.x = -19.0; A1.y = 0.0;
853  A2.x = -14.0; A2.y = -5.0;
854  A3.x = - 9.0; A3.y = 0.0;
855  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
856  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
857  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
858 
860  A1.x = -9.0; A1.y = 0.0;
861  A2.x = -4.0; A2.y = -5.0;
862  A3.x = 1.0; A3.y = 0.0;
863  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
864  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
865  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
866 
868  A1.x = -1.0; A1.y = 0.0;
869  A2.x = 4.0; A2.y = -5.0;
870  A3.x = 9.0; A3.y = 0.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, 1.0, 0.000001);
874 
876  A1.x = 1.0; A1.y = 0.0;
877  A2.x = 6.0; A2.y = -5.0;
878  A3.x = 11.0; A3.y = 0.0;
879  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
880  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
881  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
882 
884  A1.x = 11.0; A1.y = 0.0;
885  A2.x = 16.0; A2.y = -5.0;
886  A3.x = 21.0; A3.y = 0.0;
887  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
888  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
889  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
890 
891 
893  A1.x = -15.0; A1.y = -6.0;
894  A2.x = -10.0; A2.y = -1.0;
895  A3.x = - 5.0; A3.y = -6.0;
896  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
897  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
898  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
899 
901  A1.x = -5.0; A1.y = 0.0;
902  A2.x = 0.0; A2.y = 5.0;
903  A3.x = 5.0; A3.y = 0.0;
904  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
905  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
906  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 5.0, 0.000001);
907 
909  A1.x = -5.0; A1.y = 0.0;
910  A2.x = 0.0; A2.y = -5.0;
911  A3.x = 5.0; A3.y = 0.0;
912  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
913  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
914  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 5.0, 0.000001);
915 
916 
917 }
#define LW_SUCCESS
Definition: liblwgeom.h:79
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
double x
Definition: liblwgeom.h:330
#define DIST_MIN
Definition: measures.h:41
double y
Definition: liblwgeom.h:330
double distance
Definition: measures.h:48
Structure used in distance-calculations.
Definition: measures.h:46
void lw_dist2d_distpts_init(DISTPTS *dl, int mode)
Definition: measures.c:67
Here is the call graph for this function:
Here is the caller graph for this function: