PostGIS  2.5.0dev-r@@SVN_REVISION@@
static void test_lw_dist2d_arc_arc ( void  )
static

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

637 {
638  /* lw_dist2d_arc_arc(const POINT2D *A1, const POINT2D *A2, const POINT2D *A3,
639  const POINT2D *B1, const POINT2D *B2, const POINT2D *B3,
640  DISTPTS *dl) */
641  DISTPTS dl;
642  POINT2D A1, A2, A3, B1, B2, B3;
643  int rv;
644 
645  /* Unit semicircle at 0,0 */
646  B1.x = -1; B1.y = 0;
647  B2.x = 0 ; B2.y = 1;
648  B3.x = 1 ; B3.y = 0;
649 
650  /* Arc above the unit semicircle */
652  A1.x = -1; A1.y = 3;
653  A2.x = 0 ; A2.y = 2;
654  A3.x = 1 ; A3.y = 3;
655  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
656  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
657  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1, 0.000001);
658 
659  /* Arc grazes the unit semicircle */
661  A1.x = -1; A1.y = 2;
662  A2.x = 0 ; A2.y = 1;
663  A3.x = 1 ; A3.y = 2;
664  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
665  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
666  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
667 
668  /* Circles intersect, but arcs do not */
670  A1.x = -1; A1.y = 1;
671  A2.x = 0; A2.y = 2;
672  A3.x = 1; A3.y = 1;
673  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
674  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
675  CU_ASSERT_DOUBLE_EQUAL(dl.distance, sqrt(2)-1, 0.000001);
676 
677  /* Circles and arcs intersect */
679  A1.x = -1; A1.y = 1;
680  A2.x = 0; A2.y = 0;
681  A3.x = 1; A3.y = 1;
682  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
683  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
684  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0, 0.000001);
685 
686  /* Concentric: and fully parallel */
688  A1.x = -2.0; A1.y = 0.0;
689  A2.x = 0.0; A2.y = 2.0;
690  A3.x = 2.0; A3.y = 0.0;
691  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
692  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
693  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
694 
695  /* Concentric: with A fully included in B's range */
697  A1.x = -0.5 / sqrt(2.0); A1.y = 0.5 / sqrt(2.0);
698  A2.x = 0.0; A2.y = 0.5;
699  A3.x = 0.5 / sqrt(2.0); A3.y = 0.5 / sqrt(2.0);
700  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
701  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
702  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
703 
704  /* Concentric: with A partially included in B's range */
706  A1.x = -0.5 / sqrt(2.0); A1.y = -0.5 / sqrt(2.0);
707  A2.x = -0.5; A2.y = 0.0;
708  A3.x = -0.5 / sqrt(2.0); A3.y = 0.5 / sqrt(2.0);
709  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
710  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
711  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.5, 0.000001);
712 
713  /* Concentric: with A and B without parallel segments */
715  A1.x = -0.5 / sqrt(2.0); A1.y = -0.5 / sqrt(2.0);
716  A2.x = 0.0; A2.y = -0.5;
717  A3.x = 0.5 / sqrt(2.0); A3.y = -0.5 / sqrt(2.0);
718  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
719  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
720  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.736813, 0.000001);
721 
722  /* Concentric: Arcs are the same */
724  A1.x = -1.0; A1.y = 0.0;
725  A2.x = 0.0; A2.y = 1.0;
726  A3.x = 1.0; A3.y = 0.0;
727  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
728  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
729  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 0.0, 0.000001);
730 
731  /* Check different orientations */
732  B1.x = -10.0; B1.y = 0.0;
733  B2.x = 0.0 ; B2.y = 10.0;
734  B3.x = 10.0 ; B3.y = 0.0;
735 
737  A1.x = -22.0; A1.y = 0.0;
738  A2.x = -17.0; A2.y = -5.0;
739  A3.x = -12.0; A3.y = 0.0;
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, 2.0, 0.000001);
743 
745  A1.x = -19.0; A1.y = 0.0;
746  A2.x = -14.0; A2.y = -5.0;
747  A3.x = - 9.0; A3.y = 0.0;
748  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
749  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
750  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
751 
753  A1.x = -9.0; A1.y = 0.0;
754  A2.x = -4.0; A2.y = -5.0;
755  A3.x = 1.0; A3.y = 0.0;
756  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
757  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
758  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
759 
761  A1.x = -1.0; A1.y = 0.0;
762  A2.x = 4.0; A2.y = -5.0;
763  A3.x = 9.0; A3.y = 0.0;
764  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
765  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
766  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
767 
769  A1.x = 1.0; A1.y = 0.0;
770  A2.x = 6.0; A2.y = -5.0;
771  A3.x = 11.0; A3.y = 0.0;
772  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
773  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
774  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 1.0, 0.000001);
775 
777  A1.x = 11.0; A1.y = 0.0;
778  A2.x = 16.0; A2.y = -5.0;
779  A3.x = 21.0; A3.y = 0.0;
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, 1.0, 0.000001);
783 
784 
786  A1.x = -15.0; A1.y = -6.0;
787  A2.x = -10.0; A2.y = -1.0;
788  A3.x = - 5.0; A3.y = -6.0;
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, 1.0, 0.000001);
792 
794  A1.x = -5.0; A1.y = 0.0;
795  A2.x = 0.0; A2.y = 5.0;
796  A3.x = 5.0; A3.y = 0.0;
797  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
798  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
799  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 5.0, 0.000001);
800 
802  A1.x = -5.0; A1.y = 0.0;
803  A2.x = 0.0; A2.y = -5.0;
804  A3.x = 5.0; A3.y = 0.0;
805  rv = lw_dist2d_arc_arc(&A1, &A2, &A3, &B1, &B2, &B3, &dl);
806  CU_ASSERT_EQUAL( rv, LW_SUCCESS );
807  CU_ASSERT_DOUBLE_EQUAL(dl.distance, 5.0, 0.000001);
808 
809 
810 }
#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:1493
double x
Definition: liblwgeom.h:327
#define DIST_MIN
Definition: measures.h:41
double y
Definition: liblwgeom.h:327
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: