public static double DistanceSqrt( IPoint2D from, IPoint2D to ) { float xDelta = Math.Abs( from.X - to.X ); float yDelta = Math.Abs( from.Y - to.Y ); return Math.Sqrt( xDelta*xDelta + yDelta*yDelta ); }
public static int Distance( IPoint2D from, IPoint2D to ) { int xDelta = Math.Abs( from.X - to.X ); int yDelta = Math.Abs( from.Y - to.Y ); return ( xDelta > yDelta ? xDelta : yDelta ); }
public bool Contains(IPoint2D p) { foreach (var rect in m_Rects) { if (rect.Contains(p)) return true; } return false; }
public bool Contains(IPoint2D p) { foreach (Rectangle2D rect in this.m_Rects) { if (rect.Contains(p)) return true; } return false; }
public static NestArea Find(IPoint2D p) { foreach (NestArea area in m_Areas) { if (area.Contains(p)) return area; } return null; }
/// <summary> /// Calculates the distance between two points /// </summary> /// <param name="origin">the starting point</param> /// <param name="target">the ending point</param> /// <returns>an integer of the distance between the origin and target</returns> public static int DistanceBetween( IPoint2D origin, IPoint2D target ) { if( origin.X == target.X ) return Math.Abs((origin.Y - target.Y)); if( origin.Y == target.Y ) return Math.Abs((origin.Y - target.Y)); //pythagorean theorem... dist = sqrt of (x2-x1)^2 + (y2-y1)^2 return (int)Math.Sqrt(Math.Pow(Math.Abs(target.X - origin.X), 2) + Math.Pow(Math.Abs(target.Y - origin.Y), 2)); }
public static BaseBoat FindBoatAt( IPoint2D loc, Map map ) { Sector sector = map.GetSector( loc ); for ( int i = 0; i < sector.Multis.Count; i++ ) { BaseBoat boat = sector.Multis[i] as BaseBoat; if ( boat != null && boat.Contains( loc.X, loc.Y ) ) return boat; } return null; }
private static bool ConsumeJumpStamina( Player pm, IPoint2D start, IPoint2D end ) { double weightRatio = (pm.TotalWeight / pm.MaxWeight); int weightInducedLoss = (int)(5 * weightRatio); int dist = Util.DistanceBetween(start, end); int toConsume = (int)(dist * 5); toConsume += weightInducedLoss; if( (pm.Stam - toConsume) <= 0 ) return false; pm.Stam -= toConsume; return true; }
public static BaseMulti FindMultiAt(IPoint2D loc, Map map) { Sector sector = map.GetSector(loc); for (int i = 0; i < sector.Multis.Count; i++) { BaseMulti multi = sector.Multis[i]; if (multi != null && multi.Contains(loc.X, loc.Y)) { return multi; } } return null; }
public static bool Contains(IPoint2D p, IPoint2D a, IPoint2D b, IPoint2D c) { var x = p.X - a.X; var y = p.Y - a.Y; var delta = (b.X - a.X) * y - (b.Y - a.Y) * x > 0; if ((c.X - a.X) * y - (c.Y - a.Y) * x > 0 == delta) { return false; } if ((c.X - b.X) * (p.Y - b.Y) - (c.Y - b.Y) * (p.X - b.X) > 0 != delta) { return false; } return true; }
/// <summary> /// Gets a Point2D collection representing all locations between 'start' and 'end', including 'start' and 'end'. /// </summary> public static Point2D[] GetLine2D(this IPoint2D start, IPoint2D end) { return GetLine2D(start, end, null); }
public Rectangle2D(IPoint2D start, IPoint2D end) : this(start.X, start.Y, end.X, end.Y) { }
public Line2D(IPoint2D start, IPoint2D end) { m_Start = new Point2D(start); m_End = new Point2D(end); Fix(); }
public static StaticTile[] GetStaticTiles(this Map map, IPoint2D p, bool multis) { return(map.Tiles.GetStaticTiles(p.X, p.Y, multis)); }
public static Point2D Clone2D(this IPoint2D p, IPoint2D t) { return(new Point2D(p.X + t.X, p.Y + t.Y)); }
public static double GetAngle(this IPoint2D source, IPoint2D target, bool radians = false) { int x = source.X - target.X; int y = source.Y - target.Y; double angle = Math.Atan2(y, x) - Math.Atan2(y, x); if (!radians) { angle = Geometry.RadiansToDegrees(angle); } return angle; }
public static double GetDistance(this IPoint2D start, IPoint2D end) { return(Math.Abs(Math.Sqrt(Math.Pow(end.X - start.X, 2) + Math.Pow(end.Y - start.Y, 2)))); }
public static Point2D Delta2D(this IPoint2D start, int endX, int endY) { return(new Point2D(start.X - endX, start.Y - endY)); }
public static Point3D ToPoint3D(this IPoint2D p, int z = 0) { return(new Point3D(p.X, p.Y, z)); }
public static Point2D Delta2D(this IPoint2D start, IPoint2D end) { return(new Point2D(start.X - end.X, start.Y - end.Y)); }
public static Point2D Lerp2D(this IPoint2D start, int x, int y, double percent) { return(Clone2D(start, (int)((x - start.X) * percent), (int)((y - start.Y) * percent))); }
public static Point2D Lerp2D(this IPoint2D start, IPoint2D end, double percent) { return(Lerp2D(start, end.X, end.Y, percent)); }
public static Point2D Clone2D(this IPoint2D p, int xOffset = 0, int yOffset = 0) { return(new Point2D(p.X + xOffset, p.Y + yOffset)); }
public static Point2D Rotate2D(this IPoint2D from, IPoint2D to, int count) { int rx = from.X - to.X, ry = from.Y - to.Y; for (int i = 0; i < count; ++i) { int temp = rx; rx = -ry; ry = temp; } return new Point2D(to.X + rx, to.Y + ry); }
public static double GetDistance(this IPoint2D from, IPoint2D to) { int x = from.X - to.X; int y = from.Y - to.Y; return Math.Sqrt((x * x) + (y * y)); }
public static Point3D GetWorldTop(this IPoint2D p, Map map) { return(GetSurfaceTop(p, map, false)); }
public bool InSquareRange(IPoint2D p, int xyRange) { return ((((this.m_X >= (p.X - xyRange)) && (this.m_X <= (p.X + xyRange))) && (this.m_Y >= (p.Y - xyRange))) && (this.m_Y <= (p.Y + xyRange))); }
public static string ToCoordsString(this IPoint2D p, Map map) { return(ToCoords(p, map).ToString()); }
/// <summary> /// /// </summary> /// <param name="point2D"></param> /// <param name="z"></param> public Point3D(IPoint2D point2D, float z) : this(point2D.X, point2D.Y, z) { }
public static Coords ToCoords(this IPoint2D p, Map m) { return(new Coords(m, p)); }
public bool Contains(IPoint2D p) { return(m_Start <= p && m_End > p); }
public static int GetAverageZ(this IPoint2D p, Map map, int range) { return(GetAverageZ(new Rectangle2D(p.X - range, p.Y - range, (range * 2) + 1, (range * 2) + 1), map)); }
public Rectangle2D(IPoint2D start, IPoint2D end) { m_Start = new Point2D(start); m_End = new Point2D(end); }
public static void GetAverageZ(this IPoint2D p, Map map, out int cur, out int avg, out int top) { var land = new { T = map.Tiles.GetLandTile(p.X, p.Y), L = map.Tiles.GetLandTile(p.X, p.Y + 1), R = map.Tiles.GetLandTile(p.X + 1, p.Y), B = map.Tiles.GetLandTile(p.X + 1, p.Y + 1) }; var surf = new { T = GetSurfaceTop(p, map, false, false), L = GetSurfaceTop(Clone2D(p, 0, 1), map, false, false), R = GetSurfaceTop(Clone2D(p, 1), map, false, false), B = GetSurfaceTop(Clone2D(p, 1, 1), map, false, false) }; var nT = TileData.LandTable[land.T.ID].Name; var nL = TileData.LandTable[land.L.ID].Name; var nR = TileData.LandTable[land.R.ID].Name; var nB = TileData.LandTable[land.B.ID].Name; var zT = (land.T.Ignored || nT == "NoName" || surf.T.Z > Region.MinZ) ? surf.T.Z : land.T.Z; var zL = (land.L.Ignored || nL == "NoName" || surf.L.Z > Region.MinZ) ? surf.L.Z : land.L.Z; var zR = (land.R.Ignored || nR == "NoName" || surf.R.Z > Region.MinZ) ? surf.R.Z : land.R.Z; var zB = (land.B.Ignored || nB == "NoName" || surf.B.Z > Region.MinZ) ? surf.B.Z : land.B.Z; cur = zT; if (zL > Region.MinZ && zL < cur) { cur = zL; } if (zR > Region.MinZ && zR < cur) { cur = zR; } if (zB > Region.MinZ && zB < cur) { cur = zB; } top = zT; if (zL > Region.MinZ && zL > top) { top = zL; } if (zR > Region.MinZ && zR > top) { top = zR; } if (zB > Region.MinZ && zB > top) { top = zB; } if (cur <= Region.MinZ) { cur = 0; } if (top <= Region.MinZ) { top = 0; } if (zT <= Region.MinZ) { zT = 0; } if (zL <= Region.MinZ) { zL = 0; } if (zR <= Region.MinZ) { zR = 0; } if (zB <= Region.MinZ) { zB = 0; } var vL = zL + zR; if (vL < 0) { --vL; } var vR = zT + zB; if (vR < 0) { --vR; } avg = Math.Abs(zT - zB) > Math.Abs(zL - zR) ? vL / 2 : vR / 2; }
public Point3D(IPoint2D p, int z) : this(p.X, p.Y, z) { }
public static MapPoint ToMapPoint(this IPoint2D p, Map m, int z = 0) { return(new MapPoint(m, p, z)); }
public static Direction GetDirection(this IPoint2D from, IPoint2D to) { int dx = to.X - from.X, dy = to.Y - from.Y, adx = Math.Abs(dx), ady = Math.Abs(dy); if (adx >= ady * 3) { if (dx > 0) { return Direction.East; } return Direction.West; } if (ady >= adx * 3) { if (dy > 0) { return Direction.South; } return Direction.North; } if (dx > 0) { if (dy > 0) { return Direction.Down; } return Direction.Right; } if (dy > 0) { return Direction.Left; } return Direction.Up; }
public static bool IsInHavenIsland(IPoint2D loc) { return(loc.X >= 3314 && loc.X <= 3814 && loc.Y >= 2345 && loc.Y <= 3095); }
/// <summary> /// Gets a Point2D collection representing all locations between 'start' and 'end', including 'start' and 'end', on the given 'map'. /// </summary> public static Point2D[] GetLine2D(this IPoint2D start, IPoint2D end, Map map) { var path = new List<Point2D>(); Geometry.Line2D(ToPoint3D(start), ToPoint3D(end), map, (p, m) => path.Add(ToPoint2D(p))); var arr = path.OrderBy(p => GetDistance(start, p)).ToArray(); path.Clear(); path.TrimExcess(); return arr; }
public static Point2D[] GetLine2D(this IPoint2D start, IPoint2D end) { return(PlotLine2D(start, end).ToArray()); }
public static Point2D Lerp2D(this IPoint2D start, IPoint2D end, double percent) { return Lerp2D(start, end.X, end.Y, percent); }
/// <summary> /// Returns the angle towards a target spot in degrees, clockwise /// </summary> /// <param name="tx">target x</param> /// <param name="ty">target y</param> /// <returns>the angle towards the spot</returns> public float GetAngle( IPoint2D point ) { float headingDifference = ( GetHeading( point ) & 0xFFF ) - ( this.Heading & 0xFFF ); if (headingDifference < 0) headingDifference += 4096.0f; return (headingDifference * 360.0f / 4096.0f); }
public static TimeSpan GetTravelTime(this IPoint2D from, IPoint2D to, double speed) { var d = GetDistance(from, to); var s = speed * 1.25; var tt = TimeSpan.FromSeconds(d / s); //Console.WriteLine("2D Travel Time: {0} / {1} = {2}", d, s, tt.TotalSeconds); return tt; }
public static bool HasLand(this Map map, IPoint2D p) { return !GetLandTile(map, p).Ignored; }
public double DistanceSqrt(IPoint2D p) { int num = this.m_X - p.X; int num2 = this.m_Y - p.Y; return Math.Sqrt((double) ((num * num) + (num2 * num2))); }
public static StaticTile[] GetStaticTiles(this Map map, IPoint2D p) { return map.Tiles.GetStaticTiles(p.X, p.Y); }
public static NestArea Find(IPoint2D p) { return(m_Areas.FirstOrDefault(area => area.Contains(p))); }
public static IEnumerable <Point2D> PlotLine2D(this IPoint2D start, IPoint2D end) { return(Line2D.Plot(start, end)); }
public static bool InRange(IPoint2D from, IPoint2D to, int range) { return (from.X >= (to.X - range)) && (from.X <= (to.X + range)) && (from.Y >= (to.Y - range)) && (from.Y <= (to.Y + range)); }
public bool Contains(IPoint2D p) { return(m_Rects.Any(rect => rect.Contains(p))); }
public static bool IsInHavenIsland( IPoint2D loc ) { return ( loc.X >= 3314 && loc.X <= 3814 && loc.Y >= 2345 && loc.Y <= 3095 ); }
public bool InRange(IPoint2D p, int range) => p.X >= Location.m_X - range && p.X <= Location.m_X + range && p.Y >= Location.m_Y - range && p.Y <= Location.m_Y + range;
public static bool HasWater(this Map map, IPoint2D p) { return IsWater(GetLandTile(map, p)) || GetStaticTiles(map, p).Any(IsWater); }
public bool Contains(IPoint2D p) { return(!IsDisposed && _Points.ContainsKey(GetHashCode(p.X, p.Y))); }
public static LandTile GetLandTile(this Map map, IPoint2D p) { return map.Tiles.GetLandTile(p.X, p.Y); }
public Point2D(IPoint2D p) : this(p.X, p.Y) { }
public static StaticTile[] GetStaticTiles(this Map map, IPoint2D p, bool multis) { return map.Tiles.GetStaticTiles(p.X, p.Y, multis); }
public static bool RangeCheck(IPoint2D p1, IPoint2D p2, int range) { return((p1.X >= (p2.X - range)) && (p1.X <= (p2.X + range)) && (p1.Y >= (p2.Y - range)) && (p2.Y <= (p2.Y + range))); }
public bool InRange( IPoint2D from, int range ) { if ( Region == null ) return false; foreach ( Rectangle3D rect in Region.Area ) { if ( from.X >= rect.Start.X - range && from.Y >= rect.Start.Y - range && from.X < rect.End.X + range && from.Y < rect.End.Y + range ) return true; } return false; }
public static StaticTile[] GetStaticTiles(this Map map, IPoint2D p) { return(map.Tiles.GetStaticTiles(p.X, p.Y)); }