コード例 #1
0
ファイル: CityTesting.cs プロジェクト: ianscilipoti/Cities
    // Update is called once per frame
    void Update()
    {
        if (showCity)
        {
            //city.DebugDrawRecursiveLayered(1f);
            city.DebugDrawRecursive(1f);
        }

        if (refresh)
        {
            if (changeSeed)
            {
                seed = Random.Range(0, 100000);
            }

            refresh = false;
            Random.InitState(seed);
            Destroy(city.cityParent.gameObject);
            city = City.GenerateCity(radius);

            List <CityEdge> testEdges = city.GetAllEdges();
            test = new List <EdgeLoopEdge>();
            foreach (CityEdge t in testEdges)
            {
                test.Add(t);
            }
        }
        if (showRoads)
        {
            LinkedGraph <EdgeLoopEdge> .DebugDraw(test);
        }
    }
コード例 #2
0
    private void Update()
    {
        //highlighted = ((EdgeLoopEdge)edges[highlightedInd]).GetLocalLoop(ccw);
        //Debug.DrawLine((Vector3)edges[highlightedInd].a.pt + Vector3.forward, (Vector3)edges[highlightedInd].b.pt + Vector3.forward, Color.red);
        //if(highlight)
        //{

        //    if (highlighted != null)
        //    {
        //        LinkedGraph<EdgeLoopEdge>.DebugDraw(highlighted);
        //    }
        //    else
        //    {
        //        List<EdgeLoopEdge> e = new List<EdgeLoopEdge>();
        //        e.Add(edges[highlightedInd]);
        //        LinkedGraph<EdgeLoopEdge>.DebugDraw(e);
        //    }

        //}
        //else
        //{
        //
        //}
        LinkedGraph <EdgeLoopEdge> .DebugDraw(edges);
    }
コード例 #3
0
ファイル: DebugLines.cs プロジェクト: ianscilipoti/Cities
    private void Update()
    {
        LinkedGraph <LinkedGraphEdge> .DebugDraw(edges, colors, elevations);

        if (edges.Count > 0)
        {
            LinkedGraphEdge higlightedEdge = edges[edgeHighlightIndex];
            if (vertHighlight)
            {
                LinkedGraphVertex vert;
                if (vertIndex == 0)
                {
                    vert = higlightedEdge.a;
                }
                else
                {
                    vert = higlightedEdge.b;
                }

                foreach (LinkedGraphEdge edge in vert.GetConnections())
                {
                    Debug.DrawLine(HelperFunctions.projVec2(edge.a.pt) + Vector3.up * 1.1f, HelperFunctions.projVec2(edge.b.pt) + Vector3.up * 1.1f, Color.green);
                }

                Debug.Log(vert.NumConnections() + " " + Time.time);
            }
            else
            {
                Debug.DrawLine(HelperFunctions.projVec2(higlightedEdge.a.pt) + Vector3.up * 1.1f, HelperFunctions.projVec2(higlightedEdge.b.pt) + Vector3.up * 1.1f, Color.green);
            }
        }

        if (displaySimpleEdges)
        {
            foreach (Vector4 edge in simpleEdges)
            {
                Debug.DrawLine(new Vector3(edge.x, -1f, edge.y), new Vector3(edge.z, -1f, edge.w), Color.yellow);
            }
        }
    }
コード例 #4
0
    protected List <EdgeType[]> CollectChildLoops(SubdividableEdgeLoop <EdgeType> parent, List <DividingEdge> dividingEdges)
    {
        List <EdgeType> knownEdges    = new List <EdgeType>(parent.GetEdgesEnumerable());
        Polygon         parentPoly    = parent.GetPolygon();
        Path            polygonAsClip = parentPoly.ClipperPath(HelperFunctions.clipperScale);

        Vector2[] parentPoints = parent.GetPoints();

        //kinda ugly, these two variables are implicitly paired together
        Paths edgePaths = new Paths();
        List <ILinkedGraphEdgeFactory <EdgeType> > edgePathFactories = new List <ILinkedGraphEdgeFactory <EdgeType> >();
        List <System.Object[]> edgePathFactoriesParams = new List <System.Object[]>();

        foreach (DividingEdge edge in dividingEdges)
        {
            Path edgePath = new Path();
            edgePath.Add(HelperFunctions.GetIntPoint(edge.p1));
            edgePath.Add(HelperFunctions.GetIntPoint(edge.p2));

            PolyTree clippedResults = new PolyTree();
            Clipper  clipper        = new Clipper();

            clipper.AddPath(edgePath, PolyType.ptSubject, false);
            clipper.AddPath(polygonAsClip, PolyType.ptClip, true);
            clipper.Execute(ClipType.ctIntersection, clippedResults);

            Paths subPaths = Clipper.OpenPathsFromPolyTree(clippedResults);
            edgePaths.AddRange(subPaths);
            //if this edge was split into multiple paths when intersecting with parent poly, note that each subpath has the same factory
            foreach (Path path in subPaths)
            {
                edgePathFactories.Add(edge.factory);
                edgePathFactoriesParams.Add(edge.factoryParams);
            }
        }

        DebugLines debug = GameObject.FindObjectOfType <DebugLines>();


        int totalAddedEdges = 0;

        for (int j = 0; j < edgePaths.Count; j++)
        {
            Path edgePath = edgePaths[j];
            ILinkedGraphEdgeFactory <EdgeType> edgeFactory = edgePathFactories[j];
            System.Object[] edgeParams = edgePathFactoriesParams[j];
            //this is almost always just 2 elements in which case it runs once
            for (int i = 0; i < edgePath.Count - 1; i++)
            {
                //convert path back into regular coordinates. Watch out that there is high enough resolution
                //that when this conversion happens, the linkedGraph still thinks points/edges are adjacent and connects them
                Vector2 p1 = HelperFunctions.GetPoint(edgePath[i]);
                Vector2 p2 = HelperFunctions.GetPoint(edgePath[i + 1]);

                LinkedGraph <EdgeType> .ConnectNewEdge(p1, p2, edgeFactory, edgeParams, knownEdges);

                totalAddedEdges++;
            }
        }

        List <EdgeType[]> formedChildLoops = parent.GetInteriorEdgeLoops();

        if (formedChildLoops.Count == 0)
        {
            Debug.Log("No Children " + parent.GetHashCode());
        }
        return(formedChildLoops);
    }
