Example #1
0
    public Crossing(int crossingID, Simulation simulation)
    {
        this.simulation = simulation;
        this.CrossingID = crossingID;
        Feeders = new List<Feeder>();
        neighbors = new Neighbours();

        for (int i = 1; i < 5; i++)
        {
            Feeders.Add(new Feeder(i,this,simulation));
        }
    }
Example #2
0
 private IEnumerable <PatternType> ComputePattern()
 {
     return(Neighbours
            .Select(c => c.Read() == 0 ? PatternType.ConstZero : PatternType.ConstOne));
 }
Example #3
0
    public LandscapeBlock this[Neighbours neighbour]
    {
        get  { return mNeighbours[(int)neighbour]; }

        set { mNeighbours[(int)neighbour] = value; }
    }
Example #4
0
 public List <Atom> NeighboursExcept(Atom toIgnore)
 {
     return(Neighbours.Where(a => a != toIgnore).ToList());
 }
Example #5
0
 public void SetNeighbour(Cell cell)
 {
     Neighbours.Add(cell);
 }
Example #6
0
 public void EvaluatePointsNeighbourPoints(Neighbours type)
 {
     if (type == Neighbours.InEdges && edges.Length > 0)
     { // Neighbours in the edges
       // PointsEdges arrays have to an efficient algorithm
         if (!pointsEdgesEvaluated)
         {
             EvaluatePointsEdges();
         }
         // For each point
         for (int i = 0; i < points.Length; i++)
         {
             // Using HashSet to create unique value list
             HashSet <int> neighbourPoints = new HashSet <int>();
             for (int j = 0; j < points[i].edgesIndices.Length; j++)
             {
                 for (int k = 0; k < edges[points[i].edgesIndices[j]].pointsIndices.Length; k++)
                 {
                     neighbourPoints.Add(edges[points[i].edgesIndices[j]].pointsIndices[k]);
                 }
             }
             neighbourPoints.Remove(i); // Remove itself
                                        // Converting HashSet to array int[] and assign it to points neighbourPointsIndices array
             points[i].neighbourPointsIndices = new int[neighbourPoints.Count];
             neighbourPoints.CopyTo(points[i].neighbourPointsIndices);
         }
     }
     else if (type == Neighbours.InFaces && faces.Length > 0)
     { // Neighbours in the faces
       // PointsFaces arrays have to for an efficient algorithm
         if (!pointsEdgesEvaluated)
         {
             EvaluatePointsFaces();
         }
         // For each point
         for (int i = 0; i < points.Length; i++)
         {
             // Using HashSet to create unique value list
             HashSet <int> neighbourPoints = new HashSet <int>();
             for (int j = 0; j < points[i].facesIndices.Length; j++)
             {
                 for (int k = 0; k < faces[points[i].facesIndices[j]].pointsIndices.Length; k++)
                 {
                     neighbourPoints.Add(faces[points[i].facesIndices[j]].pointsIndices[k]);
                 }
             }
             neighbourPoints.Remove(i); // Remove itself
                                        // Converting HashSet to array int[] and assign it to points neighbourPointsIndices array
             points[i].neighbourPointsIndices = new int[neighbourPoints.Count];
             neighbourPoints.CopyTo(points[i].neighbourPointsIndices);
         }
     }
     else if (type == Neighbours.InCells && cells.Length > 0)
     { // Neighbours in the cells
       // PointsCells arrays have to for an efficient algorithm
         if (!pointsCellsEvaluated)
         {
             EvaluatePointsCells();
         }
         // For each point
         for (int i = 0; i < points.Length; i++)
         {
             // Using HashSet to create unique value list
             HashSet <int> neighbourPoints = new HashSet <int>();
             for (int j = 0; j < points[i].cellsIndices.Length; j++)
             {
                 for (int k = 0; k < cells[points[i].cellsIndices[j]].pointsIndices.Length; k++)
                 {
                     neighbourPoints.Add(cells[points[i].cellsIndices[j]].pointsIndices[k]);
                 }
             }
             neighbourPoints.Remove(i); // Remove itself
                                        // Converting HashSet to array int[] and assign it to points neighbourPointsIndices array
             points[i].neighbourPointsIndices = new int[neighbourPoints.Count];
             neighbourPoints.CopyTo(points[i].neighbourPointsIndices);
         }
     }
 }
