Example #1
0
        public override void ReceiveTile(Tile obj, Position loc)
        {
            if (_cl == null)
            {
                _cl = new Collage(_fmt, 1, false);
                _cl.AddBlankTiles(1);
                Activate(_main.toolBox);
            }

            EdgeKind kind = EdgeOf(loc);

            if (kind != EdgeKind.None)
            {
                int x, y;
                Edge.GetCoords(kind, out x, out y);

                Edge e = _edges[(int)kind];
                e.Distance = new Position(x, y);
                ResizeCollage(e);

                if (x == -1)
                {
                    loc.col = 0;
                }
                if (y == -1)
                {
                    loc.row = 0;
                }
            }

            _selPos = loc;
            _cl.SetTile(_selPos, obj as Tile);
            Render();
        }
Example #2
0
        public void DeleteEdge(EdgeKind kind)
        {
            if (_cl == null)
            {
                return;
            }

            int x, y;

            Edge.GetCoords(kind, out x, out y);

            if (x == -1)
            {
                DeleteCollageColumn(0);
            }
            else if (x == 1)
            {
                DeleteCollageColumn(_cl.Columns - 1);
            }

            if (y == -1)
            {
                DeleteCollageRow(0);
            }
            else if (y == 1)
            {
                DeleteCollageRow(_cl.Rows - 1);
            }
        }
Example #3
0
        private void ShiftCamera(EdgeKind e)
        {
            int x, y;

            Edge.GetCoords(e, out x, out y);
            ShiftCamera(Math.Abs(x), Math.Abs(y));
        }
