Exemplo n.º 1
0
        /// <summary>
        /// Returns the specified child octant instance, or instantiates a new octant if the specified child instance
        /// is <c>null</c>. The newly constructed instance will then be returned.
        /// </summary>
        /// <param name="octants">
        /// A reference to the <see cref="Octant"/> array from which to get the specified instance.
        /// </param>
        /// <param name="index">The index in the array whose held instance to get or set.</param>
        /// <param name="newMidpoint">The midpoint of the new child instance, if necessary.</param>
        /// <param name="newSideLength">The side length of the new child instance, if necessary.</param>
        /// <returns>The instance held at the specified index, or the newly created instance.</returns>
        private static Octant GetOrSetChildOctant(ref Octant[] octants, int index, Vector4 newMidpoint, double newSideLength)
        {
            if (octants != null && octants?[index] == null)
            {
                octants[index] = new Octant(newMidpoint, newSideLength);
            }

            return(octants?[index]);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the specified child octant tree instance, or instantiates a new octant tree if the specified child
        /// instance is <c>null</c>. The newly constructed instance will then be returned.
        /// </summary>
        /// <param name="trees">
        /// A reference to the <see cref="OctantTree"/> array from which to get the specified instance.
        /// </param>
        /// <param name="index">The index in the array whose held instance to get or set.</param>
        /// <param name="newOctant">
        /// The octant instance representing the space managed by the new child tree instance, if necessary.
        /// </param>
        /// <returns>The instance held at the specified index, or the newly created instance.</returns>
        public static OctantTree GetOrSetSubTree(ref OctantTree[] trees, int index, Octant newOctant)
        {
            if (trees != null && trees?[index] == null)
            {
                trees[index] = new OctantTree(newOctant);
            }

            return(trees?[index]);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialises a new instance of the <see cref="Octant"/> class.
        /// </summary>
        /// <param name="octant">The previous instance to make a copy of.</param>
        public Octant(Octant octant)
        {
            midpoint          = octant.Midpoint;
            sideLength        = octant.sideLength;
            halfSideLength    = octant.halfSideLength;
            quarterSideLength = octant.quarterSideLength;

            childOctants = new Octant[8];
            octant.childOctants.CopyTo(childOctants, 0);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Whether this instance is currently inside the bounds of the given <see cref="Octant"/> instance.
 /// </summary>
 /// <param name="octant">The octant to check.</param>
 /// <returns>Whether this <see cref="Body"/> instance is inside the given <see cref="Octant"/> instance.</returns>
 public bool IsInOctant(Octant octant)
 {
     return(octant.ContainsPoint(position));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Initialises a new instance of the <see cref="OctantTree"/> class.
        /// </summary>
        /// <param name="octant">The <see cref="Octant"/> instance representing the space managed by this instance.</param>
        public OctantTree(Octant octant)
        {
            this.octant = octant;

            childTrees = new OctantTree[8];
        }