public TraversalNode TraverseSplitRects(List <SplitRect> source) { var initiailRandomState = UnityEngine.Random.state; if (_seed >= 0) { UnityEngine.Random.InitState(_seed); } _longestDistanceNode = null; var result = BuildPath(source[UnityEngine.Random.Range(0, source.Count)], new HashSet <SplitRect>()); if (_seed >= 0) { UnityEngine.Random.state = initiailRandomState; } return(result); }
/// <summary> /// Create the rectangles making up the travelsal tree /// </summary> /// <param name="root"></param> /// <param name="colorIndex"></param> /// <param name="offset"></param> private void CreateTraversalNodeDebugObjects(TraversalNode root, int colorIndex, Vector3 offset) { if (root != null) { var debugObject = CreatDebugVisual(root._split._rect, offset, colorIndex); var debugBehaviour = debugObject.AddComponent <TraversalNodeDebugBehaviour>(); debugObject.transform.parent = gameObject.transform; debugBehaviour._node = root; debugBehaviour._scale = _scaleMultiplier; debugBehaviour._offset = offset; root.DebugElement = debugObject; _debugObjects.Add(debugObject); for (int i = 0; i < root._children.Count; ++i) { CreateTraversalNodeDebugObjects(root._children[i], ++colorIndex, offset); colorIndex++; } } }
private TraversalNode CreateNode(TraversalNode parent, SplitRect split, HashSet <SplitRect> closedList) { var result = new TraversalNode() { _split = split, _parent = parent, _children = new List <TraversalNode>(), _parentIntersection = parent == null ? null : RectUtil.GetIntersection(parent._split._rect, split._rect), _pathLength = parent == null ? 0 : parent._pathLength + Vector2.Distance(parent._split._rect.center, split._rect.center) }; if (_longestDistanceNode == null || result._pathLength > _longestDistanceNode._pathLength) { _longestDistanceNode = result; } closedList.Add(split); if (parent != null) { parent._children.Add(result); } return(result); }
private bool CanContinueIteration(int i, TraversalNode current) { return((i < _maxDepth || _maxDepth == -1) && (current != null) && (current._pathLength < _maxLength || _maxLength == -1)); }