/// <summary> /// Get squared distance between two world locations (in meters) /// </summary> public static float GetDistanceSquared(WorldLocation location1, WorldLocation location2) { var dx = location1.Location.X - location2.Location.X; var dy = location1.Location.Y - location2.Location.Y; var dz = location1.Location.Z - location2.Location.Z; dx += 2048 * (location1.TileX - location2.TileX); dz += 2048 * (location1.TileZ - location2.TileZ); return(dx * dx + dy * dy + dz * dz); }
/// <summary> /// Copy constructor using a MSTS-coordinates world-location /// </summary> public WorldPosition(WorldLocation copy) { TileX = copy.TileX; TileZ = copy.TileZ; Location = copy.Location; }
/// <summary> /// Get a (2D) vector pointing from <paramref name="locationFrom"/> to <paramref name="locationTo"/>, so neglecting height (y) information /// </summary> public static Vector2 GetDistance2D(WorldLocation locationFrom, WorldLocation locationTo) { return(new Vector2(locationTo.Location.X - locationFrom.Location.X + (locationTo.TileX - locationFrom.TileX) * 2048, locationTo.Location.Z - locationFrom.Location.Z + (locationTo.TileZ - locationFrom.TileZ) * 2048)); }
/// <summary> /// Check whether location1 and location2 are within given distance from each other /// </summary> /// <param name="location1">first location</param> /// <param name="location2">second location</param> /// <param name="distance">distance defining the boundary between 'within' and 'outside'</param> public static bool Within(WorldLocation location1, WorldLocation location2, float distance) { return(GetDistanceSquared(location1, location2) < distance * distance); }
/// <summary> /// Constructor from another location /// </summary> /// <param name="worldLocation">the other location to use as initialization</param> public WorldLocation(WorldLocation worldLocation) { TileX = worldLocation.TileX; TileZ = worldLocation.TileZ; Location = worldLocation.Location; }
/// <summary> /// Create a nice string-representation of the world position /// </summary> public override string ToString() { return(WorldLocation.ToString()); }