public EntrancesPair(Node a, Node b) { this.a = a; this.b = b; aEntrance = this.a.GetComponent <IntersectionEntrance>(); bEntrance = this.b.GetComponent <IntersectionEntrance>(); }
public bool IsIntersection() { IntersectionEntrance ieA = AnchorA.GetComponent <IntersectionEntrance>(); IntersectionEntrance ieB = AnchorB.GetComponent <IntersectionEntrance>(); if (ieA == null || ieB == null) { return(false); } if (ieA.centre == ieB.centre) { return(true); } return(false); }
private static void EvaluateIntersection(Node n) { if (n.GetNodeComponent <IntersectionEntrance>() == null) { Node[] neighbours = NodeNetCreator.mainNet.GetAllNeighbours(n); List <Node> intersectionMembers = new List <Node>(neighbours.Length); if (neighbours.Length >= 3) { //Por cada vecino for (int i = 0; i < neighbours.Length; i++) { Node[] nNeighbours = NodeNetCreator.mainNet.GetAllNeighbours(neighbours[i]); int commonNeighbours = 0; for (int j = 0; j < nNeighbours.Length; j++) { if (NodeNetCreator.mainNet.AreNeighbours(n, nNeighbours[j])) { commonNeighbours++; } } if (commonNeighbours == 2) { intersectionMembers.Add(neighbours[i]); } } if (intersectionMembers.Count == 3) { intersectionMembers.Add(n); Stretch[] stretches = NodeNetCreator.mainNet.GetAllStretchesBetweenNodes(intersectionMembers.ToArray()); Stretch[] straightStretches = FindCrossSectionsInIntersection(stretches); IntersectionEntrance a = straightStretches[0].AnchorA.AddNodeComponent <IntersectionEntrance>(); IntersectionEntrance b = straightStretches[0].AnchorB.AddNodeComponent <IntersectionEntrance>(); IntersectionEntrance c = straightStretches[1].AnchorA.AddNodeComponent <IntersectionEntrance>(); IntersectionEntrance d = straightStretches[1].AnchorB.AddNodeComponent <IntersectionEntrance>(); a.transitable = b.transitable = true; c.transitable = d.transitable = false; } } } }
public void CreateIntersection(Node[] selectedNodes) { if (selectedNodes.Length == 4) { foreach (var n in selectedNodes) { IntersectionCentre i = n.gameObject.GetComponent <IntersectionCentre>(); if (i != null) { DestroyImmediate(i); } IntersectionEntrance ie = n.gameObject.GetComponent <IntersectionEntrance>(); if (ie != null) { DestroyImmediate(ie); } } IntersectionCentre ic = selectedNodes[0].gameObject.AddComponent <IntersectionCentre>(); foreach (var n in selectedNodes) { Node farestNode = null; float maxDistance = float.MinValue; foreach (var nn in selectedNodes) { if (n != nn) { float d = Vector3.Distance(n.transform.position, nn.transform.position); if (d > maxDistance) { maxDistance = d; farestNode = nn; } } } ic.AddPair(n, farestNode, ic); } } }
public void AddPair(Node a, Node b, IntersectionCentre ic) { if (!a.GetComponent <IntersectionEntrance>()) { IntersectionEntrance ie = a.gameObject.AddComponent <IntersectionEntrance>(); ie.centre = ic; } if (!b.GetComponent <IntersectionEntrance>()) { IntersectionEntrance ie = b.gameObject.AddComponent <IntersectionEntrance>(); ie.centre = ic; } EntrancesPair p = new EntrancesPair(a, b); if (!ExistPair(p)) { pairs.Add(p); } }