Пример #1
0
        public void AddRelation(Vertex v, RelationType r, double angle)
        {
            List <Edge> e2 = new List <Edge>();

            foreach (Edge e in edges)
            {
                if (e.A == v || e.B == v)
                {
                    e2.Add(e);
                }
            }
            if (!CanAddRelation(e2[0], r) || !CanAddRelation(e2[1], r))
            {
                MessageBox.Show("Cannot add relation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Vertex v2 = e2[1].A == v ? e2[1].B : e2[1].A;
            Point  w2 = new Point(v2.X - v.X, v2.Y - v.Y);

            double prevAngle = GetAngle(v);

            double dAngle = -(angle - prevAngle);

            double radians = (Math.PI / 180f) * dAngle;

            Point newW = new Point((int)(w2.X * Math.Cos(radians) - w2.Y * Math.Sin(radians)), (int)(w2.X * Math.Sin(radians) + w2.Y * Math.Cos(radians)));
            int   dx   = (newW.X + v.X) - v2.X;
            int   dy   = (newW.Y + v.Y) - v2.Y;

            int oldv2X = v2.X;
            int oldV2Y = v2.Y;

            v2.X = newW.X + v.X;
            v2.Y = newW.Y + v.Y;

            double newAngle = GetAngle(v);

            if (newAngle > angle + 5 || newAngle < angle - 5)
            {
                v2.X    = oldv2X;
                v2.Y    = oldV2Y;
                dAngle  = -dAngle;
                radians = (Math.PI / 180f) * dAngle;
                newW    = new Point((int)(w2.X * Math.Cos(radians) - w2.Y * Math.Sin(radians)), (int)(w2.X * Math.Sin(radians) + w2.Y * Math.Cos(radians)));
                dx      = (newW.X + v.X) - v2.X;
                dy      = (newW.Y + v.Y) - v2.Y;
                v2.X    = newW.X + v.X;
                v2.Y    = newW.Y + v.Y;
            }

            AngleRelation angleR = new AngleRelation(e2[0], e2[1]);

            FixRelation(v2, dx, dy, new List <Relation>());
            e2[0].RelationTypeE = RelationType.Angle;
            e2[1].RelationTypeE = RelationType.Angle;
            e2[0].W             = v;
            e2[1].W             = v;
            relations.Add(angleR);
        }
Пример #2
0
        public void MoveEdge(Edge e, int dx, int dy)
        {
            if (!edges.Contains(e))
            {
                return;
            }
            List <Relation> rel = GetEdgeRelations(e, relations);

            if (rel.Count != 0 && rel[0] is AngleRelation)
            {
                AngleRelation angleRel = (AngleRelation)rel[0];
                Vertex[]      changedV = angleRel.MoveEdge(e, dx, dy);
                foreach (Vertex v in changedV)
                {
                    FixRelation(v, dx, dy, new List <Relation>()
                    {
                        rel[0]
                    });
                }
                return;
            }
            e.A.ChangeLocation(dx, dy);
            e.B.ChangeLocation(dx, dy);
            FixRelation(e.A, dx, dy, new List <Relation>());
            FixRelation(e.B, dx, dy, new List <Relation>());
        }