public static Point2D GetRandomPoint2D(this IPoint2D start, int minRange, int maxRange) { var angle = Utility.RandomDouble() * Math.PI * 2; var radius = minRange + (Math.Sqrt(Utility.RandomDouble()) * (maxRange - minRange)); var x = (int)(radius * Math.Cos(angle)); var y = (int)(radius * Math.Sin(angle)); return(start.Clone2D(x, y)); }
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), L = GetSurfaceTop(p.Clone2D(0, 1), map, false), R = GetSurfaceTop(p.Clone2D(1), map, false), B = GetSurfaceTop(p.Clone2D(1, 1), map, false) }; int zT = (land.T.Ignored || TileData.LandTable[land.T.ID].Name == "NoName") ? surf.T.Z : land.T.Z; int zL = (land.L.Ignored || TileData.LandTable[land.L.ID].Name == "NoName") ? surf.L.Z : land.L.Z; int zR = (land.R.Ignored || TileData.LandTable[land.R.ID].Name == "NoName") ? surf.R.Z : land.R.Z; int zB = (land.B.Ignored || TileData.LandTable[land.B.ID].Name == "NoName") ? surf.B.Z : land.B.Z; cur = zT; if (zL < cur) { cur = zL; } if (zR < cur) { cur = zR; } if (zB < cur) { cur = zB; } top = zT; if (zL > top) { top = zL; } if (zR > top) { top = zR; } if (zB > top) { top = zB; } int vL = zL + zR; if (vL < 0) { --vL; } int vR = zT + zB; if (vR < 0) { --vR; } avg = Math.Abs(zT - zB) > Math.Abs(zL - zR) ? vL / 2 : vR / 2; }
public static Point2D Lerp2D(this IPoint2D start, int x, int y, double percent) { return(start.Clone2D((int)((x - start.X) * percent), (int)((y - start.Y) * percent))); }