예제 #1
0
        public List <Point> GetPossibleConnections(ref List <Vertex> remaingVertices, ref List <LinearParameters> usedFunctions)
        {
            List <Point> possiblePoints = new List <Point>();

            foreach (Vertex vertex in remaingVertices)
            {
                if (vertex != this)
                {
                    // Checking if vertex isn't already connected
                    if (!Neighbors.Contains(vertex))
                    {
                        LinearParameters currFun = new LinearParameters(Point, vertex.Point);

                        bool crosses = false;

                        foreach (LinearParameters func in usedFunctions)
                        {
                            crosses = currFun.Crosses(func);
                            if (crosses)
                            {
                                break;
                            }
                        }
                        if (!crosses)
                        {
                            possiblePoints.Add(vertex.Point);
                        }
                    }
                }
            }
            return(possiblePoints);
        }
예제 #2
0
        public bool Crosses(LinearParameters function)
        {
            // Same function, need to check X values
            if (A == function.A)
            {
                if (B == function.B)
                {
                    if (StartX > function.StartX)
                    {
                        return(!(StartX > function.EndX));
                    }

                    else if (StartX < function.StartX)
                    {
                        return(!(function.StartX > EndX));
                    }

                    else
                    {
                        // The same X value
                        if (A == double.PositiveInfinity)
                        {
                            if (StartY > function.StartY)
                            {
                                return(!(StartY >= function.EndY));
                            }

                            else if (StartY < function.StartY)
                            {
                                return(!(function.StartY >= EndY));
                            }

                            // Because minimum length cannot be 0
                            else
                            {
                                return(true);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
                // They will never cross with different B and the same A
                return(false);
            }
            else
            {
                double crossX;
                if (A == double.PositiveInfinity)
                {
                    // one or the functions: x=Start.X
                    crossX = StartX;

                    if (crossX >= function.StartX && crossX <= function.EndX)
                    {
                        double yValue = crossX * function.A + function.B;

                        if (EndY >= StartY)
                        {
                            return(yValue > StartY && yValue < EndY);
                        }
                        else
                        {
                            return(yValue > EndY && yValue < StartY);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (function.A == double.PositiveInfinity)
                {
                    // one or the functions: x=Start.X
                    crossX = function.StartX;

                    if (crossX >= StartX && crossX <= EndX)
                    {
                        double yValue = crossX * A + B;
                        if (function.EndY >= function.StartY)
                        {
                            return(yValue > function.StartY && yValue < function.EndY);
                        }
                        else
                        {
                            return(yValue > function.EndY && yValue < function.StartY);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                // If none of the funtions
                else
                {
                    // both functions: y = Ax + B
                    crossX = Math.Round((function.B - B) / (A - function.A), Globals.RoundVal);

                    if ((crossX > function.StartX && crossX < function.EndX) && (crossX > StartX && crossX < EndX))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
        }