diff --git a/Sources/Sandbox.Game/Game/Entities/Cube/MyCubeGrid.Static.cs b/Sources/Sandbox.Game/Game/Entities/Cube/MyCubeGrid.Static.cs index 36f589be87..3a3e7a6b87 100644 --- a/Sources/Sandbox.Game/Game/Entities/Cube/MyCubeGrid.Static.cs +++ b/Sources/Sandbox.Game/Game/Entities/Cube/MyCubeGrid.Static.cs @@ -508,8 +508,8 @@ public static bool CheckConnectivity(IMyGridConnectivityTest grid, MyCubeBlockDe // This code is used to avoid mixed start, end values, overlapped values on sides. So as result we need precise neighbour(s). Not neighbours touched on edges. // Start and end sometimes have exchanged values - Vector3 start = Vector3.Min(thisMountPoint.Start, thisMountPoint.End); - Vector3 end = Vector3.Max(thisMountPoint.Start, thisMountPoint.End); + Vector3 start, end; + Vector3.MinMax(thisMountPoint.Start, thisMountPoint.End, out start, out end); // Clamp only overlapped values on sides not thickness of aabb of mount point Vector3I clampMask = Vector3I.One - Vector3I.Abs(thisMountPoint.Normal); @@ -547,8 +547,8 @@ public static bool CheckConnectivity(IMyGridConnectivityTest grid, MyCubeBlockDe m_cacheNeighborBlocks.Clear(); - var currentMin = Vector3.Min(gridPosStart, gridPosEnd); - var currentMax = Vector3.Max(gridPosStart, gridPosEnd); + Vector3 currentMin, currentMax; + Vector3.MinMax(gridPosStart, gridPosEnd, out currentMin, out currentMax); var minI = Vector3I.Floor(currentMin); var maxI = Vector3I.Floor(currentMax); diff --git a/Sources/VRage.Math/Vector3.cs b/Sources/VRage.Math/Vector3.cs index c9fb47d8e0..4be087bbae 100644 --- a/Sources/VRage.Math/Vector3.cs +++ b/Sources/VRage.Math/Vector3.cs @@ -796,6 +796,46 @@ public float AbsMax() } } + /// + /// Returns the vector that contains the lowest and the highest value from each matching pair of components. + /// + /// Source vector.Source vector.[OutAttribute] The minimized vector.[OutAttribute] The maximized vector. + public static void MinMax(Vector3 value1, Vector3 value2, out Vector3 min, out Vector3 max) + { + if (value1.X < value2.X) + { + min.X = value1.X; + max.X = value2.X; + } + else + { + max.X = value1.X; + min.X = value2.X; + } + + if (value1.Y < value2.Y) + { + min.Y = value1.Y; + max.Y = value2.Y; + } + else + { + max.Y = value1.Y; + min.Y = value2.Y; + } + + if (value1.Z < value2.Z) + { + min.Z = value1.Z; + max.Z = value2.Z; + } + else + { + max.Z = value1.Z; + min.Z = value2.Z; + } + } + /// /// Returns a vector that contains the lowest value from each matching pair of components. ///