Ejemplo n.º 1
0
        }//Addes X and Y to all points

        public void AddPointOnEdge(Edge e)
        {
            Vertice start  = e.Start;
            Vertice end    = e.End;
            Vertice middle = new Vertice((start.x + end.x) / 2, (start.y + end.y) / 2);

            points.Add(middle);
            if (e.relation != RelationEnum.None)
            {
                Relation ps1 = ps.FirstOrDefault(x => x.edge1.Equals(e) || x.edge2.Equals(e));
                ps1.edge1.relation = RelationEnum.None;
                ps1.edge2.relation = RelationEnum.None;
                ps.Remove(ps1);
            }
            edges.Remove(e);
            edges.Add(new Edge(start, middle));
            edges.Add(new Edge(middle, end));
        }
Ejemplo n.º 2
0
        public bool RemovePoint(Vertice point)
        {
            if (points.Count > 3)
            {
                Vertice a = null;
                Vertice b = null;
                (Edge, Edge)associatedEdges = GetEdgesFromPoint(point);
                if (associatedEdges.Item1 != null)
                {
                    a = associatedEdges.Item1.Start;
                    Edge e = associatedEdges.Item1;
                    if (e.relation != RelationEnum.None)
                    {
                        Relation ps1 = ps.FirstOrDefault(x => x.edge1.Equals(e) || x.edge2.Equals(e));
                        ps1.edge1.relation = RelationEnum.None;
                        ps1.edge2.relation = RelationEnum.None;
                        ps.Remove(ps1);
                    }
                    RemoveEdge(associatedEdges.Item1);
                }

                if (associatedEdges.Item2 != null)
                {
                    b = associatedEdges.Item2.End;
                    Edge e = associatedEdges.Item2;
                    if (e.relation != RelationEnum.None)
                    {
                        Relation ps2 = ps.FirstOrDefault(x => x.edge1.Equals(e) || x.edge2.Equals(e));
                        ps2.edge1.relation = RelationEnum.None;
                        ps2.edge2.relation = RelationEnum.None;
                        ps.Remove(ps2);
                    }
                    RemoveEdge(associatedEdges.Item2);
                }
                points.Remove(point);
                AddEdge(new Edge(a, b));
                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        public bool ContainsPoint(Vertice point)
        {
            int    A        = Start.y - End.y;
            int    B        = End.x - Start.x;
            int    C        = Start.y * (Start.x - End.x) + Start.x * (End.y - Start.y);
            double distance = (double)Math.Abs(A * point.x + B * point.y + C) / Math.Sqrt(A * A + B * B);

            if (distance < CONST.pointHalf)
            {
                double xy   = Math.Abs(Math.Sqrt(Math.Pow(End.x - Start.x, 2) + Math.Pow(End.y - Start.y, 2)));
                double xp   = Math.Abs(Math.Sqrt(Math.Pow(End.x - point.x, 2) + Math.Pow(End.y - point.y, 2)));
                double py   = Math.Abs(Math.Sqrt(Math.Pow(point.x - Start.x, 2) + Math.Pow(point.y - Start.y, 2)));
                double cosA = (Math.Pow(xy, 2) + Math.Pow(xp, 1) - Math.Pow(py, 2)) / (2 * xy * xp);
                double cosB = (Math.Pow(xy, 2) + Math.Pow(py, 1) - Math.Pow(xp, 2)) / (2 * xy * py);
                if (cosA > 0 && cosA < 1 && cosB > 0 && cosB < 1)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 4
0
        public bool MovePoint(Vertice start, Vertice end)
        {
            if (start != null && end != null)
            {
                (Edge, Edge)e = GetEdgesFromPoint(start);
                List <Vertice> oldVertices = points.Clone();
                if (e.Item1 != null)
                {
                    e.Item1.End.x = end.x;
                    e.Item1.End.y = end.y;
                }
                if (e.Item2 != null)
                {
                    e.Item2.Start.x = end.x;
                    e.Item2.Start.y = end.y;
                }
                start.x = end.x;
                start.y = end.y;
                if (!KeepRelations(e.Item2.End))
                {
                    for (int i = 0; i < oldVertices.Count; i++)
                    {
                        points[i].x = oldVertices[i].x;
                        points[i].y = oldVertices[i].y;
                    }
                    for (int i = oldVertices.Count - 1; i >= 0; i--)
                    {
                        oldVertices[i].Dispose();
                    }
                    MoveFigure(end.x - start.x, end.y - start.y);
                    return(false);
                }
                return(true);
            }
            return(false);



            //if (start != null && end != null)
            //{
            //    (Edge, Edge) e = GetEdgesFromPoint(start);
            //    if (!KeepRelations(e.Item2.End))
            //    {
            //        MoveFigure(end.x - start.x, end.y - start.y);
            //        return false;
            //    }
            //    else
            //    {
            //        if (e.Item1 != null)
            //        {
            //            e.Item1.End.x = end.x;
            //            e.Item1.End.y = end.y;
            //        }
            //        if (e.Item2 != null)
            //        {
            //            e.Item2.Start.x = end.x;
            //            e.Item2.Start.y = end.y;
            //        }
            //        start.x = end.x;
            //        start.y = end.y;
            //    }
            //    return true;
            //}
            //return false;
        }
Ejemplo n.º 5
0
        //HELPERS
        public bool KeepRelations(Vertice v)
        {
            List <Vertice> oldVertices         = points.Clone();
            int            indexer             = 0;
            int            maxEdges            = edges.Count * 2;
            Vertice        startPoint          = GetEdgesFromPoint(v).Item1.Start;
            Edge           startEdge           = GetEdgesFromPoint(v).Item1;
            Vertice        currentPoint        = v;
            Vertice        currentReversePoint = v;
            List <Edge>    reversedEdgeList    = KeepRelationsHelper.GetReversedEdgesList(edges);

            for (int zz = 0; zz < points.Count + 2; zz++)
            {
                (Edge, Edge)edgesFromPoint = GetEdgesFromPoint(currentPoint);
                if (AllRelationsOk())
                {
                    for (int i = oldVertices.Count - 1; i >= 0; i--)
                    {
                        oldVertices[i].Dispose();
                    }
                    return(true);
                }

                if (!currentPoint.Equals(startPoint))
                {
                    Relation rel = GetRelationFromEdge(edgesFromPoint.Item1);
                    if (rel != null)
                    {
                        if (!IsRelationOk(rel))
                        {
                            RelationLogic.RelationLogic.RepairRelation(rel, edgesFromPoint, currentPoint);
                        }
                    }
                }
                currentPoint = edgesFromPoint.Item2.End;
                indexer++;
            }

            for (int zz = 0; zz < points.Count + 2; zz++)
            {
                (Edge, Edge)edgesReverseFromPoint = KeepRelationsHelper.GetEdgesFromPointListEdge(currentReversePoint, reversedEdgeList);
                if (AllRelationsOk())
                {
                    for (int i = oldVertices.Count - 1; i >= 0; i--)
                    {
                        oldVertices[i].Dispose();
                    }
                    return(true);
                }
                if (!currentReversePoint.Equals(startPoint))
                {
                    Relation rel = KeepRelationsHelper.GetRelationFromEdgeListRelation(edgesReverseFromPoint.Item1, ps);
                    if (rel != null)
                    {
                        if (!IsRelationOk(rel))
                        {
                            RelationLogic.RelationLogic.RepairRelation(rel, edgesReverseFromPoint, currentReversePoint);
                        }
                    }
                }
                currentReversePoint = edgesReverseFromPoint.Item2.End;
            }

            for (int i = 0; i < oldVertices.Count; i++)
            {
                points[i].x = oldVertices[i].x;
                points[i].y = oldVertices[i].y;
            }
            for (int i = oldVertices.Count - 1; i >= 0; i--)
            {
                oldVertices[i].Dispose();
            }
            return(false);
        }