예제 #1
0
        /// <summary>
        /// Clones this object.
        /// </summary>
        /// <returns>A clone of the object.</returns>
        public object Clone()
        {
            Hyperrectangle <T> copy = new Hyperrectangle <T> {
                Dimensions = _numDimensions
            };

            Array.Copy(_minimumBound, copy._minimumBound, _numDimensions);
            Array.Copy(_maximumBound, copy._maximumBound, _numDimensions);
            return(copy);
        }
예제 #2
0
        /// <summary>
        /// Creates a hyperrectangle which contains both arguments.
        /// </summary>
        /// <param name="lhs">The first hyperrectangle</param>
        /// <param name="rhs">The second hyperrectangle</param>
        /// <returns>The union of the two arguments</returns>
        public static Hyperrectangle <T> Union(Hyperrectangle <T> lhs, Hyperrectangle <T> rhs)
        {
            if (lhs.Dimensions != rhs.Dimensions)
            {
                throw new ArgumentException("Hyperrectangles must be of the same dimensionality.");
            }
            Hyperrectangle <T> result = new Hyperrectangle <T>(lhs.Dimensions);

            for (int i = 0; i < result._numDimensions; i++)
            {
                T lhsVal = lhs._minimumBound[i];
                T rhsVal = rhs._minimumBound[i];
                result._minimumBound[i] = lhsVal.CompareTo(rhsVal) < 0 ? lhsVal : rhsVal;
                lhsVal = lhs._maximumBound[i];
                rhsVal = rhs._maximumBound[i];
                result._maximumBound[i] = lhsVal.CompareTo(rhsVal) > 0 ? lhsVal : rhsVal;
            }
            return(result);
        }