Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="newX"></param>
        /// <param name="newY"></param>
        /// <param name="pointHash"></param>
        /// <returns></returns>
        public bool SetPoint(double newX, double newY, int pointHash)
        {
            double dX  = 0;
            double dY  = 0;
            bool   res = false;

            switch (PointHash.GetPointIndex(pointHash))
            {
            case 1:
                dX  = newX - X1;
                dY  = newY - Y1;
                res = OnChangeP1(newX, newY);
                if (LocalConstraint != 0)
                {
                    res = OnChangeP2(X2 + dX, Y2 + dY);
                }
                break;

            case 2:
                dX  = newX - X2;
                dY  = newY - Y2;
                res = OnChangeP2(newX, newY);
                if (LocalConstraint != 0)
                {
                    res = OnChangeP1(X1 + dX, Y1 + dY);
                }
                break;
            }
            return(res);
        }
        public void PoinsAreEquals()
        {
            DcPoint point1 = new DcPoint(new Point(100, 300), PointHash.CreateHash(1, 2));
            DcPoint point2 = new DcPoint(new Point(100, 300), PointHash.CreateHash(2, 3));

            Assert.IsTrue(point1.Equals(point2));
        }
        public void PoinsAreNotEquals()
        {
            DcPoint point1 = new DcPoint(new Point(100, 250), PointHash.CreateHash(1, 2));
            DcPoint point2 = new DcPoint(new Point(100, 300), PointHash.CreateHash(2, 2));

            Assert.IsFalse(point1.Equals(point2));
        }
Exemple #4
0
        public void GetOwnerID_1048576_Test()
        {
            int expected = 0;
            var actual   = PointHash.GetIdFromHash(1048576);

            Assert.AreEqual(expected, actual);
        }
Exemple #5
0
        public void SetConstraint_Depended_Reference_Added_To_Active()
        {
            // Init
            IDictionary <int, DcPoint> pointCollection = new Dictionary <int, DcPoint>();
            DcLineSegment lineSegment = new DcLineSegment(100, 100, 100, 200);

            PointManager.AddPrimitivePoints(pointCollection, lineSegment);
            DcPoint point = new DcPoint(100, 200, PointHash.CreateHash(1, 1));

            // Action
            point = PointManager.SetConstraint(point, pointCollection);

            var ActiveHash = 0;

            foreach (var item in lineSegment.Points)
            {
                if (item.Value.X == 100 && item.Value.Y == 200)
                {
                    ActiveHash = item.Key;
                }
            }

            DcPoint activePoint = pointCollection[ActiveHash];

            var expected = point.GetHashCode();

            var actual = activePoint.DependedHash;

            Assert.AreEqual(expected, actual);
        }
Exemple #6
0
        public void GetOwnerID_2097500_Test()
        {
            int expected = 348;
            var actual   = PointHash.GetIdFromHash(2097500);

            Assert.AreEqual(expected, actual);
        }
Exemple #7
0
        public void GetPointIndex_2097500_Test()
        {
            int expected = 2;
            var actual   = PointHash.GetPointIndex(2097500);

            Assert.AreEqual(expected, actual);
        }
Exemple #8
0
        public void GetPointIndex_1048576_Test()
        {
            int expected = 1;
            var actual   = PointHash.GetPointIndex(1048576);

            Assert.AreEqual(expected, actual);
        }
Exemple #9
0
        public void CreateHash_Test_2_348()
        {
            int expected = 2097500;
            var actual   = PointHash.CreateHash(2, 348);

            Assert.AreEqual(expected, actual);
        }
Exemple #10
0
        public void CreateHash_Test_1_0()
        {
            int expected = 1048576;
            var actual   = PointHash.CreateHash(1, 0);

            Assert.AreEqual(expected, actual);
        }
Exemple #11
0
        public void CreateHash_Test_0_1()
        {
            int expected = 1;
            var actual   = PointHash.CreateHash(0, 1);

            Assert.AreEqual(expected, actual);
        }
Exemple #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="originPoint"></param>
        /// <param name="length"></param>
        /// <param name="angle"></param>
        public DcLineSegment(Point originPoint, double length, double angle)
        {
            _x1 = originPoint.X;
            _y1 = originPoint.Y;

            while (angle >= 360)
            {
                angle -= 360;
            }
            while (angle <= -360)
            {
                angle += 360;
            }
            _angle = angle < 0 ? angle + 360 : angle;

            _length = length;

            if (angle == 0)
            {
                _x2 = _x1 + length;
                _y2 = _y1;
            }
            else if (angle == 180)
            {
                _x2 = _x1 - length;
                _y2 = _y1;
            }
            else if (angle == 90)
            {
                _x2 = _x1;
                _y2 = _y1 + length;
            }
            else if (angle == 270)
            {
                _x2 = _x1;
                _y2 = _y1 - length;
            }
            else
            {
                _x2 = _x1 + DcMath.Xoffset(length, angle);
                _y2 = _y1 + DcMath.Yoffset(length, angle);
            }

            _height = DcMath.GetHeight(Y1, Y2);
            _width  = DcMath.GetWidth(X1, X2);

            _p1Hash = PointHash.CreateHash(1, _id);
            _p2Hash = PointHash.CreateHash(2, _id);

            _points = new Dictionary <int, Point>()
            {
                { _p1Hash, new Point(_x1, _y1) },
                { _p2Hash, new Point(_x2, _y2) }
            };
        }
Exemple #13
0
        public void SetConstraint_No_Active_References()
        {
            // Init
            IDictionary <int, DcPoint> pointCollection = new Dictionary <int, DcPoint>();
            DcLineSegment lineSegment = new DcLineSegment(100, 100, 100, 200);

            PointManager.AddPrimitivePoints(pointCollection, lineSegment);
            DcPoint point = new DcPoint(110, 200, PointHash.CreateHash(1, 1));

            // Action
            point = PointManager.SetConstraint(point, pointCollection);

            var expected = 0;

            var actual = point.ActiveHash;

            Assert.AreEqual(expected, actual);
        }
Exemple #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        public DcLineSegment(double x1, double y1, double x2, double y2)
        {
            _x1 = x1;
            _y1 = y1;
            _x2 = x2;
            _y2 = y2;

            _p1Hash = PointHash.CreateHash(1, _id);
            _p2Hash = PointHash.CreateHash(2, _id);

            _points = new Dictionary <int, Point>()
            {
                { _p1Hash, new Point(X1, Y1) },
                { _p2Hash, new Point(X2, Y2) }
            };

            _length = DcMath.GetDistance(X1, Y1, X2, Y2);
            _angle  = DcMath.GetLineSegmentAngle(this);
            _height = DcMath.GetHeight(Y1, Y2);
            _width  = DcMath.GetWidth(X1, X2);
        }