Example #7
0
        /// <summary>
        /// Switchs the position of the node with a neighbouring node. Has in consideration the references of the neigbour node neighbours.
        /// </summary>
        /// <param name="neighbour">The relative position of the node we want to switch places with.</param>
        /// <returns>Returns <see langword="false"/> if the neigbour node is null.</returns>
        public bool SwitchNodePosition(Neighbours neighbour)
        {
            switch (neighbour)
            {
            case Neighbours.Top:

                if (Top == null)
                {
                    return(false);
                }

                QuadNode <T> temporary  = Top.MemberwiseClone() as QuadNode <T>;
                QuadNode <T> substitute = Top;

                ////assign nodes to the neigbour nodes of the involved pieces
                if (substitute.Left != null)
                {
                    substitute.Left.Right = this;
                }
                if (substitute.Right != null)
                {
                    substitute.Right.Left = this;
                }
                if (substitute.Top != null)
                {
                    substitute.Top.Bottom = this;
                }

                if (this.Left != null)
                {
                    this.Left.Right = substitute;
                }
                if (this.Bottom != null)
                {
                    this.Bottom.Top = substitute;
                }
                if (this.Right != null)
                {
                    this.Right.Left = substitute;
                }

                ////---------------------------------------

                ////assign nodes of the involved pieces
                substitute.Left   = this.Left;
                substitute.Top    = this;
                substitute.Bottom = this.Bottom;
                substitute.Right  = this.Right;

                this.Top    = temporary.Top;
                this.Left   = temporary.Left;
                this.Right  = temporary.Right;
                this.Bottom = substitute;

                return(true);

            case Neighbours.Left:

                if (this.Left == null)
                {
                    return(false);
                }

                temporary  = this.Left.MemberwiseClone() as QuadNode <T>;
                substitute = this.Left;

                //deal with neigbors of the involved pieces
                if (substitute.Left != null)
                {
                    substitute.Left.Right = this;
                }
                if (substitute.Top != null)
                {
                    substitute.Top.Bottom = this;
                }
                if (substitute.Bottom != null)
                {
                    substitute.Bottom.Top = this;
                }

                if (this.Top != null)
                {
                    this.Top.Bottom = substitute;
                }
                if (this.Right != null)
                {
                    this.Right.Left = substitute;
                }
                if (this.Bottom != null)
                {
                    this.Bottom.Top = substitute;
                }


                //assign end nodes of the involved pieces
                substitute.Left   = this;
                substitute.Top    = this.Top;
                substitute.Bottom = this.Bottom;
                substitute.Right  = this.Right;

                this.Top    = temporary.Top;
                this.Left   = temporary.Left;
                this.Bottom = temporary.Bottom;
                this.Right  = substitute;

                return(true);

            case Neighbours.Bottom:

                if (this.Bottom == null)
                {
                    return(false);
                }

                temporary  = this.Bottom.MemberwiseClone() as QuadNode <T>;
                substitute = this.Bottom;

                //deal with neigbors of the involved pieces
                if (substitute.Left != null)
                {
                    substitute.Left.Right = this;
                }
                if (substitute.Bottom != null)
                {
                    substitute.Bottom.Top = this;
                }
                if (substitute.Right != null)
                {
                    substitute.Right.Left = this;
                }

                if (this.Top != null)
                {
                    this.Top.Bottom = substitute;
                }
                if (this.Left != null)
                {
                    this.Left.Right = substitute;
                }
                if (this.Right != null)
                {
                    this.Right.Left = substitute;
                }


                //assing end nodes of the involved pieces
                this.Bottom.Bottom = this;
                substitute.Left    = this.Left;
                substitute.Top     = this.Top;
                substitute.Right   = this.Right;

                this.Top    = substitute;
                this.Left   = temporary.Left;
                this.Bottom = temporary.Bottom;
                this.Right  = temporary.Right;

                return(true);

            case Neighbours.Right:

                if (this.Right == null)
                {
                    return(false);
                }

                temporary  = this.Right.MemberwiseClone() as QuadNode <T>;
                substitute = this.Right;

                //assign end nodes of the neighbour nodes of the involved pieces
                if (substitute.Top != null)
                {
                    substitute.Top.Bottom = this;
                }
                if (substitute.Right != null)
                {
                    substitute.Right.Left = this;
                }
                if (substitute.Bottom != null)
                {
                    substitute.Bottom.Top = this;
                }

                if (this.Top != null)
                {
                    this.Top.Bottom = substitute;
                }
                if (this.Left != null)
                {
                    this.Left.Right = substitute;
                }
                if (this.Bottom != null)
                {
                    this.Bottom.Top = substitute;
                }


                //assign end nodes of the involved pieces
                substitute.Right  = this;
                substitute.Left   = this.Left;
                substitute.Bottom = this.Bottom;
                substitute.Top    = this.Top;

                this.Top    = temporary.Top;
                this.Left   = substitute;
                this.Bottom = temporary.Bottom;
                this.Right  = temporary.Right;

                return(true);


            default:
                break;
            }

            return(false);
        }
