/// <summary> /// Disjoint Returns true if disjoint. Returns false if intersecting, /// and sets the overlap depth, d scaled by the axis length /// </summary> /// <param name="d"></param> /// <param name="axis"></param> /// <param name="box"></param> /// <param name="triangle"></param> /// <param name="collTolerance"></param> /// <returns></returns> private static bool Disjoint(out float d, Vector3 axis, Box box, Triangle triangle, float collTolerance) { float min0, max0, min1, max1; box.GetSpan(out min0, out max0, axis); triangle.GetSpan(out min1, out max1, axis); if (min0 > (max1 + collTolerance + JiggleMath.Epsilon) || min1 > (max0 + collTolerance + JiggleMath.Epsilon)) { d = 0.0f; return true; } if ((max0 > max1) && (min1 > min0)) { // triangle is inside - choose the min dist to move it out d = System.Math.Min(max0 - min1, max1 - min0); } else if ((max1 > max0) && (min0 > min1)) { // box is inside - choose the min dist to move it out d = System.Math.Min(max1 - min0, max0 - min1); } else { // objects overlap d = (max0 < max1) ? max0 : max1; d -= (min0 > min1) ? min0 : min1; } return false; }
// BEN-OPTIMISATION: ref axis and ref triangle, BEN-CLEANUP: Renamed min and max variables. /// <summary> /// Disjoint Returns true if disjoint. Returns false if intersecting, /// and sets the overlap depth, d scaled by the axis length /// </summary> /// <param name="d"></param> /// <param name="axis"></param> /// <param name="box"></param> /// <param name="triangle"></param> /// <param name="collTolerance"></param> /// <returns>bool</returns> private static bool Disjoint(out float d, ref Vector3 axis, Box box, ref Triangle triangle, float collTolerance) { float minBox, maxBox, minTri, maxTri; // BEN-OPTIMISATION: ref axis box.GetSpan(out minBox, out maxBox, ref axis); triangle.GetSpan(out minTri, out maxTri, ref axis); if (minBox > (maxTri + collTolerance + JiggleMath.Epsilon) || minTri > (maxBox + collTolerance + JiggleMath.Epsilon)) { d = 0.0f; return (true); } if ((maxBox > maxTri) && (minTri > minBox)) { // triangle is inside - choose the min dist to move it out d = System.Math.Min(maxBox - minTri, maxTri - minBox); } else if ((maxTri > maxBox) && (minBox > minTri)) { // box is inside - choose the min dist to move it out d = System.Math.Min(maxTri - minBox, maxBox - minTri); } else { // objects overlap d = (maxBox < maxTri) ? maxBox : maxTri; d -= (minBox > minTri) ? minBox : minTri; } return (false); }
/// <summary> /// Disjoint Returns true if disjoint. Returns false if intersecting, /// and sets the overlap depth, d scaled by the axis length. /// </summary> /// <param name="d"></param> /// <param name="axis"></param> /// <param name="box0"></param> /// <param name="box1"></param> /// <param name="collTolerance"></param> /// <returns>bool</returns> private static bool Disjoint(out float d, ref Vector3 axis, Box box0, Box box1, float collTolerance) { float min0, max0, min1, max1; // BEN-OPTIMISATION: Used new GetSpan() with referenced axis. box0.GetSpan(out min0, out max0, ref axis); box1.GetSpan(out min1, out max1, ref axis); if (min0 > (max1 + collTolerance + JiggleMath.Epsilon) || min1 > (max0 + collTolerance + JiggleMath.Epsilon)) { d = 0.0f; return true; } if ((max0 > max1) && (min1 > min0)) { // box1 is inside - choose the min dist to move it out d = MathHelper.Min(max0 - min1, max1 - min0); } else if ((max1 > max0) && (min0 > min1)) { // box0 is inside - choose the min dist to move it out d = MathHelper.Min(max1 - min0, max0 - min1); } else { // boxes overlap d = (max0 < max1) ? max0 : max1; d -= (min0 > min1) ? min0 : min1; } return false; }