Beispiel #1
0
        ////////////////////////////////////////////////////////////////////////
        /// <summary> Snap this box to another box </summary>
        /// <param name="snapBox"> The box to snap to </param>
        /// <param name="threshold"> The threshold within this box will snap </param>
        /// <returns> Whether or not this box was within the threshold and snapped to it </returns>
        ////////////////////////////////////////////////////////////////////////
        public bool IntelliSnapToBox(Box2i snapBox, int threshold)
        {
            // Test if we snap
            Vector2i moveVect = new Vector2i(0, 0);

            if (!GetIntelliSnapOffset(snapBox, threshold, ref moveVect))
            {
                return(false);
            }

            // Move the box
            pos += moveVect;

            // We snapped the box
            return(true);
        }
Beispiel #2
0
        ////////////////////////////////////////////////////////////////////////
        /// <summary> Is a point contained within this box.  The left and top
        /// sides are inclusive but if the point is on the right and bottom
        /// then it is not contained </summary>
        /// <param name="pt"> The point to test for containment </param>
        /// <returns> Whether or not the point is contained </returns>
        ////////////////////////////////////////////////////////////////////////
        public bool ContainsPoint(Point2i pt)
        {
            // If we have a negative dimension, check differently
            if (dims.x < 0)
            {
                if ((pt.x >= pos.x) || (pt.x < (pos.x + dims.x)))
                {
                    return(false);
                }
            }
            // Else check normally
            else
            {
                if ((pt.x < pos.x) || (pt.x >= (pos.x + dims.x)))
                {
                    return(false);
                }
            }

            // Test the y component
            if (dims.y < 0.0f)
            {
                if ((pt.y >= pos.y) || (pt.y < (pos.y + dims.y)))
                {
                    return(false);
                }
            }
            // Else check normally
            else
            {
                if ((pt.y < pos.y) || (pt.y >= (pos.y + dims.y)))
                {
                    return(false);
                }
            }

            // The point is inside
            return(true);
        }
Beispiel #3
0
 ////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Construct a pox from a position and size
 /// </summary>
 /// <param name="inPos"> The position of the box </param>
 /// <param name="inSize"> The size of the box </param>
 ////////////////////////////////////////////////////////////////////////
 public Box2i(Point2i inPos, Vector2i inSize)
 {
     pos  = inPos;
     dims = inSize;
 }
Beispiel #4
0
 ////////////////////////////////////////////////////////////////////////
 /// <summary> A copy constructor from a floating point box </summary>
 /// <param name="copy"> The box to copy </param>
 ////////////////////////////////////////////////////////////////////////
 public Box2i(Box2 copy)
 {
     pos  = new Point2i(copy.pos);
     dims = new Vector2i(copy.dims);
 }
Beispiel #5
0
 ////////////////////////////////////////////////////////////////////////
 /// <summary> A copy constructor </summary>
 /// <param name="copy"> The box to copy </param>
 ////////////////////////////////////////////////////////////////////////
 public Box2i(Box2i copy)
 {
     pos = copy.pos; dims = copy.dims;
 }
Beispiel #6
0
 ///////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Initialize a point from another point
 /// </summary>
 ///////////////////////////////////////////////////////////////////////
 public Point2i(Point2i copyPt)
 {
     x = copyPt.x; y = copyPt.y;
 }
Beispiel #7
0
 ///////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Initialize a point from an integer point
 /// </summary>
 ///////////////////////////////////////////////////////////////////////
 public Point2(Point2i copyPt)
 {
     x = (float)copyPt.x; y = (float)copyPt.y;
 }