Example #8
0
 public void AddNeighbour(Node neighbor)
 {
     Neighbours.Add(neighbor);
 }
Example #9
0
 private void AddNeighbour(Cell cell, Vec3 border_point, Tuple <Vec3, Vec3> border_segment)
 {
     Neighbours.Add(new Neighbour(cell, border_point, border_segment, Flags & cell.Flags));
     AlignPlaneDirty = true;
 }
Example #10
0
        //public void UpdateAlignPlane()
        //{
        //    if (!AlignPlaneDirty)
        //        return;

        //    AlignPlaneDirty = false;

        //    if (AABB.Dimensions.Z < 3 || Neighbours == null)
        //    {
        //        AlignPlane = new Plane(AABB.Center, new Vec3(0, 0, 1));
        //    }
        //    // special case for single neighbor
        //    else if (Neighbours.Count == 1)
        //    {
        //        if (Neighbours[0].border_segment != null)
        //            AlignPlane = new Plane(Neighbours[0].border_segment.Item1, Neighbours[0].border_segment.Item2, Center);
        //    }
        //    else
        //    {
        //        var borders = Neighbours.Where(x => (x.connection_flags & MovementFlag.Walk) != 0 && x.border_segment != null).Select(x => x.border_segment);

        //        if (borders.Count() == 0)
        //        {
        //            AlignPlane = new Plane(AABB.Center, new Vec3(0, 0, 1));
        //            return;
        //        }

        //        // corners starting from min CCW and then from corner above min CCW
        //        Vec3[] corners = new Vec3[] { AABB.Min, new Vec3(AABB.Min.X, AABB.Max.Y, AABB.Min.Z), new Vec3(AABB.Max.X, AABB.Max.Y, AABB.Min.Z), new Vec3(AABB.Max.X, AABB.Min.Y, AABB.Min.Z),
        //                                      new Vec3(AABB.Min.X, AABB.Min.Y, AABB.Max.Z), new Vec3(AABB.Min.X, AABB.Max.Y, AABB.Max.Z), AABB.Max, new Vec3(AABB.Max.X, AABB.Min.Y, AABB.Max.Z) };

        //        bool[] corner_connected = new bool[8];

        //        List<int> connected_upper_corners = new List<int>();
        //        List<int> connected_lower_corners = new List<int>();

        //        for (int i = 0; i < corners.Count(); ++i)
        //        {
        //            corner_connected[i] = borders.FirstOrDefault(x => Vec3.GetDistanceFromSegment(x.Item1, x.Item2, corners[i]) < 2) != null;

        //            if (corner_connected[i])
        //            {
        //                if (i <= 3)
        //                    connected_lower_corners.Add(i);
        //                else
        //                {
        //                    connected_upper_corners.Add(i);
        //                    // disable connected corner below this one, as upper corners has priority as there are situations where two stairscases can cross -
        //                    // in this case there might be 4 connected lower corners but only 2 connected upper corners
        //                    connected_lower_corners.RemoveAll(x => x == (i - 4));
        //                }
        //            }
        //        }

        //        if (connected_lower_corners.Count == 1 && connected_upper_corners.Count == 1)
        //        {
        //            // this ain't perfect solution (when those 3 point lineup its non-determined)
        //            AlignPlane = new Plane(corners[connected_lower_corners[0]], corners[connected_upper_corners[0]], AABB.Center);
        //        }
        //        // check upper corners first because
        //        else if (connected_upper_corners.Count > 1)
        //        {
        //            if (connected_lower_corners.Count > 0)
        //                AlignPlane = new Plane(corners[connected_upper_corners[0]], corners[connected_upper_corners[1]], AABB.Center);
        //            else
        //                AlignPlane = new Plane(corners[connected_upper_corners[0]], corners[connected_upper_corners[1]], new Vec3(AABB.Center.X, AABB.Center.Y, AABB.Max.Z));
        //        }
        //        else if (connected_lower_corners.Count > 1)
        //        {
        //            if (connected_upper_corners.Count > 0)
        //                AlignPlane = new Plane(corners[connected_lower_corners[0]], corners[connected_lower_corners[1]], AABB.Center);
        //            else
        //                AlignPlane = new Plane(corners[connected_lower_corners[0]], corners[connected_lower_corners[1]], new Vec3(AABB.Center.X, AABB.Center.Y, AABB.Min.Z));
        //        }
        //        else
        //        {
        //            //having 1 or non connected corners i'm unable to determine plane
        //            //Log("[Nav] Undetermined cell align plane too few corners connected!");
        //        }

        //        //Tuple<Vec3, Vec3> longest_border = null;
        //        //float longest_border_len_2 = 0;

        //        //foreach (Neighbour n in Neighbours)
        //        //{
        //        //    if (n.border_segment == null)
        //        //        continue;

        //        //    var border_segment = n.border_segment;
        //        //    float len_2 = border_segment.Item1.Distance2DSqr(border_segment.Item2);

        //        //    if (longest_border == null || longest_border_len_2 < len_2)
        //        //    {
        //        //        longest_border = border_segment;
        //        //        longest_border_len_2 = len_2;
        //        //    }
        //        //}

        //        //if (longest_border != null)
        //        //    AlignPlane = new Plane(longest_border.Item1, longest_border.Item2, Center);
        //    }
        //}

        public void UpdateAlignPlane()
        {
            if (!AlignPlaneDirty)
            {
                return;
            }

            AlignPlaneDirty = false;

            if (AABB.Dimensions.Z < 3 || Neighbours == null)
            {
                AlignPlane = new Plane(AABB.Center, new Vec3(0, 0, 1));
            }
            // special case for single neighbor
            else if (Neighbours.Count == 1)
            {
                Vec3 v1 = null;
                Vec3 v2 = null;

                if (GetBorderSegmentWith(Neighbours[0].cell.AABB, ref v1, ref v2))
                {
                    AlignPlane = new Plane(v1, v2, Center);
                }
            }
            else
            {
                // find plane from all possible plane with smallest average distance of all connection points from it
                var connect_points = Neighbours.Where(x => (x.connection_flags & MovementFlag.Walk) != 0).Select(x => x.border_point);

                //this is Diablo related hack, as most certainly
                Plane[] possible_align_planes = null;

                if (AABB.Dimensions.X > 30)
                {
                    possible_align_planes = new Plane[] { new Plane(AABB.Min, new Vec3(AABB.Min.X, AABB.Max.Y, AABB.Min.Z), AABB.Center),                                     // bottom-up in direction -X
                                                          new Plane(new Vec3(AABB.Min.X, AABB.Min.Y, AABB.Max.Z), new Vec3(AABB.Min.X, AABB.Max.Y, AABB.Max.Z), AABB.Center), // up-bottom in direction -X
                                                          new Plane(AABB.Min, new Vec3(0, 0, 1)),                                                                             //flat bottom
                                                          new Plane(AABB.Max, new Vec3(0, 0, 1)) };                                                                           // flat up
                }
                else if (AABB.Dimensions.Y > 30)
                {
                    possible_align_planes = new Plane[] { new Plane(new Vec3(AABB.Min.X, AABB.Max.Y, AABB.Min.Z), new Vec3(AABB.Max.X, AABB.Max.Y, AABB.Min.Z), AABB.Center), // bottom-up in direction Y
                                                          new Plane(new Vec3(AABB.Min.X, AABB.Max.Y, AABB.Max.Z), AABB.Max, AABB.Center),                                     // up-bottom in direction Y
                                                          new Plane(AABB.Min, new Vec3(0, 0, 1)),                                                                             //flat bottom
                                                          new Plane(AABB.Max, new Vec3(0, 0, 1)) };                                                                           // flat up
                }
                else
                {
                    possible_align_planes = new Plane[] { new Plane(AABB.Min, new Vec3(AABB.Min.X, AABB.Max.Y, AABB.Min.Z), AABB.Center),                                     // bottom-up in direction -X
                                                          new Plane(new Vec3(AABB.Min.X, AABB.Min.Y, AABB.Max.Z), new Vec3(AABB.Min.X, AABB.Max.Y, AABB.Max.Z), AABB.Center), // up-bottom in direction -X
                                                          new Plane(new Vec3(AABB.Min.X, AABB.Max.Y, AABB.Min.Z), new Vec3(AABB.Max.X, AABB.Max.Y, AABB.Min.Z), AABB.Center), // bottom-up in direction Y
                                                          new Plane(new Vec3(AABB.Min.X, AABB.Max.Y, AABB.Max.Z), AABB.Max, AABB.Center),                                     // up-bottom in direction Y
                                                          new Plane(AABB.Min, new Vec3(0, 0, 1)),                                                                             //flat bottom
                                                          new Plane(AABB.Max, new Vec3(0, 0, 1)) };                                                                           // flat up
                }

                float min_avg_dist = -1;

                foreach (Plane plane in possible_align_planes)
                {
                    float avg_dist = 0;
                    foreach (Vec3 p in connect_points)
                    {
                        avg_dist += plane.Distance(p);
                    }

                    avg_dist /= (float)connect_points.Count();

                    if (avg_dist < min_avg_dist || min_avg_dist < 0)
                    {
                        AlignPlane   = plane;
                        min_avg_dist = avg_dist;
                    }
                }
            }
        }
