public static string PrintGrid(int[,] grid, IEnumerable<Point> path = null, IEnumerable<Point> pawns = null) { string str = string.Empty; HashSet<Point> pathPoints = new HashSet<Point>(path); for (int j = 0; j < grid.GetLength(0); j++) { for (int i = 0; i < grid.GetLength(1); i++) { Point point = new Point(i, j); if (pawns != null && pawns.Contains(point)) { str += "╬"; } else if (path != null && pathPoints.Contains(point)) { str += "┼"; } else { switch (grid[j, i]) { case Board.WALL_TILE: str += "█"; break; case Board.FLOOR_TILE: str += "░"; break; } } } str += "\n"; } return str; }
public Point GetDestination(Point destination, FixedObject destObject, Hero hero) { var cell = Map.PointToCell(destination); var obj = Game.Map.GetObjectFromCell(cell); var largeObjectOuter = obj as LargeObjectOuterAbstract; if(largeObjectOuter == null) return destination; var startingPoint = new Point(cell.X - largeObjectOuter.PlaceInObject.X, cell.Y - largeObjectOuter.PlaceInObject.Y); var innerObject = largeObjectOuter.InnerObject as Wickiup; var totDist = Int32.MaxValue; Point p = null; var heroPos = Map.PointToCell(hero.Position); for (int i = 0; i < (int)innerObject.Size.Width + 2; i++ ) { for (int j = 0; j < (int) innerObject.Size.Height + 2; j++) { if (i > 0 && i < (int) innerObject.Size.Width + 1 && j > 0 && j < (int) innerObject.Size.Height + 1) continue; var curPoint = new Point(i - 1, j - 1); bool isPassable; if (j == 0 || j == (int) innerObject.Size.Height + 1) { isPassable = innerObject.HorizontalBorder[i, j == 0 ? 0 : 1]; } else { isPassable = innerObject.VerticalBorder[j - 1, i == 0 ? 0 : 1]; } if (!isPassable) continue; int totdistX = Math.Abs(heroPos.X - startingPoint.X - curPoint.X); int totdistY = Math.Abs(heroPos.Y - startingPoint.Y - curPoint.Y); var curtotDist = totdistX*totdistX + totdistY*totdistY; if (curtotDist < totDist) { totDist = curtotDist; p = curPoint; } } } var newCenterPoint = Map.CellToPoint(new Point(startingPoint.X + p.X, startingPoint.Y + p.Y)); var x = newCenterPoint.X + Map.CELL_MEASURE / 2 + (p.X > -1 && p.X < innerObject.Size.Width ? 0 : p.X == -1 ? Map.CELL_MEASURE / 2 + 2 : -Map.CELL_MEASURE / 2 - 2); var y = newCenterPoint.Y + Map.CELL_MEASURE / 2 + (p.Y > -1 && p.Y < innerObject.Size.Height ? 0 : p.Y == -1 ? Map.CELL_MEASURE / 2 + 2 : -Map.CELL_MEASURE / 2 - 2); innerPoint = startingPoint; return new Point(x, y); }
public static Point GetInsidePoint(IReadOnlyList<Point> points, Box boundingBox) { var y = (boundingBox.MinY + boundingBox.MaxY) / 2; var xIntersections = new List<double>(); var point1 = points.Last(); foreach (var point2 in points) { if ((y > point1.Y) != (y > point2.Y)) { xIntersections.Add((y - point2.Y) * (point1.X - point2.X) / (point1.Y - point2.Y) + point2.X); } point1 = point2; } xIntersections.Sort(); Debugger.BreakWhen(xIntersections.Count == 0 || xIntersections.Count % 2 != 0); var x = (boundingBox.MinX + boundingBox.MaxX) / 2; var maxDelta = double.NegativeInfinity; for (var i = 0; i < xIntersections.Count - 1; i += 2) { var delta = Math.Abs(xIntersections[i] - xIntersections[i + 1]); if (delta > maxDelta) { x = (xIntersections[i] + xIntersections[i + 1]) / 2; maxDelta = delta; } } var point = new Point(x, y); #if DEBUG Debugger.BreakWhen(!PointInPolygonTest.Contains(points, point)); #endif return point; }
// p1: đối thủ // p2: private Point TimKiemNuocDi(int p1, int p2) { Point oCoResult = new Point(); long DiemMax = 0; for (int i = 0; i < cell_quantity; i++) { for (int j = 0; j < cell_quantity; j++) { if (matrix[i, j] == 0) { long DiemTanCong = DiemTanCong_DuyetDoc(i, j, p1, p2) + DiemTanCong_DuyetNgang(i, j, p1, p2) + DiemTanCong_DuyetCheoNguoc(i, j, p1, p2) + DiemTanCong_DuyetCheoXuoi(i, j, p1, p2); long DiemPhongNgu = DiemPhongNgu_DuyetDoc(i, j, p1, p2) + DiemPhongNgu_DuyetNgang(i, j, p1, p2) + DiemPhongNgu_DuyetCheoNguoc(i, j, p1, p2) + DiemPhongNgu_DuyetCheoXuoi(i, j, p1, p2); long DiemTam = DiemTanCong > DiemPhongNgu ? DiemTanCong : DiemPhongNgu; if (DiemMax < DiemTam) { DiemMax = DiemTam; oCoResult = new Point(i, j); } } } } return oCoResult; }
/// <summary> /// Blocking unary call example. Calls GetFeature and prints the response. /// </summary> public void GetFeature(int lat, int lon) { try { Log("*** GetFeature: lat={0} lon={1}", lat, lon); Point request = new Point { Latitude = lat, Longitude = lon }; Feature feature = client.GetFeature(request); if (feature.Exists()) { Log("Found feature called \"{0}\" at {1}, {2}", feature.Name, feature.Location.GetLatitude(), feature.Location.GetLongitude()); } else { Log("Found no feature at {0}, {1}", feature.Location.GetLatitude(), feature.Location.GetLongitude()); } } catch (RpcException e) { Log("RPC failed " + e); throw; } }
public void AddMap(RobotMap map, Point offset) { foreach (var item in map.Map) { Map.Add(item.Key + offset, item.Value); } }
public RectangleImpl(Point lowerLeft, Point upperRight) { this.minX = lowerLeft.GetX(); this.maxX = upperRight.GetX(); this.minY = lowerLeft.GetY(); this.maxY = upperRight.GetY(); }
public IList<Point> Filter(IList<Point> points) { IList<Point> result = new List<Point>(); if (points.Count == 0) { return result; } var point = new Point(points.First()); result.Add(point); foreach (var currentSourcePoint in points.Skip(1)) { if (!this.DistanceIsTooSmall(currentSourcePoint, point)) { point = new Point(currentSourcePoint); result.Add(point); } } if (this.checkBoundary && result.Count > 1) { CheckFirstAndLastPoint(result); } return result; }
public void TestDistance() { Point p1 = new Point(-2, -3); Point p2 = new Point(-4, 4); double distance = Trigonometry.Distance(p1, p2); Assert.AreEqual(7.28, distance, 0.01); }
public Vertex(Point p) { Self = p; Num = Low = 0; Visited = false; Parent = null; }
public Pathfinding(Map ma, Point m, Point t, int r) { map = ma; me = m; target = t; range = r; }
public Point ToPixelSpace(Point quadraticPos) { var pixelPos = new Point( quadraticToPixelScale.Width * quadraticPos.X + quadraticToPixelOffset.X, quadraticToPixelScale.Height * quadraticPos.Y + quadraticToPixelOffset.Y); return new Point((float)Math.Round(pixelPos.X, 2), (float)Math.Round(pixelPos.Y, 2)); }
public override void SubmitForm(Form form) { base.SubmitForm(form); BlockWidth = (int)form.Datas["BlockWidth"]; BlockHeight = (int)form.Datas["BlockHeight"]; BlockCenter = (Point)form.Datas["BlockCenter"]; }
public string[] PrintMap(int xMin, int yMin, int width, int heigth, Point robotPosition) { var robotX = robotPosition.X - xMin; var robotY = robotPosition.Y - yMin; var result = new string[heigth]; for (int y = 0; y < heigth; y++) { var ch = new char[width]; for (int x = 0; x < width; x++) { var p = new Point(xMin + x, yMin + y); if(robotX == x && robotY == y) { ch[x] = '&'; } else if (Map.ContainsKey(p)) { ch[x] = (char)Map[p]; } else ch[x] = ' '; } result[y] = new string(ch); } Array.Reverse(result); return result; }
public Point GetPointAtFractionLength(double t, out Point tangent) { // Calculate point on curve. double x = (1 - t) * (1 - t) * (1 - t) * Point0.X + 3 * t * (1 - t) * (1 - t) * Point1.X + 3 * t * t * (1 - t) * Point2.X + t * t * t * Point3.X; double y = (1 - t) * (1 - t) * (1 - t) * Point0.Y + 3 * t * (1 - t) * (1 - t) * Point1.Y + 3 * t * t * (1 - t) * Point2.Y + t * t * t * Point3.Y; Point point = new Point(x, y); // Calculate tangent to curve. x = 3 * (1 - t) * (1 - t) * (Point1.X - Point0.X) + 6 * t * (1 - t) * (Point2.X - Point1.X) + 3 * t * t * (Point3.X - Point2.X); y = 3 * (1 - t) * (1 - t) * (Point1.Y - Point0.Y) + 6 * t * (1 - t) * (Point2.Y - Point1.Y) + 3 * t * t * (Point3.Y - Point2.Y); tangent = new Point(x, y); return point; }
public void Func1() { Point a = new Point(10, 10); Point b = a; a.x = 100; System.Console.WriteLine(b.x); }
public void DrawLine(Pen pen, Point p1, Point p2) { using (var paint = CreatePaint(pen, new Size(Math.Abs(p2.X - p1.X), Math.Abs(p2.Y - p1.Y)))) { Canvas.DrawLine((float)p1.X, (float)p1.Y, (float)p2.X, (float)p2.Y, paint.Paint); } }
private static System.String _GetGeoCoordinateString(System.Point GeoLocation) { var Longitude = System.Windows.Forms.Map.GetLongitudeCoordinatesFromLongitudeLocation(GeoLocation.X); var Latitude = System.Windows.Forms.Map.GetLongitudeCoordinatesFromLongitudeLocation(GeoLocation.Y); return(Latitude.GetTruncatedAsInt32() + "° " + System.Math.Abs(Latitude.GetFraction() * 600000.0).GetTruncatedAsInt32() + "’ " + ((Latitude > 0) ? ("N") : ("S")) + ", " + Longitude.GetTruncatedAsInt32() + "° " + System.Math.Abs(Longitude.GetFraction() * 600000.0).GetTruncatedAsInt32() + "’ " + ((Longitude > 0) ? ("O") : ("W"))); }
public ScSign(string text, TSPlayer registrar, Point point) { _point = point; cooldown = 0; _cooldownGroup = string.Empty; RegisterCommands(text, registrar); }
static void Main(string[] args) { Point p1 = new Point(); p1.x = 1; p1.y = 3; p1.sym = '*'; p1.Draw(); /*int x1 = 1; int y1 = 3; char sym1 = '*'; Draw(x1, x1, sym1); */ Point p2 = new Point(); p2.x =4; p2.y = 5; p2.sym = '#'; p2.Draw(); /* int x2 = 4; int y2 = 5; char sym2 = '#'; Draw(x2, y2, sym2); */ Console.ReadLine(); }
public VoronoiRegion(Vertex generator) { this.id = generator.id; this.generator = generator; this.vertices = new List<Point>(); this.bounded = true; }
internal static void Solve_Part2() { Console.WriteLine("Solving Day 01, Part 2..."); var directions = System.IO.File.ReadAllText("01.txt").Split(','); var pt = new Point(); var hist = new List<string>(); foreach (var direction in directions) { if (string.IsNullOrWhiteSpace(direction)) continue; var beenThere = pt.Walk( direction.Trim().Substring(0, 1), int.Parse(direction.Trim().Substring(1)), true); if (beenThere) break; } // wrong: // 297 (high) // correct: // 163 return; }
public override void NowPrimaried(object request) { TargettingKeystrokeRequest targettingRequest = (TargettingKeystrokeRequest)request; m_targetablePoints = targettingRequest.TargetablePoints; m_selectionDelegate = targettingRequest.SelectionDelegate; if (m_selectionDelegate == null) throw new ArgumentNullException("Selection delegate for targetting must not be null"); m_alternateSelectionKey = targettingRequest.AlternateSelectionKey; m_targettingType = targettingRequest.TargettingType; SelectionPoint = SetTargettingInitialSpot(m_engine); EnablePlayerTargeting enableRequest = new EnablePlayerTargeting(true, m_targetablePoints); if (targettingRequest.HaloDelegate != null) enableRequest.HaloDelegate = x => targettingRequest.HaloDelegate(x); m_gameInstance.SendPaintersRequest(enableRequest); m_gameInstance.SendPaintersRequest(new EnableMapCursor(true, SelectionPoint)); // If we have no targetable points, just exit now if (m_targetablePoints.Count == 0) Escape(); m_gameInstance.UpdatePainters(); }
internal static void Solve_Part1() { Console.WriteLine("Solving Day 01, Part 1..."); var directions = System.IO.File.ReadAllText("01.txt").Split(','); var pt = new Point(); foreach (var direction in directions) { if (string.IsNullOrWhiteSpace(direction)) continue; pt.Walk( direction.Trim().Substring(0, 1), int.Parse(direction.Trim().Substring(1)), false); } Console.WriteLine($"You are at {pt}; which is {Math.Abs(pt.X) + Math.Abs(pt.Y)} blocks away..."); // correct: // 279 return; }
private void drawLine(Point p1, Point p2, ViewBase view) { TSD.Line newLine = new TSD.Line(view, p1, p2); LineTypeAttributes lineParams = new LineTypeAttributes(LineTypes.SolidLine, DrawingColors.Black); newLine.Attributes.Line = lineParams; newLine.Insert(); }
public Figure(Point p1, Point p2, Point p3) { this.p1 = new Point(p1.X, p1.Y, p1.Name); this.p2 = new Point(p2.X, p2.Y, p3.Name); this.p3 = new Point(p3.X, p3.Y, p3.Name); name = "Triangle"; }
public Normal ComputeVerticeNormal(int vInd, ref Point[] meshVertices) { Point v_0, v_1, v_2; switch (vInd) { case 0: v_0 = meshVertices[v0]; v_1 = meshVertices[v1]; v_2 = meshVertices[v2]; break; case 1: v_0 = meshVertices[v1]; v_1 = meshVertices[v0]; v_2 = meshVertices[v2]; break; case 2: v_0 = meshVertices[v2]; v_1 = meshVertices[v1]; v_2 = meshVertices[v0]; break; default: throw new ArgumentException(); } var Normal = (Normal)((v_1 - v_0) ^ (v_2 - v_0)).Normalize(); //var Normal = (Normal)((v_0 - v_1) ^ (v_0 - v_2)).Normalize(); return Normal; }
public void RTreeQuery_PointIntersectionTest() { for (int seed = 0; seed < 1; ++seed) { int n = 100000; var points = new Point[n]; var rand = new Random(seed); double scale = 1000; for (int i = 0; i < n; ++i) { points[i] = new Point(rand.NextDouble() * scale, rand.NextDouble() * scale); } var bsptree = new RTree<Point>( from p in points select new KeyValuePair<Rectangle, Point>(new Rectangle(p), p)); Assert.AreEqual(bsptree.GetAllLeaves().Count(), n); Assert.AreEqual(bsptree.GetAllIntersecting(new Rectangle(-2, -2, -1, -1)).Count(), 0); Assert.AreEqual(bsptree.GetAllIntersecting(new Rectangle(0, 0, scale, scale)).Count(), n); int intersecting = 0; for (int i = 0; i < 10000; ++i) { double s = scale / 100; var query = new Rectangle(rand.NextDouble() * s, rand.NextDouble() * s, rand.NextDouble() * s, rand.NextDouble() * s); if (bsptree.IsIntersecting(query)) { ++intersecting; } } System.Console.WriteLine(intersecting); } }
public static Point ConvertDirectionToDestinationPoint(Point initial, Direction direction) { Point destPoint; switch (direction) { case Direction.North: destPoint = new Point(initial.X, initial.Y - 1); break; case Direction.South: destPoint = new Point(initial.X, initial.Y + 1); break; case Direction.West: destPoint = new Point(initial.X - 1, initial.Y); break; case Direction.East: destPoint = new Point(initial.X + 1, initial.Y); break; case Direction.Northeast: destPoint = new Point(initial.X + 1, initial.Y - 1); break; case Direction.Northwest: destPoint = new Point(initial.X - 1, initial.Y - 1); break; case Direction.Southeast: destPoint = new Point(initial.X + 1, initial.Y + 1); break; case Direction.Southwest: destPoint = new Point(initial.X - 1, initial.Y + 1); break; default: throw new ArgumentException("ConvertDirectionToDestinationPoint - Invalid Direction"); } return destPoint; }
public Point GetNextPoint() { Point head = pList.Last(); Point nextPoint = new Point(head); nextPoint.Move(1, direction); return nextPoint; }
public void RunOnce(IRenderGDI aPort) { int i; int cxClient = fSize.cx; int cyClient = fSize.cy; Point[] points = new Point[fNumSegments]; aPort.SaveState(); aPort.SetDefaultPenColor(RGBColor.Red); aPort.MoveTo(0, cyClient / 2); aPort.LineTo(cxClient, cyClient / 2); aPort.SetDefaultPenColor(RGBColor.Black); for (i = 0; i < fNumSegments; i++) { points[i].x = i * cxClient / fNumSegments; points[i].y = (int)(((double)cyClient/2.0f)*(1.0f-Math.Sin(Math.PI*2.0f*(double)i/(double)fNumSegments))); } aPort.PolyLine(points); aPort.RestoreState(); }
private void _UpdateCoordinatesLabel(System.Point GeoLocation) { _CoordinatesLabel.Text = _GetGeoCoordinateString(GeoLocation); }