コード例 #5
0
    // Start is called before the first frame update
    void Start()
    {
        Random.InitState(0);
        edges = new List <EdgeLoopEdge>();
        //graph = new SegmentGraph<float>();



        //graph.AddSegment(Vector2.zero, new Vector2(0, 10), 0f);
        //graph.AddSegment(new Vector2(-3f, 1f), new Vector2(3f, 1f), 0f);
        //graph.AddSegment(new Vector2(-3f, 2f), new Vector2(3f, 2f), 0f);
        //graph.AddSegment(new Vector2(-3f, 3f), new Vector2(3f, 3f), 0f);

        //graph.AddSegment(new Vector2(1f, 0), new Vector2(2f, 10f), 0f);


        //graph.AddSegment(new Vector2(-3f, 5f), new Vector2(0f, 5f), 0f);

        //graph.AddSegment(new Vector2(-5f, 10f), new Vector2(5f, 10f), 0f);
        EdgeLoopEdgeFactory factory = new EdgeLoopEdgeFactory();

        for (int i = 0; i < 20; i++)
        {
            LinkedGraph <EdgeLoopEdge> .ConnectNewEdge(new Vector2(0, i / 2f) * 10f, new Vector2(10, i / 2f) * 10f, factory, edges);
        }

        for (int i = 0; i < 20; i++)
        {
            LinkedGraph <EdgeLoopEdge> .ConnectNewEdge(new Vector2(i / 2f, 0) * 10f, new Vector2(i / 2f, 10) * 10f, factory, edges);
        }

        //LinkedGraphEdge.ConnectNewEdge(Vector2.zero, new Vector2(0, 10), factory, edges);

        //LinkedGraphEdge.ConnectNewEdge(Vector2.zero, new Vector2(5, 5), factory, edges);
        //LinkedGraph<EdgeLoopEdge>.ConnectNewEdge()

        //LinkedGraphVertex bl = new LinkedGraphVertex(Vector2.down + Vector2.left);
        //LinkedGraphVertex br = new LinkedGraphVertex(Vector2.down + Vector2.right);

        //LinkedGraphVertex tl = new LinkedGraphVertex(Vector2.up + Vector2.left);
        //LinkedGraphVertex tr = new LinkedGraphVertex(Vector2.up + Vector2.right);

        //LinkedGraphVertex mid = new LinkedGraphVertex(Vector2.zero);

        //EdgeLoopEdge b = LinkedGraph<EdgeLoopEdge>.AddEdge(br, bl, factory, edges);
        //EdgeLoopEdge r = LinkedGraph<EdgeLoopEdge>.AddEdge(br, tr, factory, edges);
        //EdgeLoopEdge t = LinkedGraph<EdgeLoopEdge>.AddEdge(tl, tr, factory, edges);
        //EdgeLoopEdge l = LinkedGraph<EdgeLoopEdge>.AddEdge(bl, tl, factory, edges);

        //EdgeLoopEdge blm = LinkedGraph<EdgeLoopEdge>.AddEdge(bl, mid, factory, edges);
        //EdgeLoopEdge brm = LinkedGraph<EdgeLoopEdge>.AddEdge(br, mid, factory, edges);
        //EdgeLoopEdge trm = LinkedGraph<EdgeLoopEdge>.AddEdge(tr, mid, factory, edges);
        //EdgeLoopEdge tlm = LinkedGraph<EdgeLoopEdge>.AddEdge(tl, mid, factory, edges);

        //SubdividableEdgeLoop<EdgeLoopEdge> squareLoop = new SubdividableEdgeLoop<EdgeLoopEdge>(new EdgeLoopEdge[] {b,r,t,l}, true);


        ////LinkedGraph<EdgeLoopEdge> test = (LinkedGraph<EdgeLoopEdge>)new LinkedGraph<CityEdge>();

        //print(squareLoop.EdgeFollowsWinding(b));
        //print(squareLoop.EdgeFollowsWinding(r));
        //print(squareLoop.EdgeFollowsWinding(t));
        //print(squareLoop.EdgeFollowsWinding(l));

        //List<EdgeLoopEdge[]> children = squareLoop.GetInteriorEdgeLoops();

        //List<float> test = new List<float>();
        //test.Add(0);
        //test.Add(1);
        //test.Add(2);

        //test.Insert(2, 1.5f);

        //test.RemoveAt(2);

        //test.Insert(2, 1.5f);
        //test.Insert(3, 1.7f);


        //foreach (float i in test)
        //{
        //    print(i);
        //}

        //print("poo");
        //for (int i = 0; i < 5; i ++)
        //{
        //    print(i + " %" + (i - 1) % 5);
        //}
    }