Пример #1
0
        public void EqualsTest()
        {
            Init();
            LineSegment newLine = new Datas.LineSegment(new Point3D()
            {
                X = 0, Y = 0, Z = 0
            }, new Point3D()
            {
                X = 1, Y = 0, Z = 0
            });
            var result = this.LineSegment.Equals(newLine);

            Assert.AreEqual(result, true);

            Init();
            LineSegment newLine2 = new Datas.LineSegment(new Point3D()
            {
                X = 2, Y = 0, Z = 0
            }, new Point3D()
            {
                X = 3, Y = 0, Z = 0
            });
            var result2 = this.LineSegment.Equals(newLine2);

            Assert.AreEqual(result2, false);
        }
Пример #2
0
        public void GetLengthTest()
        {
            //线段起始点为空测试
            object      exception = null;
            LineSegment nullTest  = new Datas.LineSegment(null, null);

            try
            {
                var dir_null = nullTest.GetLength();
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            Assert.IsNotNull(exception);


            //长度测试
            Init();
            var length = this.LineSegment.GetLength();

            Assert.AreEqual(length, 1);
        }
Пример #3
0
        public void GetCrossPointsTest()
        {
            Init();
            Point3D otherStart = new Point3D()
            {
                X = 0.5, Y = 1, Z = 0
            };
            Point3D otherEnd = new Point3D()
            {
                X = 0.5, Y = -1, Z = 0
            };
            LineSegment    otherLine = new Datas.LineSegment(otherStart, otherEnd);
            List <Point3D> list      = LineSegment.GetCrossPoints(otherLine) as List <Point3D>;

            Assert.IsNotNull(list);
            Assert.AreEqual(list.Count, 1);
            Assert.AreEqual(Math.Round(list[0].X, 8), 0.5);
            Assert.AreEqual(Math.Round(list[0].Y, 8), 0);


            Init();
            Point3D otherStart2 = new Point3D()
            {
                X = 0.5, Y = 1, Z = 0
            };
            Point3D otherEnd2 = new Point3D()
            {
                X = 0.5, Y = 0.5, Z = 0
            };
            LineSegment    otherLine2 = new Datas.LineSegment(otherStart2, otherEnd2);
            List <Point3D> list2      = LineSegment.GetCrossPoints(otherLine2) as List <Point3D>;

            Assert.IsNotNull(list2);
            Assert.AreEqual(list2.Count, 1);
            Assert.AreEqual(Math.Round(list2[0].X, 8), 0.5);
            Assert.AreEqual(Math.Round(list2[0].Y, 8), 0);

            Init();
            Point3D otherStart3 = new Point3D()
            {
                X = 2, Y = 1, Z = 0
            };
            Point3D otherEnd3 = new Point3D()
            {
                X = 2, Y = 0.5, Z = 0
            };
            LineSegment    otherLine3 = new Datas.LineSegment(otherStart3, otherEnd3);
            List <Point3D> list3      = LineSegment.GetCrossPoints(otherLine3) as List <Point3D>;

            Assert.IsNotNull(list3);
            Assert.AreEqual(list3.Count, 0);

            Init();
            Point3D otherStart4 = new Point3D()
            {
                X = 0.5, Y = 0.5, Z = 0
            };
            Point3D otherEnd4 = new Point3D()
            {
                X = 0.5, Y = 1, Z = 0
            };
            LineSegment    otherLine4 = new Datas.LineSegment(otherStart4, otherEnd4);
            List <Point3D> list4      = LineSegment.GetCrossPoints(otherLine4) as List <Point3D>;

            Assert.IsNotNull(list4);
            Assert.AreEqual(list4.Count, 0);

            Init();
            Point3D otherStart5 = new Point3D()
            {
                X = 0.5, Y = 0, Z = 0
            };
            Point3D otherEnd5 = new Point3D()
            {
                X = 0.5, Y = -0.5, Z = 0
            };
            LineSegment    otherLine5 = new Datas.LineSegment(otherStart5, otherEnd5);
            List <Point3D> list5      = LineSegment.GetCrossPoints(otherLine5) as List <Point3D>;

            Assert.IsNotNull(list5);
            Assert.AreEqual(list5.Count, 1);
            Assert.AreEqual(Math.Round(list5[0].X, 8), 0.5);
            Assert.AreEqual(Math.Round(list5[0].Y, 8), 0);

            Init();
            Point3D otherStart6 = new Point3D()
            {
                X = -0.5, Y = 0, Z = 0
            };
            Point3D otherEnd6 = new Point3D()
            {
                X = 0.5, Y = 0, Z = 0
            };
            LineSegment    otherLine6 = new Datas.LineSegment(otherStart6, otherEnd6);
            List <Point3D> list6      = LineSegment.GetCrossPoints(otherLine6) as List <Point3D>;

            Assert.IsNotNull(list6);
            Assert.AreEqual(list6.Count, 0);
        }
Пример #4
0
        public void GetCurveCurveRelationShipTypeTest()
        {
            Init();
            Point3D otherStart = new Point3D()
            {
                X = 0.5, Y = 1, Z = 0
            };
            Point3D otherEnd = new Point3D()
            {
                X = 0.5, Y = -1, Z = 0
            };
            LineSegment otherLine          = new Datas.LineSegment(otherStart, otherEnd);
            LineCurveRelationShipType type = LineSegment.GetCurveCurveRelationShipType(otherLine);

            Assert.AreEqual(type, LineCurveRelationShipType.Intersect);

            Init();
            Point3D otherStart2 = new Point3D()
            {
                X = 0.5, Y = 1, Z = 0
            };
            Point3D otherEnd2 = new Point3D()
            {
                X = 0.5, Y = 0.5, Z = 0
            };
            LineSegment otherLine2          = new Datas.LineSegment(otherStart2, otherEnd2);
            LineCurveRelationShipType type2 = LineSegment.GetCurveCurveRelationShipType(otherLine2);

            Assert.AreEqual(type2, LineCurveRelationShipType.Intersect);

            Init();
            Point3D otherStart3 = new Point3D()
            {
                X = 2, Y = 1, Z = 0
            };
            Point3D otherEnd3 = new Point3D()
            {
                X = 2, Y = 0.5, Z = 0
            };
            LineSegment otherLine3          = new Datas.LineSegment(otherStart3, otherEnd3);
            LineCurveRelationShipType type3 = LineSegment.GetCurveCurveRelationShipType(otherLine3);

            Assert.AreEqual(type3, LineCurveRelationShipType.Right);

            Init();
            Point3D otherStart4 = new Point3D()
            {
                X = 0.5, Y = 0.5, Z = 0
            };
            Point3D otherEnd4 = new Point3D()
            {
                X = 0.5, Y = 1, Z = 0
            };
            LineSegment otherLine4          = new Datas.LineSegment(otherStart4, otherEnd4);
            LineCurveRelationShipType type4 = LineSegment.GetCurveCurveRelationShipType(otherLine4);

            Assert.AreEqual(type4, LineCurveRelationShipType.Others);

            Init();
            Point3D otherStart5 = new Point3D()
            {
                X = 0.5, Y = 0, Z = 0
            };
            Point3D otherEnd5 = new Point3D()
            {
                X = 0.5, Y = 0.5, Z = 0
            };
            LineSegment otherLine5          = new Datas.LineSegment(otherStart5, otherEnd5);
            LineCurveRelationShipType type5 = LineSegment.GetCurveCurveRelationShipType(otherLine5);

            Assert.AreEqual(type5, LineCurveRelationShipType.Intersect);

            Init();
            Point3D otherStart6 = new Point3D()
            {
                X = -0.5, Y = 0, Z = 0
            };
            Point3D otherEnd6 = new Point3D()
            {
                X = 0.5, Y = 0, Z = 0
            };
            LineSegment otherLine6          = new Datas.LineSegment(otherStart6, otherEnd6);
            LineCurveRelationShipType type6 = LineSegment.GetCurveCurveRelationShipType(otherLine6);

            Assert.AreEqual(type6, LineCurveRelationShipType.Coincide);

            Init();
            Point3D otherStart7 = new Point3D()
            {
                X = 2, Y = 2, Z = 0
            };
            Point3D otherEnd7 = new Point3D()
            {
                X = 2, Y = 3, Z = 0
            };
            LineSegment otherLine7          = new Datas.LineSegment(otherStart7, otherEnd7);
            LineCurveRelationShipType type7 = LineSegment.GetCurveCurveRelationShipType(otherLine7);

            Assert.AreEqual(type7, LineCurveRelationShipType.Left);

            Init();
            Point3D otherStart8 = new Point3D()
            {
                X = 1, Y = -1, Z = 0
            };
            Point3D otherEnd8 = new Point3D()
            {
                X = 1, Y = 3, Z = 0
            };
            LineSegment otherLine8          = new Datas.LineSegment(otherStart8, otherEnd8);
            LineCurveRelationShipType type8 = LineSegment.GetCurveCurveRelationShipType(otherLine8);

            Assert.AreEqual(type8, LineCurveRelationShipType.On_Left);
        }
Пример #5
0
        public void GetIntersectionTest()
        {
            Init();
            Point3D otherStart = new Point3D()
            {
                X = 0.5, Y = 1, Z = 0
            };
            Point3D otherEnd = new Point3D()
            {
                X = 0.5, Y = -1, Z = 0
            };
            LineSegment otherLine = new Datas.LineSegment(otherStart, otherEnd);
            Point3D     point     = LineSegment.GetIntersection(otherLine);

            Assert.AreEqual(Math.Round(point.X, 6), 0.5);
            Assert.AreEqual(Math.Round(point.Y, 6), 0);

            Init();
            Point3D otherStart2 = new Point3D()
            {
                X = 0.5, Y = 1, Z = 0
            };
            Point3D otherEnd2 = new Point3D()
            {
                X = 0.5, Y = 0.5, Z = 0
            };
            LineSegment otherLine2 = new Datas.LineSegment(otherStart2, otherEnd2);
            Point3D     point2     = LineSegment.GetIntersection(otherLine2);

            Assert.IsNull(point2);

            Init();
            Point3D otherStart3 = new Point3D()
            {
                X = 1.5, Y = 1, Z = 0
            };
            Point3D otherEnd3 = new Point3D()
            {
                X = 1.5, Y = -1, Z = 0
            };
            LineSegment otherLine3 = new Datas.LineSegment(otherStart3, otherEnd3);
            Point3D     point3     = LineSegment.GetIntersection(otherLine3);

            Assert.IsNull(point3);

            Init();
            Point3D otherStart4 = new Point3D()
            {
                X = 1, Y = 1, Z = 0
            };
            Point3D otherEnd4 = new Point3D()
            {
                X = 1, Y = -1, Z = 0
            };
            LineSegment otherLine4 = new Datas.LineSegment(otherStart4, otherEnd4);
            Point3D     point4     = LineSegment.GetIntersection(otherLine4);

            Assert.AreEqual(Math.Round(point4.X, 6), 1);
            Assert.AreEqual(Math.Round(point4.Y, 6), 0);

            Init();
            Point3D otherStart5 = new Point3D()
            {
                X = 1.5, Y = 0, Z = 0
            };
            Point3D otherEnd5 = new Point3D()
            {
                X = 2, Y = 0, Z = 0
            };
            LineSegment otherLine5 = new Datas.LineSegment(otherStart5, otherEnd5);
            Point3D     point5     = LineSegment.GetIntersection(otherLine5);

            Assert.IsNull(point5);
        }
Пример #6
0
        public void GetDirectionTest()
        {
            //线段起始点为空测试
            object      exception = null;
            LineSegment nullTest  = new Datas.LineSegment(null, null);

            try
            {
                var dir_null = nullTest.GetDirection();
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            Assert.IsNotNull(exception);

            //垂直测试(向东)
            Init();
            var dir = this.LineSegment.GetDirection();

            Assert.AreEqual(dir, Math.PI / 2);

            //正北测试
            Point3D startPoint2 = new Point3D()
            {
                X = 0, Y = 0, Z = 0
            };
            Point3D endPoint2 = new Point3D()
            {
                X = 0, Y = 1, Z = 0
            };
            LineSegment LineSegment2 = new LineSegment(startPoint2, endPoint2);
            var         dir2         = LineSegment2.GetDirection();

            Assert.AreEqual(dir2, 0);

            //正南测试
            Point3D startPoint3 = new Point3D()
            {
                X = 0, Y = 0, Z = 0
            };
            Point3D endPoint3 = new Point3D()
            {
                X = 0, Y = -1, Z = 0
            };
            LineSegment LineSegment3 = new LineSegment(startPoint3, endPoint3);
            var         dir3         = LineSegment3.GetDirection();

            Assert.AreEqual(dir3, Math.PI);

            //垂直测试(向西)
            Point3D startPoint4 = new Point3D()
            {
                X = 0, Y = 0, Z = 0
            };
            Point3D endPoint4 = new Point3D()
            {
                X = -1, Y = 0, Z = 0
            };
            LineSegment LineSegment4 = new LineSegment(startPoint4, endPoint4);
            var         dir4         = LineSegment4.GetDirection();

            Assert.AreEqual(dir4, -Math.PI / 2);
        }