Example #11
0
 /// <summary>
 /// Adds a neighbour
 /// </summary>
 /// <param name="neighbour"></param>
 public void AddNeighbour(Node <T> neighbour)
 {
     neighbour.Parent = this;
     Neighbours.Add(neighbour);
 }
Example #12
0
        /// <summary>
        /// Retrieve node
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public Node <T> GetNode(T element)
        {
            var node = Neighbours.FirstOrDefault(x => x.NodeContent.Equals(element));

            return(node);
        }
Example #13
0
        /// <summary>
        /// Verify if a node exists inthe array
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="element"></param>
        /// <returns></returns>
        public bool Exist(T element)
        {
            var hasAny = Neighbours.Any(x => x.NodeContent.Equals(element));

            return(hasAny);
        }
Example #14
0
 public override void PrepareAlgorithm()
 {
     //候補集合を生成
     candidateSelector.BuildCandidate(Neighbours.Count(), thought);
 }
Example #15
0
 public override Cell Tick(Neighbours neighbours)
 {
     return(neighbours.CountAlive() == 3
         ? new LiveCell() as Cell
         : this);
 }
Example #16
0
 public void AddNeighbour(Vertex <R> n)
 {
     Neighbours.Add(n);
 }
Example #17
0
            public void Ensure_AvailableNeigboursReturnNone_WhenAllIsEmptyString()
            {
                var neighbours = new Neighbours();

                Assert.Empty(neighbours.AvailableNeighbours);
            }
