예제 #1
0
        public void LineDistance2DSegmentTest()
        {
            double delta = 0.000000000000001;

            // create the line to test.
            PointF2D a = new PointF2D(0, 0);
            PointF2D b = new PointF2D(1, 1);
            LineF2D line = new LineF2D(a, b,true,true);

            // calculate the results
            double sqrt_2 = (double)System.Math.Sqrt(2);
            double sqrt_2_div_2 = (double)System.Math.Sqrt(2) / 2.0f;

            // the point to test to.
            PointF2D c = new PointF2D(1, 0);
            Assert.AreEqual(line.Distance(c), sqrt_2_div_2, delta, string.Format("Point distance should be {0}f!", sqrt_2_div_2));

            // the point to test to.
            c = new PointF2D(0, 1);
            Assert.AreEqual(line.Distance(c), sqrt_2_div_2, delta, string.Format("Point distance should be {0}f!", sqrt_2_div_2));

            // the point to test to.
            c = new PointF2D(2, 2);
            Assert.AreEqual(line.Distance(c), sqrt_2, delta);

            // the point to test to.
            c = new PointF2D(2, 3);
            Assert.AreEqual(line.Distance(c), 2.23606797749979, delta, string.Format("Point distance should be {0}f!", sqrt_2_div_2));

            // the point to test to.
            c = new PointF2D(3, 2);
            Assert.AreEqual(line.Distance(c), 2.23606797749979, delta, string.Format("Point distance should be {0}f!", sqrt_2_div_2));

            // the point to test to.
            c = new PointF2D(1, 0);
            Assert.AreEqual(line.Distance(c), sqrt_2_div_2, delta, string.Format("Point distance should be {0}f!", sqrt_2_div_2));

            // the point to test to.
            c = new PointF2D(0, 1);
            Assert.AreEqual(line.Distance(c), sqrt_2_div_2, delta, string.Format("Point distance should be {0}f!", sqrt_2_div_2));

            // the point to test to.
            c = new PointF2D(2, 2);
            Assert.AreEqual(line.Distance(c), sqrt_2, delta, string.Format("Point distance should be {0}!", sqrt_2));

            // the point to test to.
            c = new PointF2D(2, 1);
            Assert.AreEqual(line.Distance(c), 1, delta, string.Format("Point distance should be {0}f!", 1));

            // the point to test to.
            c = new PointF2D(1, 2);
            Assert.AreEqual(line.Distance(c), 1, delta, string.Format("Point distance should be {0}f!", 1));

            // the point to test to.
            c = new PointF2D(-1, -1);
            Assert.AreEqual(line.Distance(c), sqrt_2, delta, string.Format("Point distance should be {0}f!", 1));

            // the point to test to.
            c = new PointF2D(1, -1);
            Assert.AreEqual(line.Distance(c), sqrt_2, delta, string.Format("Point distance should be {0}f!", 1));
        }
예제 #2
0
        public void Point2DTest()
        {
            // create the test cases.
            PointF2D a = new PointF2D(0, 0);
            PointF2D b = new PointF2D(1, 1);

            // calculate the results
            double sqrt_2 = (double)System.Math.Sqrt(2);
            double sqrt_2_div_2 = (double)System.Math.Sqrt(2) / 2.0f;

            // test distance.
            Assert.AreEqual(a.Distance(b), sqrt_2, string.Format("Distance should be {0}!", sqrt_2));

            // test substraction into vector.
            VectorF2D ab = b - a;
            Assert.AreEqual(ab[0], 1, "Vector should be 1 at index 0!");
            Assert.AreEqual(ab[1], 1, "Vector should be 1 at index 1!");
            VectorF2D ba = a - b;
            Assert.AreEqual(ba[0], -1, "Vector should be -1 at index 0!");
            Assert.AreEqual(ba[1], -1, "Vector should be -1 at index 1!");
        }
예제 #3
0
 /// <summary>
 /// Calculates the distance between this point and the given point.
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public double Distance(PointF2D p)
 {
     return PointF2D.Distance(this, p);
 }
예제 #4
0
        public void LinePosition2DTest()
        {
            PointF2D a = new PointF2D(0, 0);
            PointF2D b = new PointF2D(1, 1);

            LineF2D line = new LineF2D(a, b);

            // test where the position lie.
            Assert.AreEqual(line.PositionOfPoint(new PointF2D(0, 0.5f)), LinePointPosition.Left, "Point position should be right!");
            Assert.AreEqual(line.PositionOfPoint(new PointF2D(0.5f, 0.5f)), LinePointPosition.On, "Point position should be on!");
            Assert.AreEqual(line.PositionOfPoint(new PointF2D(0.5f, 0)), LinePointPosition.Right, "Point position should be left!");
        }
예제 #5
0
파일: View.cs 프로젝트: jorik041/osmsharp
        /// <summary>
        /// Converts the given geo coordinates to projected two dimension versions on the target.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="points"></param>
        /// <returns></returns>
        public PointF2D[] ConvertToTargetCoordinates(
            ITarget target,
            GeoCoordinate[] points)
        {
            PointF2D[] target_points = new PointF2D[points.Length];

            for (int idx = 0; idx < points.Length; idx++)
            {
                target_points[idx] = this.ConvertToTargetCoordinates(target, points[idx]);
            }

            return target_points;
        }