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.cs38
1 files changed, 38 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index e8dfec1..2276951 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -333,6 +333,44 @@ namespace OpenSim.Framework
333 return Utils.UIntsToLong(X, Y); 333 return Utils.UIntsToLong(X, Y);
334 } 334 }
335 335
336 // Regions are identified with a 'handle' made up of its region coordinates packed into a ulong.
337 // Several places rely on the ability to extract a region's location from its handle.
338 // Note the location is in 'world coordinates' (see below).
339 // Region handles are based on the lowest coordinate of the region so trim the passed x,y to be the regions 0,0.
340 public static ulong RegionWorldLocToHandle(uint X, uint Y)
341 {
342 return Utils.UIntsToLong(X, Y);
343 }
344
345 public static void RegionHandleToWorldLoc(ulong handle, out uint X, out uint Y)
346 {
347 X = (uint)(handle >> 32);
348 Y = (uint)(handle & (ulong)uint.MaxValue);
349 }
350
351 public static void RegionHandleToRegionLoc(ulong handle, out uint X, out uint Y)
352 {
353 uint worldX, worldY;
354 RegionHandleToWorldLoc(handle, out worldX, out worldY);
355 X = WorldToRegionLoc(worldX);
356 Y = WorldToRegionLoc(worldY);
357 }
358
359 // A region location can be 'world coordinates' (meters from zero) or 'region coordinates'
360 // (number of regions from zero). This measurement of regions relies on the legacy 256 region size.
361 // These routines exist to make what is being converted explicit so the next person knows what was meant.
362 // Convert a region's 'world coordinate' to its 'region coordinate'.
363 public static uint WorldToRegionLoc(uint worldCoord)
364 {
365 return worldCoord / Constants.RegionSize;
366 }
367
368 // Convert a region's 'region coordinate' to its 'world coordinate'.
369 public static uint RegionToWorldLoc(uint regionCoord)
370 {
371 return regionCoord * Constants.RegionSize;
372 }
373
336 public static T Clamp<T>(T x, T min, T max) 374 public static T Clamp<T>(T x, T min, T max)
337 where T : IComparable<T> 375 where T : IComparable<T>
338 { 376 {