/// <summary> /// Calculates the overlap of the cubes on single axis having one of the center coordinates and size. /// </summary> private T CalculateOverlapOnSingleAxis(T centerCoord1, T size1, T centerCoord2, T size2) { // basically there are two cases, when on a single axis one cube overlap entirelly the second one and when not :) // not really a rocket science :) T sDiff = _calc.Div2(_calc.Add(size1, size2)); T xLeft1 = _calc.Sub(centerCoord1, _calc.Div2(size1)); T xRight1 = _calc.Add(centerCoord1, _calc.Div2(size1)); T xLeft2 = _calc.Sub(centerCoord2, _calc.Div2(size2)); T xRight2 = _calc.Add(centerCoord2, _calc.Div2(size2)); // first one overlap second if (_calc.Contains(xLeft1, xRight1, xLeft2, xRight2)) { return(size2); } // second overlap first else if (_calc.Contains(xLeft2, xRight2, xLeft1, xRight1)) { return(size1); } // they overlap partially or not at all else { T xDist = _calc.Abs(_calc.Sub(centerCoord1, centerCoord2)); return(_calc.Sub(sDiff, xDist)); } }