Example #4
0
 public EdgeStatementSyntax(
     IEdgeVertexStatementSyntax left,
     EdgeKind edgeKind,
     IEdgeVertexStatementSyntax right,
     AttributeListSyntax?attributes = null)
     : this(
         left,
Example #5
0
        // Constructors

        public Edge(Node <TValue> tail, Node <TValue> head, EdgeKind kind, EdgeWeight weight)
        {
            Tail   = tail;
            Head   = head;
            Kind   = kind;
            Weight = weight;
        }
Example #6
0
 internal Lnk(Lnk e)
 {
     this.u  = e.u;
     this.v  = e.v;
     this.l  = e.l;
     this.c  = e.c;
     this.ek = e.ek;
 }
Example #7
0
        public Edge ExchangeRight(ExpressionTree <T> tree, EdgeKind k)
        {
            var r = this.Right;

            this.Right = new Edge(this, tree, k);

            return(r);
        }
Example #8
0
        public Edge ExchangeLeft(ExpressionTree <T> tree, EdgeKind k)
        {
            var l = this.Left;

            this.Left = new Edge(this, tree, k);

            return(l);
        }
Example #9
0
            public Edge(ExpressionTree <T> s, ExpressionTree <T> t, EdgeKind k)
            {
                CHECKS.ASSERT_NOT_NULL(s, "A node in an expression tree cannot be null.");
                CHECKS.ASSERT_NOT_NULL(t, "A node in an expression tree cannot be null.");

                Source = s;
                Target = t;
                Kind   = k;
            }
Example #10
0
 public GraphBuilder <T> Kind(EdgeKind kind)
 {
     if (kind == default)
     {
         throw new ArgumentNullException(nameof(kind));
     }
     this._kind = kind;
     return(this);
 }
Example #11
0
        public Edge <TValue> AddEdge(TValue tail, TValue head, EdgeKind kind, EdgeWeight weight)
        {
            var tailNode = GetNode(tail);
            var headNode = GetNode(head);
            var edge     = new Edge <TValue>(tailNode, headNode, kind, weight);

            tailNode.OutgoingEdges.Add(edge);
            headNode.IncomingEdges.Add(edge);
            return(edge);
        }
Example #12
0
        internal Edge <T> AddEdge(EdgeKind kind, params Node <T>[] to)
        {
            if (to == null || to.Length == 0)
            {
                throw new ArgumentNullException(nameof(to));
            }

            Edge <T> edge = new Edge <T>(kind, this, to);

            _edges.Add(edge);
            return(edge);
        }
Example #13
0
        public bool HighlightEdgeAt(int x, int y)
        {
            bool     wasOob;
            Position pos  = GetPosition(x, y, out wasOob);
            EdgeKind kind = wasOob ? EdgeKind.None : EdgeOf(pos);

            Edge e       = _edges[(int)kind];
            bool changed = _hlEdge != e;

            _hlEdge = e;
            return(changed);
        }
Example #14
0
 internal Lnk(int u,
              int v,
              int l,
              int c,
              EdgeKind ek)
 {
     this.u  = u;
     this.v  = v;
     this.l  = l;
     this.c  = c;
     this.ek = ek;
 }
Example #15
0
        public static IGraph ImportAdjacentList <T>(string _FilePath, EdgeKind _EdgeKind) where T : IWeight, new()
        {
            Console.WriteLine("Starte Importieren: " + _FilePath);
            var hStopwatch = new Stopwatch();

            hStopwatch.Start();

            String[] hAdjacentListFileContent = { };
            if (File.Exists(_FilePath))
            {
                hAdjacentListFileContent = File.ReadAllLines(_FilePath);
            }

            // Initiales Anlegen der Knoten.
            var hGraph     = new Graph();
            var hNodeCount = Convert.ToInt32(hAdjacentListFileContent[0]);

            for (int hNodeId = 0; hNodeId < hNodeCount; hNodeId++)
            {
                hGraph.CreateNewNode(hNodeId);
            }



            // Anlegen der Kanten
            switch (_EdgeKind)
            {
            case EdgeKind.UndirectedUnweighted:
                ImportUnweightedUndirected(hGraph, hAdjacentListFileContent);
                break;

            case EdgeKind.UndirectedWeighted:
                ImportWeightedUndirected <T>(hGraph, hAdjacentListFileContent);
                break;

            case EdgeKind.DirectedWeighted:
                ImportWeightedDirected <T>(hGraph, hAdjacentListFileContent);
                break;
            } //switch (_EdgeKind)



            hStopwatch.Stop();
            Console.WriteLine("Anzahl eingelesener Knoten:\t" + hGraph.GetNodeDictionary().Count.ToString());
            Console.WriteLine("Anzahl eingelesener Kanten:\t" + hGraph.GetEdgeIndices().Count.ToString());
            Console.WriteLine("Dauer Einlesevorgang:\t\t" + hStopwatch.ElapsedMilliseconds.ToString() + " ms");
            Console.WriteLine();

            return(hGraph);
        }
Example #16
0
 internal Lnk(
     int u,
     int v,
     int l,
     int c,
     EdgeKind ek,
     Lnk next)
 {
     this.u    = u;
     this.v    = v;
     this.l    = l;
     this.c    = c;
     this.ek   = ek;
     this.next = next;
 }
Example #17
0
    private void AddWallHit(WallController wallController, EdgeKind edgeKind, Vector2 point)
    {
        if (wallController == _curentlyIgnoredWall)
        {
            return;
        }

        EdgeHitContainer curEdgeHits = null;

        if (!_WallHits.TryGetValue(wallController, out curEdgeHits))
        {
            curEdgeHits = new EdgeHitContainer();
            _WallHits.Add(wallController, curEdgeHits);
        }

        curEdgeHits.Add(edgeKind, point);
    }
Example #18
0
    internal Edge GetEdge(EdgeKind kind)
    {
        if (kind == EdgeKind.A)
        {
            return(EdgeA);
        }
        if (kind == EdgeKind.B)
        {
            return(EdgeB);
        }
        if (kind == EdgeKind.C)
        {
            return(EdgeC);
        }

        return(EdgeD);
    }
Example #19
0
        public override IPiece PieceAt(Position loc)
        {
            if (_cl == null ||
                loc.col < -1 || loc.row < -1 ||
                loc.col > _cl.Columns || loc.row > _cl.Rows)
            {
                return(null);
            }

            EdgeKind kind = EdgeOf(loc);

            if (kind == EdgeKind.None)
            {
                return(_cl.TileAt(loc));
            }

            return(_edges[(int)kind]);
        }
    public IEnumerable <LineSegment> GetHitSegments(EdgeKind edge)
    {
        if (edge == EdgeKind.A)
        {
            return(GetSegments(_HitsEdgeA));
        }
        else if (edge == EdgeKind.B)
        {
            return(GetSegments(_HitsEdgeB));
        }
        else if (edge == EdgeKind.C)
        {
            return(GetSegments(_HitsEdgeC));
        }
        else if (edge == EdgeKind.D)
        {
            return(GetSegments(_HitsEdgeD));
        }

        return(Enumerable.Empty <LineSegment>());
    }
    internal void Add(EdgeKind edge, Vector2 point)
    {
        if (_isClosed)
        {
            return;
        }

        if (edge == EdgeKind.A)
        {
            _HitsEdgeA.Add(point);
        }
        else if (edge == EdgeKind.B)
        {
            _HitsEdgeB.Add(point);
        }
        else if (edge == EdgeKind.C)
        {
            _HitsEdgeC.Add(point);
        }
        else if (edge == EdgeKind.D)
        {
            _HitsEdgeD.Add(point);
        }
    }
Example #22
0
 internal Lnk(int u,
     int v,
     int l,
     int c,
     EdgeKind ek)
 {
     this.u = u;
     this.v = v;
     this.l = l;
     this.c = c;
     this.ek = ek;
 }
Example #23
0
 public void InsertLeft(ExpressionTree <T> tree, EdgeKind k)
 {
     this.Left = new Edge(this, tree, k);
 }
Example #24
0
    public void InitLightMesh(IEnumerable <WallController> wallControllers)
    {
        _mesh = GetComponent <MeshFilter>().mesh;

        var            vertices2d         = new List <Vector2>();
        GameObject     lastHitWall        = null;
        WallController lastWallController = null;
        EdgeKind       lastHitEdgeKind    = EdgeKind.None;
        Vector3        lastHitPointLocal  = new Vector3();
        Vector3        lastHitPointWorld  = new Vector3();

        DrawRaycast(transform.position, wallControllers);

        float angle = 0;

        for (int i = 0; i < _raysToShoot; i++)
        {
            var x = Mathf.Sin(angle);
            var y = Mathf.Cos(angle);
            angle -= 2 * Mathf.PI / _raysToShoot;

            Vector3      dir = new Vector3(x, y, 0);
            RaycastHit2D hit;
            hit = Physics2D.Raycast(transform.position, dir, _distance, WallLayerMask);
            if (hit.collider != null)
            {
                Vector3 curHitPointWorld = hit.point;
                Vector3 curHitPointLocal = transform.InverseTransformPoint(curHitPointWorld);

                WallController curWallController = hit.collider.GetComponent <WallController>();
                EdgeKind       curHitEdgeKind    = curWallController.GetEdgeKind(curHitPointWorld);

                if (curHitEdgeKind == EdgeKind.None)
                {
                    //TODO this shouldn't happen!! this happens with all the points close to an intersecting point between two edges
                    //that's why the edges don't close properly

                    lastHitPointLocal = curHitPointLocal;
                    continue;

                    //draw points on if on no edge
                    //Debug.DrawLine(transform.position, hit.point, Color.white, 180);
                    //curWallController.DrawEdges();
                }

                if (lastHitWall == null)
                {
                    lastHitWall = hit.collider.gameObject;
                }
                else if (lastHitWall != hit.collider.gameObject || curHitEdgeKind != lastHitEdgeKind)
                {
                    //always add first and last hitpoint on the same wall to form an edge

                    //add last hit point
                    vertices2d.Add(lastHitPointLocal);

                    lastHitWall = hit.collider.gameObject;

                    //add current hit point
                    vertices2d.Add(curHitPointLocal);

                    AddWallHit(lastWallController, lastHitEdgeKind, lastHitPointWorld);

                    bool isCurWallParent = GetComponentInParent <WallController>() == curWallController;
                    if (isCurWallParent)
                    {
                        var curEdge = curWallController.GetEdge(curHitEdgeKind);
                        AddWallHit(curWallController, curHitEdgeKind, curEdge.Start);
                        AddWallHit(curWallController, curHitEdgeKind, curEdge.End);

                        _curentlyIgnoredWall = curWallController;
                    }
                    else
                    {
                        AddWallHit(curWallController, curHitEdgeKind, curHitPointWorld);
                    }
                }

                lastHitPointLocal = curHitPointLocal;
                lastHitPointWorld = curHitPointWorld;

                lastHitEdgeKind    = curHitEdgeKind;
                lastWallController = curWallController;
            }
            else
            {
                var tmp = transform.InverseTransformPoint(transform.position + dir);
                lastHitPointLocal = new Vector2(tmp.x, tmp.y);
                vertices2d.Add(lastHitPointLocal);
            }
        }
        vertices2d.Add(lastHitPointLocal);

        // build mesh
        List <Vector3> newVertices = new List <Vector3>();

        foreach (var curPos in vertices2d)
        {
            newVertices.Add(new Vector3(curPos.x, curPos.y, 0));
        }

        var triangles = new int[newVertices.Count * 3];

        // triangle list
        int j = -1;

        for (int n = 0; n < triangles.Length - 3; n += 3)
        {
            j++;
            triangles[n] = newVertices.Count - 1;
            if (j >= newVertices.Count)
            {
                triangles[n + 1] = 0;
            }
            else
            {
                triangles[n + 1] = j + 1;
            }
            triangles[n + 2] = j;
        }
        j++;

        // central point
        newVertices[newVertices.Count - 1] = new Vector3(0, 0, 0);
        triangles[triangles.Length - 3]    = newVertices.Count - 1;
        triangles[triangles.Length - 2]    = 0;
        triangles[triangles.Length - 1]    = j - 1;

        // Create the mesh
        _mesh.vertices  = newVertices.ToArray();
        _mesh.triangles = triangles;
        _mesh.uv        = new Vector2[newVertices.Count];

        CloseWallHitContainers();
    }
Example #25
0
 public static void GetCoords(EdgeKind e, out int x, out int y)
 {
     x = ((int)e % 3) - 1;
     y = ((int)e / 3) - 1;
 }
Example #26
0
 public Edge(EdgeKind kind)
 {
     _kind = kind;
     _dist = new Position(0, 0);
 }
Example #27
0
 public void InsertRight(ExpressionTree <T> tree, EdgeKind k)
 {
     this.Right = new Edge(this, tree, k);
 }
Example #28
0
 /// <summary>
 /// Deprecated!
 /// </summary>
 /// <param name="_FilePath"></param>
 /// <param name="_EdgeKind"></param>
 /// <returns></returns>
 public static IGraph ImportAdjacentList(string _FilePath, EdgeKind _EdgeKind)
 {
     return(ImportAdjacentList <CostWeighted>(_FilePath, _EdgeKind));
 }
Example #29
0
 internal Edge(EdgeKind kind, Node <T> from, params Node <T>[] to)
 {
     ToNodes  = new ReadOnlyCollection <Node <T> >(to);
     FromNode = from;
     EdgeKind = kind;
 }
Example #30
0
 internal Lnk(Lnk e)
 {
     this.u = e.u;
     this.v = e.v;
     this.l = e.l;
     this.c = e.c;
     this.ek = e.ek;
 }
Example #31
0
 internal Lnk(
     int u,
     int v,
     int l,
     int c,
     EdgeKind ek,
     Lnk next)
 {
     this.u = u;
     this.v = v;
     this.l = l;
     this.c = c;
     this.ek = ek;
     this.next = next;
 }