Example #1
0
        /// <summary>
        /// Create a new tree node.
        /// </summary>
        /// <param name="point">the grid point to create the node from</param>
        public TreeNode(GridPoint point)
        {
            this.x = point.x;
            this.y = point.y;
            this.z = point.z;
            this.t = point.t;
            this.value = point.value;

            this.parents = new List<TreeNode>();
            this.children = new List<TreeNode>();
        }
Example #2
0
        /// <summary>
        /// Check if two points 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(GridPoint 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;
        }
Example #3
0
 //===================================================================//
 //                            Getters                                //
 //===================================================================//
 /// <summary>
 /// Compares two AbstractGridPoints. Used for sorting a list of them.
 /// </summary>
 /// <param name="p1">the first point</param>
 /// <param name="p2">the second point</param>
 /// <returns>
 /// -1 if p1's value is greater;
 ///  1 if p2's value is greater;
 ///  0 if they are the same
 ///  </returns>
 public static int Compare(GridPoint p1, GridPoint p2)
 {
     if (p1.value > p2.value) { return -1; }
     if (p1.value < p2.value) { return  1; }
     return 0;
 }