aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs65
1 files changed, 62 insertions, 3 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 59159a8..0851d26 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -54,7 +54,7 @@ namespace OpenSim.Framework
54 /// </summary> 54 /// </summary>
55 public class Util 55 public class Util
56 { 56 {
57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 57 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
58 58
59 private static uint nextXferID = 5000; 59 private static uint nextXferID = 5000;
60 private static Random randomClass = new Random(); 60 private static Random randomClass = new Random();
@@ -69,6 +69,39 @@ namespace OpenSim.Framework
69 69
70 public static readonly Regex UUIDPattern 70 public static readonly Regex UUIDPattern
71 = new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"); 71 = new Regex("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$");
72
73 /// <summary>
74 /// Linear interpolates B<->C using percent A
75 /// </summary>
76 /// <param name="a"></param>
77 /// <param name="b"></param>
78 /// <param name="c"></param>
79 /// <returns></returns>
80 public static double lerp(double a, double b, double c)
81 {
82 return (b*a) + (c*(1 - a));
83 }
84
85 /// <summary>
86 /// Bilinear Interpolate, see Lerp but for 2D using 'percents' X & Y.
87 /// Layout:
88 /// A B
89 /// C D
90 /// A<->C = Y
91 /// C<->D = X
92 /// </summary>
93 /// <param name="x"></param>
94 /// <param name="y"></param>
95 /// <param name="a"></param>
96 /// <param name="b"></param>
97 /// <param name="c"></param>
98 /// <param name="d"></param>
99 /// <returns></returns>
100 public static double lerp2D(double x, double y, double a, double b, double c, double d)
101 {
102 return lerp(y, lerp(x, a, b), lerp(x, c, d));
103 }
104
72 105
73 public static Encoding UTF8 = Encoding.UTF8; 106 public static Encoding UTF8 = Encoding.UTF8;
74 107
@@ -105,7 +138,7 @@ namespace OpenSim.Framework
105 float dx = a.X - b.X; 138 float dx = a.X - b.X;
106 float dy = a.Y - b.Y; 139 float dy = a.Y - b.Y;
107 float dz = a.Z - b.Z; 140 float dz = a.Z - b.Z;
108 return (dx*dx + dy*dy + dz*dz) < (amount*amount); 141 return (dx*dx + dy*dy + dz*dz) < (amount*amount);
109 } 142 }
110 143
111 /// <summary> 144 /// <summary>
@@ -944,7 +977,7 @@ namespace OpenSim.Framework
944 else 977 else
945 { 978 {
946 os = ReadEtcIssue(); 979 os = ReadEtcIssue();
947 } 980 }
948 981
949 if (os.Length > 45) 982 if (os.Length > 45)
950 { 983 {
@@ -1172,6 +1205,32 @@ namespace OpenSim.Framework
1172 return found.ToArray(); 1205 return found.ToArray();
1173 } 1206 }
1174 1207
1208 public static string ServerURI(string uri)
1209 {
1210 if (uri == string.Empty)
1211 return string.Empty;
1212
1213 // Get rid of eventual slashes at the end
1214 uri = uri.TrimEnd('/');
1215
1216 IPAddress ipaddr1 = null;
1217 string port1 = "";
1218 try
1219 {
1220 ipaddr1 = Util.GetHostFromURL(uri);
1221 }
1222 catch { }
1223
1224 try
1225 {
1226 port1 = uri.Split(new char[] { ':' })[2];
1227 }
1228 catch { }
1229
1230 // We tried our best to convert the domain names to IP addresses
1231 return (ipaddr1 != null) ? "http://" + ipaddr1.ToString() + ":" + port1 : uri;
1232 }
1233
1175 #region FireAndForget Threading Pattern 1234 #region FireAndForget Threading Pattern
1176 1235
1177 public static void FireAndForget(System.Threading.WaitCallback callback) 1236 public static void FireAndForget(System.Threading.WaitCallback callback)