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)); }
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); }
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); } }
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); }
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); }
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); }