Example #18
0
 public bool IsAdjacent(Tile t)
 {
     return(Neighbours.ContainsValue(t));
 }
Example #19
0
 //COMMON
 public override void PrepareAlgorithm()
 {
     candidateSelector.BuildCandidate(Neighbours.Count(), thought.CurrentThought);
 }
Example #20
0
 public Separate(Neighbours <Steering, Steering> neighbours, float preferredDistance)
 {
     this.preferredDistance          = preferredDistance;
     isResponsibleForNeighbourUpdate = false;
     this.neighbours = neighbours;
 }
Example #21
0
 private void Awake()
 {
     neighbours = GetComponent <Neighbours>();
 }
Example #22
0
 public void Add(IVertex <V> vertex)
 {
     Neighbours.Add(vertex);
 }
Example #23
0
 public void AddNeighbour(Cell neigh)
 {
     Neighbours.Add(neigh);
 }
Example #24
0
 public void Remove(IVertex <V> vertex)
 {
     Neighbours.Remove(vertex);
 }
Example #25
0
 public List <Atom> UnprocessedNeighbours(Predicate <Atom> unprocessedTest)
 {
     return(Neighbours.Where(a => unprocessedTest(a)).ToList());
 }
Example #26
0
        private static bool IsSameColor(EntityManager entityManager, Neighbours target, Neighbours neighbours, int2 position, Entity slot, Dictionary <int2, Entity> positions)
        {
            if ((target & neighbours) == 0)
            {
                return(false);
            }

            position += FieldUtils.NeighbourToInt2(target);
            Entity entity;

            if (positions.TryGetValue(position, out entity))
            {
                var currentColor = entityManager.GetComponentData <Chip>(entityManager.GetComponentData <ChipReference>(slot).Value).Color;
                if (!entityManager.HasComponent <ChipReference>(entity))
                {
                    return(false);
                }

                var newColor = entityManager.GetComponentData <Chip>(entityManager.GetComponentData <ChipReference>(entity).Value).Color;
                if (newColor == currentColor)
                {
                    return(true);
                }
            }

            return(false);
        }
