public void AddTrunk() { var newSegment = new TrunkNode() { Position = TrunkNodes.Count, BranchLeft = new BranchNode() { HasBranch = false }, BranchRight = new BranchNode() { HasBranch = false } }; newSegment.BranchLeft.AttachedTrunk = newSegment; newSegment.BranchRight.AttachedTrunk = newSegment; TrunkNodes.Add(newSegment); BranchNodes.Add(newSegment.BranchLeft); BranchNodes.Add(newSegment.BranchRight); TrunkCost = this.CalculateTrunkCost(); OnTrunkNodesUpdated?.Invoke(); }
public void TestNodeParent() { var root = new RootNode("Root"); var trunk = new TrunkNode("Trunk"); root.AddChild(trunk); Assert.AreEqual(root, trunk.GetParent()); }
public void TestCannotAddLeavesToTrunk() { var trunk = new TrunkNode("Trunk doesn't allow leaves to be added"); try { trunk.AddChild(new LeafNode("Leaf")); Assert.Fail(); } catch (Exception ex) { Assert.AreEqual(typeof(ArgumentException), ex.GetType()); } }
public TreeData(List <MapNode> startRoots) { TrunkNodes = new List <TrunkNode>(); BranchNodes = new List <BranchNode>(); RootNodes = startRoots; RootLines = new List <List <Vector3> >(); startRoots.ForEach(x => RootLines.Add(new List <Vector3>() { new Vector3(0f, Random.Range(0.6f, 0.7f), 0f), x.WorldPosition })); // Starting data TrunkNodes.Add(new TrunkNode() { Position = 0 }); var firstSegment = new TrunkNode() { Position = 1, BranchLeft = new BranchNode() { HasBranch = false }, BranchRight = new BranchNode() { HasBranch = false } }; firstSegment.BranchLeft.AttachedTrunk = firstSegment; firstSegment.BranchRight.AttachedTrunk = firstSegment; BranchNodes.Add(firstSegment.BranchLeft); BranchNodes.Add(firstSegment.BranchRight); TrunkNodes.Add(firstSegment); RootCost = this.CalculateRootCost(); BranchCost = this.CalculateBranchCost(); TrunkCost = this.CalculateTrunkCost(); }