Nez.Portable/Math/RectangleF.cs
/// <summary>
/// returns true if the boxes are colliding
/// moveX and moveY will return the movement that b1 must move to avoid the collision
/// </summary>
/// <param name="other">Other.</param>
/// <param name="moveX">Move x.</param>
/// <param name="moveY">Move y.</param>
returns true if the boxes are colliding
moveX and moveY will return the movement that b1 must move to avoid the collision
returns true if the boxes are colliding moveX and moveY will return the movement that b1 must move to avoid the collision
public bool collisionCheck(ref RectangleF other, out float moveX, out float moveY)
        {
            moveX = moveY = 0.0f;
            var l = other.x - (x + width);
            var r = (other.x + other.width) - x;
            var t = other.y - (y + height);
            var b = (other.y + other.height) - y;
            if (l > 0 || r < 0 || t > 0 || b < 0)
                return false;
            moveX = Math.Abs(l) < r ? l : r;
            moveY = Math.Abs(t) < b ? t : b;
            if (Math.Abs(moveX) < Math.Abs(moveY))
                moveY = 0.0f;
            else
                moveX = 0.0f;
            return true;
        }
public bool collisionCheck ( ref RectangleF other , out float moveX , out float moveY ) { moveX = moveY = 0.0f ; var l = other . x - ( x + width ) ; var r = ( other . x + other . width ) - x ; var t = other . y - ( y + height ) ; var b = ( other . y + other . height ) - y ; if ( l > 0 || r < 0 || t > 0 || b < 0 ) return false ; moveX = Math . Abs ( l ) < r ? l : r ; moveY = Math . Abs ( t ) < b ? t : b ; if ( Math . Abs ( moveX ) < Math . Abs ( moveY ) ) moveY = 0.0f ; else moveX = 0.0f ; return true ; }
returns true if the boxes are colliding
moveX and moveY will return the movement that b1 must move to avoid the collision
returns true if the boxes are colliding moveX and moveY will return the movement that b1 must move to avoid the collision
// check that there was a collision // find the offset of both sides // only use whichever offset is the smallest
RectangleF
ref
<not_specific>
float
out
<not_specific>
other
<not_specific>
None
moveX
<not_specific>
None
moveY
<not_specific>
None