Build 0.20.7.0

This commit is contained in:
Markus Isberg
2022-11-18 18:13:38 +02:00
parent 8c8fd865c5
commit ecb6d40b4b
111 changed files with 1346 additions and 701 deletions
@@ -562,35 +562,45 @@ namespace Barotrauma
public static double LineSegmentToPointDistanceSquared(Point lineA, Point lineB, Point point)
{
double xDiff = lineB.X - lineA.X;
double yDiff = lineB.Y - lineA.Y;
return LineSegmentToPointDistanceSquared(lineA.X, lineA.Y, lineB.X, lineB.Y, point.X, point.Y);
}
public static float LineSegmentToPointDistanceSquared(Vector2 lineA, Vector2 lineB, Vector2 point)
{
return (float)LineSegmentToPointDistanceSquared(lineA.X, lineA.Y, lineB.X, lineB.Y, point.X, point.Y);
}
private static double LineSegmentToPointDistanceSquared(double line1X, double line1Y, double line2X, double line2Y, double pointX, double pointY)
{
double xDiff = line2X - line1X;
double yDiff = line2Y - line1Y;
if (xDiff == 0 && yDiff == 0)
{
double v1 = lineA.X - point.X;
double v2 = lineA.Y - point.Y;
double v1 = line1X - pointX;
double v2 = line1Y - pointY;
return (v1 * v1) + (v2 * v2);
}
// Calculate the t that minimizes the distance.
double t = ((point.X - lineA.X) * xDiff + (point.Y - lineA.Y) * yDiff) / (xDiff * xDiff + yDiff * yDiff);
double t = ((pointX - line1X) * xDiff + (pointY - line1Y) * yDiff) / (xDiff * xDiff + yDiff * yDiff);
// See if this represents one of the segment's
// end points or a point in the middle.
if (t < 0)
{
xDiff = point.X - lineA.X;
yDiff = point.Y - lineA.Y;
xDiff = pointX - line1X;
yDiff = pointY - line1Y;
}
else if (t > 1)
{
xDiff = point.X - lineB.X;
yDiff = point.Y - lineB.Y;
xDiff = pointX - line2X;
yDiff = pointY - line2Y;
}
else
{
xDiff = point.X - (lineA.X + t * xDiff);
yDiff = point.Y - (lineA.Y + t * yDiff);
xDiff = pointX - (line1X + t * xDiff);
yDiff = pointY - (line1Y + t * yDiff);
}
return xDiff * xDiff + yDiff * yDiff;
@@ -7,6 +7,7 @@ using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using Barotrauma.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
@@ -825,16 +826,29 @@ namespace Barotrauma
public static bool StatIdentifierMatches(Identifier original, Identifier match)
{
if (original == match) { return true; }
return Matches(original, match) || Matches(match, original);
for (int i = 0; i < match.Value.Length; i++)
static bool Matches(Identifier a, Identifier b)
{
if (i >= original.Value.Length) { return match[i] is '~'; }
if (!CharEquals(original[i], match[i])) { return false; }
for (int i = 0; i < b.Value.Length; i++)
{
if (i >= a.Value.Length) { return b[i] is '~'; }
if (!CharEquals(a[i], b[i])) { return false; }
}
return false;
}
return false;
static bool CharEquals(char a, char b) => char.ToLowerInvariant(a) == char.ToLowerInvariant(b);
}
public static bool EquivalentTo(this IPEndPoint self, IPEndPoint other)
=> self.Address.EquivalentTo(other.Address) && self.Port == other.Port;
public static bool EquivalentTo(this IPAddress self, IPAddress other)
{
if (self.IsIPv4MappedToIPv6) { self = self.MapToIPv4(); }
if (other.IsIPv4MappedToIPv6) { other = other.MapToIPv4(); }
return self.Equals(other);
}
}
}