Пример #1
0
        public void CrossesAccuracyAlongEdge()
        {
            for (int i = 1; i < 3; i++)
            {
                var Edge = new LineSegment(Vector2.Zero, new Vector2(10000 * i * 3000, 7008 * i * 3000));
                var Dx   = (Vector2)(Edge.Vertex1 - Edge.Vertex2);

                for (float a = 0f; a <= 1; a += 0.05f)
                {
                    Vector2 EdgePoint = Edge.Vertex2 + Dx * a;
                    Assert.IsTrue(Edge.Contains(EdgePoint));
                    Assert.IsTrue(Edge.Contains(Edge.Vertex1));
                    Assert.IsTrue(Edge.Contains(Edge.Vertex2));
                }
            }
        }
Пример #2
0
    public bool Intersection(LineSegment other, out Vector3 intersection)
    {
        if (!base.Intersection(other as Line, out intersection))
        {
            return(false);
        }

        return(this.Contains(intersection) && other.Contains(intersection));
    }
Пример #3
0
        public static IEnumerable <string> GetResourcePacks(string OptionsPath)
        {
            /*
             * StreamReader is the glorious thing that can read the contents of external files.
             *
             * Every time "sr.ReadLine()" is run, the StreamReader will retrievea new line from the
             * file as a string. I then use some fancy string operators to parse out the data I want.
             */
            using (StreamReader sr = new StreamReader(OptionsPath))
            {
                char[] RemoveChars = { '[', ']' };  //Declaring this out here prevents some derpy syntax errors.
                string Line;

                /*
                 * Once a StreamReader has run out of lines to process, this condition will exit the while loop.
                 * Of course, that shouldn't actually happen, so it only prevents an infinite loop. The loop
                 * will exit anyway once it finds the "resourcePacks" line, so it'll only run out if the file
                 * doesn't actually contain that, which means the user did something dumb.
                 */
                while (!sr.EndOfStream)
                {
                    /*
                     * I have to use a temporary variable here since calling sr.ReadLine() multiple times
                     * in the following if statement would end up reading multiple different lines into
                     * the condition rather than referencing the same line multiple times.
                     */
                    Line = sr.ReadLine();
                    if (Line.StartsWith("resourcePacks"))
                    {
                        foreach (string LineSegment in Line.Split(':')[1].Trim(RemoveChars).Split(','))
                        {
                            /*
                             * This line is a bit weird since I was messing around with two C# features I've
                             * never used before, the "conditional operator" and "yield return".
                             *
                             * The conditional operator is that stuff with the ? : weirdness. What it does is
                             * evaluates a condition and then returns separate values depending on whether it's
                             * true or false. In this case, it checks the string for a / to determine whether or not
                             * the string is a resource pack or the default textures. If it's a resource pack, it
                             * separates out the pack name from the "file/" crap. If it's the default textures, it
                             * marks it with "JAR\" so that the code doesn't get confused in case some moron names
                             * a resource pack "vanilla". Here's a link if you want to read more about the conditional operator:
                             * https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator
                             *
                             * What yield return does is a lot simpler. Instead of merely returning a single value
                             * as soon as the code reaches a return statement, it adds that value to a list that will be
                             * returned at the end.
                             */
                            yield return(LineSegment.Contains('/')    //Condition
                                ? LineSegment.Split('/')[1].Trim('"') //If true
                                : @"JAR\" + LineSegment.Trim('"'));   //If false
                        }
                        yield break;                                  //This statement merely tells the code "Yo, you just got all the data. You can go back to other stuff now."
                    }
                }

                /*
                 * Remember how I mentioned that the while loop shouldn't actually exit? In order to prevent the
                 * code doing anything weird, this will manually throw an exception. Why do that you may ask?
                 * The code calling this method can be enclosed inside of a try/catch block specifically to catch
                 * this exception, then respond by gracefully exiting rather than just killing eveything.
                 */
                throw new TrashMonkeyException("Could not find resource pack data in options file!");
            }
        }
        public override void ApplyLayout(LayoutGraph graph)
        {
            ApplyLayoutCore(graph);

            foreach (Node n in graph.Nodes)
            {
                foreach (Edge e in n.OutEdges)
                {
                    bool        lastSegmentOverlap = false;
                    IEdgeLayout er = graph.GetLayout(e);
                    if (er.PointCount() > 0)
                    {
                        // last bend point
                        YPoint bendPoint = er.GetPoint(er.PointCount() - 1);

                        IEnumerator <Edge> ecc = n.OutEdges.GetEnumerator();
                        loop : while (ecc.MoveNext())
                        {
                            Edge eccEdge = ecc.Current;
                            if (eccEdge != e)
                            {
                                YPointPath path = graph.GetPath(eccEdge);
                                for (ILineSegmentCursor lc = path.LineSegments(); lc.Ok; lc.Next())
                                {
                                    LineSegment seg = lc.LineSegment;
                                    if (seg.Contains(bendPoint))
                                    {
                                        lastSegmentOverlap = true;
                                        goto loop;
                                    }
                                }
                            }
                        }
                    }


                    YList points = graph.GetPointList(e);
                    for (ListCell c = points.FirstCell; c != null; c = c.Succ())
                    {
                        YPoint p = (YPoint)c.Info;
                        if (c.Succ() == null && !lastSegmentOverlap)
                        {
                            break;
                        }

                        YPoint p0 = (YPoint)(c.Pred() == null ? graph.GetSourcePointAbs(e) : c.Pred().Info);
                        YPoint p2;
                        if (Math.Abs(p0.X - p.X) < 0.01)
                        {
                            p2 = new YPoint(p.X, p.Y - 0.001);
                        }
                        else
                        {
                            p2 = new YPoint(p.X - 0.001, p.Y);
                        }

                        points.InsertBefore(p2, c);
                    }
                    graph.SetPoints(e, points);
                }
            }
        }