//===================================================================// // Constructors // //===================================================================// /// <summary> /// Create a new ContourNode based on an existing TreeNode. /// </summary> /// <param name="node">the node to copy</param> public ContourNode(TreeNode node) { this.x = node.x; this.y = node.y; this.z = node.z; this.t = node.t; this.value = node.value; this.branches = new List<ContourNode>(); }
/// <summary> /// Copy constructor for tree node. /// Copies x, y, z, and value. /// </summary> /// <param name="other">the node to copy.</param> public TreeNode(TreeNode other) { this.x = other.x; this.y = other.y; this.z = other.z; this.t = other.t; this.value = other.value; this.parents = new List<TreeNode>(); this.children = new List<TreeNode>(); }
/// <summary> /// Adds the specified node as a parent of this node. /// </summary> /// <param name="other">the node to make a parent of this node</param> public void AddParent(TreeNode other) { this.parents.Add(other); }
/// <summary> /// Adds the specified node as a child of this node. /// </summary> /// <param name="other">the node to make a child of this node</param> public void AddChild(TreeNode other) { this.children.Add(other); }
/// <summary> /// Determines if this node's x, y, z, and value values match another node's values. /// </summary> /// <param name="other">the node to check against</param> /// <returns>true if they match; false otherwise</returns> public bool Matches(TreeNode other) { return (this.x == other.x) && (this.y == other.y) && (this.z == other.z) && (this.t == other.t); }
/// <summary> /// Check if two tree nodes are considered adjacent to each other. /// </summary> /// <param name="other">the other point</param> /// <returns>true if they're adjacent; false otherwise</returns> public bool IsAdjacentTo(TreeNode other) { int diff_x = this.x - other.x; int diff_y = this.y - other.y; int diff_z = this.z - other.z; int diff_t = this.t - other.t; if (Math.Abs(diff_x) > 1 || Math.Abs(diff_y) > 1 || Math.Abs(diff_z) > 1 || Math.Abs(diff_z) > 1) { return false; } if (diff_x < 0 || diff_y < 0 || diff_z < 0 || diff_t < 0) { diff_x *= -1; diff_y *= -1; diff_z *= -1; diff_t *= -1; } if (diff_x < 0 || diff_y < 0 || diff_z < 0 || diff_t < 0) { return false; } return true; }
//===================================================================// // Booleans // //===================================================================// /// <summary> /// Checks if this node matches another TreeNode. /// </summary> /// <param name="other">the TreeNode to check</param> /// <returns>true if they match; false otherwise</returns> public bool Matches(TreeNode other) { return this.x == other.x && this.y == other.y && this.z == other.z && this.t == other.t; }