Exemple #1
0
        private static RectPrism OrderMinMax(RectPrism rect)
        {
            if ((double)rect.xMin > (double)rect.xMax)
            {
                float xMin = rect.xMin;
                rect.xMin = rect.xMax;
                rect.xMax = xMin;
            }

            if ((double)rect.yMin > (double)rect.yMax)
            {
                float yMin = rect.yMin;
                rect.yMin = rect.yMax;
                rect.yMax = yMin;
            }

            if ((double)rect.zMin > (double)rect.zMax)
            {
                float zMin = rect.zMin;
                rect.zMin = rect.zMax;
                rect.zMax = zMin;
            }

            return(rect);
        }
Exemple #2
0
 /// <summary>
 ///   <para>Returns a point inside a rectangle, given normalized coordinates.</para>
 /// </summary>
 /// <param name="rectangle">Rectangle to get a point inside.</param>
 /// <param name="normalizedRectCoordinates">Normalized coordinates to get a point for.</param>
 public static Vector3 NormalizedToPoint(RectPrism rectangle, Vector3 normalizedRectCoordinates)
 {
     return(new Vector3(
                UnityEngine.Mathf.Lerp(rectangle.x, rectangle.xMax, normalizedRectCoordinates.x),
                UnityEngine.Mathf.Lerp(rectangle.y, rectangle.yMax, normalizedRectCoordinates.y),
                UnityEngine.Mathf.Lerp(rectangle.z, rectangle.zMax, normalizedRectCoordinates.z)
                ));
 }
Exemple #3
0
 /// <summary>
 ///   <para></para>
 /// </summary>
 /// <param name="source"></param>
 public RectPrism(RectPrism source)
 {
     m_XMin   = source.m_XMin;
     m_YMin   = source.m_YMin;
     m_ZMin   = source.m_ZMin;
     m_Width  = source.m_Width;
     m_Height = source.m_Height;
     m_Depth  = source.m_Depth;
 }
Exemple #4
0
 /// <summary>
 ///   <para>Set components of an existing Rect.</para>
 /// </summary>
 /// <param name="source">The rect to copy values from</param>
 public void Set(RectPrism source)
 {
     m_XMin   = source.x;
     m_YMin   = source.y;
     m_ZMin   = source.z;
     m_Width  = source.Width;
     m_Height = source.Height;
     m_Depth  = source.Depth;
 }
Exemple #5
0
        /// <summary>
        ///   <para>Returns true if the other rectangle overlaps this one. If allowInverse is present and true, the widths and heights of the Rects are allowed to take negative values (ie, the min value is greater than the max), and the test will still work.</para>
        /// </summary>
        /// <param name="other">Other rectangle to test overlapping with.</param>
        /// <param name="allowInverse">Does the test allow the widths and heights of the Rects to be negative?</param>
        public bool Overlaps(RectPrism other, bool allowInverse)
        {
            RectPrism rect = this;

            if (allowInverse)
            {
                rect  = RectPrism.OrderMinMax(rect);
                other = RectPrism.OrderMinMax(other);
            }

            return(rect.Overlaps(other));
        }
Exemple #6
0
 /// <summary>
 ///   <para>Returns the normalized coordinates cooresponding the the point.</para>
 /// </summary>
 /// <param name="rectangle">Rectangle to get normalized coordinates inside.</param>
 /// <param name="point">A point inside the rectangle to get normalized coordinates for.</param>
 /// <param name="clamped">Whether the resulting vector will be clamped between {0,0,0} and {1,1,1}</param>
 public static Vector3 PointToNormalized(RectPrism rectangle, Vector3 point, bool clamped = true)
 {
     if (!clamped)
     {
         return(new Vector3(
                    MathfExtensions.InverseLerpUnclamped(rectangle.x, rectangle.xMax, point.x),
                    MathfExtensions.InverseLerpUnclamped(rectangle.y, rectangle.yMax, point.y),
                    MathfExtensions.InverseLerpUnclamped(rectangle.z, rectangle.zMax, point.z)
                    ));
     }
     else
     {
         return(new Vector3(
                    UnityEngine.Mathf.InverseLerp(rectangle.x, rectangle.xMax, point.x),
                    UnityEngine.Mathf.InverseLerp(rectangle.y, rectangle.yMax, point.y),
                    UnityEngine.Mathf.InverseLerp(rectangle.z, rectangle.zMax, point.z)
                    ));
     }
 }
Exemple #7
0
 public bool Equals(RectPrism other)
 {
     return(m_XMin.Equals(other.m_XMin) && m_YMin.Equals(other.m_YMin) && m_ZMin.Equals(other.m_ZMin) &&
            m_Width.Equals(other.m_Width) && m_Height.Equals(other.m_Height) && m_Depth.Equals(other.m_Depth));
 }
Exemple #8
0
 /// <summary>
 ///   <para>Returns true if the other rectangle overlaps this one. If allowInverse is present and true, the widths and heights of the Rects are allowed to take negative values (ie, the min value is greater than the max), and the test will still work.</para>
 /// </summary>
 /// <param name="other">Other rectangle to test overlapping with.</param>
 public bool Overlaps(RectPrism other)
 {
     return((double)other.xMax > (double)xMin && (double)other.xMin < (double)xMax &&
            (double)other.yMax > (double)yMin && (double)other.yMin < (double)yMax &&
            (double)other.zMax > (double)zMin && (double)other.zMin < (double)zMax);
 }