Example #27
0
 public List <Atom> NeighboursExcept(params Atom[] toIgnore)
 {
     return(Neighbours.Where(a => !toIgnore.Contains(a)).ToList());
 }
Example #28
0
 // 周囲のセルを設定します。
 internal void AddNeighbour(Cell neighbour) => Neighbours.Add(neighbour);
Example #29
0
    public Vector3 GetPositionOnEdge(Neighbours edge)
    {
        Vector3 pos = Vector3.zero;
        Vector3 start = Vector3.zero;
        Vector3 end = Vector3.one;

        switch (edge) {
        case Neighbours.North:
            end = surfaceMarkerMax.transform.position;
            start = new Vector3(surfaceMarkerMin.transform.position.x, end.y, end.z);
            break;

        case Neighbours.East:
            start = surfaceMarkerMax.transform.position;
            end = new Vector3(start.x, start.y, surfaceMarkerMin.transform.position.z);
            break;

        case Neighbours.South:
            start = surfaceMarkerMin.transform.position;
            end = new Vector3(surfaceMarkerMax.transform.position.x, start.y, start.z);
            break;

        case Neighbours.West:
            start = surfaceMarkerMin.transform.position;
            end = new Vector3(start.x, start.y, surfaceMarkerMax.transform.position.z);
            break;
        }

        pos = GetRandomPointOnLine(start, end);

        return pos;
    }
 public void AddNeighbor(ChiuNode node)
 {
     Neighbours.Add(node);
 }