PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_lw_dist2d_arc_arc()

static void test_lw_dist2d_arc_arc ( void  )
static

Definition at line 682 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().

683 {
684  /* lw_dist2d_arc_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3,
685  const POINT2D *B1, const POINT2D *B2, const POINT2D *B3,
686  DISTPTS *dl) */
687  DISTPTS dl;
688  POINT2D A1, A2, A3, B1, B2, B3;
689  int rv;
690 
691  /* Ticket #4326 */
693  A1.x = -1.0; A1.y = 4.0;
694  A2.x = 0.0; A2.y = 5.0;
695  A3.x = 1.0; A3.y = 4.0;
696  B1.x = 1.0; B1.y = 6.0;
697  B2.x = 6.0; B2.y = 1.0;
698  B3.x = 9.0; B3.y = 7.0;
699  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
700  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
701  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.0475666, 0.000001);
702 
703  /* Unit semicircle at 0,0 */
704  B1.x = -1; B1.y = 0;
705  B2.x = 0 ; B2.y = 1;
706  B3.x = 1 ; B3.y = 0;
707 
708  /* Arc above the unit semicircle */
710  A1.x = -1; A1.y = 3;
711  A2.x = 0 ; A2.y = 2;
712  A3.x = 1 ; A3.y = 3;
713  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
714  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
715  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
716 
717  /* Arc grazes the unit semicircle */
719  A1.x = -1; A1.y = 2;
720  A2.x = 0 ; A2.y = 1;
721  A3.x = 1 ; A3.y = 2;
722  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
723  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
724  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
725 
726  /* Circles intersect, but arcs do not */
728  A1.x = -1; A1.y = 1;
729  A2.x = 0; A2.y = 2;
730  A3.x = 1; A3.y = 1;
731  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
732  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
733  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2)-1, 0.000001);
734 
735  /* Circles and arcs intersect */
737  A1.x = -1; A1.y = 1;
738  A2.x = 0; A2.y = 0;
739  A3.x = 1; A3.y = 1;
740  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
741  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
742  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
743 
744  /* Concentric: and fully parallel */
746  A1.x = -2.0; A1.y = 0.0;
747  A2.x = 0.0; A2.y = 2.0;
748  A3.x = 2.0; A3.y = 0.0;
749  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
750  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
751  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
752 
753  /* Concentric: with A fully included in B's range */
755  A1.x = -0.5 / sqrt(2.0); A1.y = 0.5 / sqrt(2.0);
756  A2.x = 0.0; A2.y = 0.5;
757  A3.x = 0.5 / sqrt(2.0); A3.y = 0.5 / sqrt(2.0);
758  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
759  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
760  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
761 
762  /* Concentric: with A partially included in B's range */
764  A1.x = -0.5 / sqrt(2.0); A1.y = -0.5 / sqrt(2.0);
765  A2.x = -0.5; A2.y = 0.0;
766  A3.x = -0.5 / sqrt(2.0); A3.y = 0.5 / sqrt(2.0);
767  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
768  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
769  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
770 
771  /* Concentric: with A and B without parallel segments */
773  A1.x = -0.5 / sqrt(2.0); A1.y = -0.5 / sqrt(2.0);
774  A2.x = 0.0; A2.y = -0.5;
775  A3.x = 0.5 / sqrt(2.0); A3.y = -0.5 / sqrt(2.0);
776  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
777  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
778  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.736813, 0.000001);
779 
780  /* Concentric: Arcs are the same */
782  A1.x = -1.0; A1.y = 0.0;
783  A2.x = 0.0; A2.y = 1.0;
784  A3.x = 1.0; A3.y = 0.0;
785  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
786  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
787  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.0, 0.000001);
788 
789  /* Check different orientations */
790  B1.x = -10.0; B1.y = 0.0;
791  B2.x = 0.0 ; B2.y = 10.0;
792  B3.x = 10.0 ; B3.y = 0.0;
793 
795  A1.x = -22.0; A1.y = 0.0;
796  A2.x = -17.0; A2.y = -5.0;
797  A3.x = -12.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, 2.0, 0.000001);
801 
803  A1.x = -19.0; A1.y = 0.0;
804  A2.x = -14.0; A2.y = -5.0;
805  A3.x = - 9.0; A3.y = 0.0;
806  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
807  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
808  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
809 
811  A1.x = -9.0; A1.y = 0.0;
812  A2.x = -4.0; A2.y = -5.0;
813  A3.x = 1.0; A3.y = 0.0;
814  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
815  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
816  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
817 
819  A1.x = -1.0; A1.y = 0.0;
820  A2.x = 4.0; A2.y = -5.0;
821  A3.x = 9.0; A3.y = 0.0;
822  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
823  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
824  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
825 
827  A1.x = 1.0; A1.y = 0.0;
828  A2.x = 6.0; A2.y = -5.0;
829  A3.x = 11.0; A3.y = 0.0;
830  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
831  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
832  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
833 
835  A1.x = 11.0; A1.y = 0.0;
836  A2.x = 16.0; A2.y = -5.0;
837  A3.x = 21.0; A3.y = 0.0;
838  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
839  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
840  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
841 
842 
844  A1.x = -15.0; A1.y = -6.0;
845  A2.x = -10.0; A2.y = -1.0;
846  A3.x = - 5.0; A3.y = -6.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, 1.0, 0.000001);
850 
852  A1.x = -5.0; A1.y = 0.0;
853  A2.x = 0.0; A2.y = 5.0;
854  A3.x = 5.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, 5.0, 0.000001);
858 
860  A1.x = -5.0; A1.y = 0.0;
861  A2.x = 0.0; A2.y = -5.0;
862  A3.x = 5.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, 5.0, 0.000001);
866 
867 }
#define LW_SUCCESS
Definition: liblwgeom.h:80
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:1493
double x
Definition: liblwgeom.h:328
#define DIST_MIN
Definition: measures.h:44
double y
Definition: liblwgeom.h:328
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
Here is the call graph for this function:
Here is the caller graph for this function: