Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        internal static void AddPrimitivePoints(IDictionary <int, DcPoint> pointCollection, IPrimitive primitive)
        {
            foreach (var item in primitive.Points)
            {
                DcPoint newPoint = new DcPoint(item.Value, item.Key);

                newPoint = SetConstraint(newPoint, pointCollection);

                pointCollection.Add(item.Key, newPoint);
            }
        }
Esempio n. 5
0
        internal static bool ResolveConstraint(DrCanvas canvas, double newX, double newY, int issuerHash)
        {
            DcPoint issuerPoint = canvas.PointCollection[issuerHash];
            DcPoint subPoint    = canvas.PointCollection[issuerPoint.DependedHash];

            IVisualObject visualObject = canvas.GetDrawingVisualById(PointHash.GetIdFromHash(subPoint.GetHashCode()))?.VisualObject;

            if (visualObject is IPrimitive primitive)
            {
                return(primitive.SetPoint(newX, newY, subPoint.GetHashCode()));
            }

            return(false);
        }
Esempio n. 6
0
        internal static DcPoint SetConstraint(DcPoint newPoint, IDictionary <int, DcPoint> pointCollection)
        {
            if (!pointCollection.Values.Contains(newPoint))
            {
                return(newPoint);
            }

            DcPoint pointIssuer = pointCollection.Values.Where(v => v.Equals(newPoint)).First();

            // Setting reference to the dependent point
            pointIssuer.DependedHash = newPoint.GetHashCode();
            pointCollection[pointIssuer.GetHashCode()] = pointIssuer;

            // Setting reference to the active point
            newPoint.ActiveHash = pointIssuer.GetHashCode();
            return(newPoint);
        }
Esempio n. 7
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);
        }