public void AddPoint(Canvas canvas, Point location, int pointIdx = -1) { Ellipse dot = new Ellipse { Stroke = new SolidColorBrush(Colors.Black), StrokeThickness = 1, Height = DotSize, Width = DotSize, Fill = new SolidColorBrush(Colors.Yellow), Margin = new Thickness(location.X - DotSize / 2, location.Y - DotSize / 2, 0, 0) }; if (pointIdx == -1) { Corners.Add(dot); Polygon.Points.Add(location); } else { Corners.Insert(pointIdx, dot); Polygon.Points.Insert(pointIdx, location); } canvas.Children.Add(dot); DeselectEdge(); }
public void Add(Point item) { if (item == null) { throw new NullReferenceException("Cannot add a corner which is null to a region"); } if (Count == 0 || item != Corners[0]) { Corners.Add(item); } }
public void ClassifyEdge() { var compatiblity = new List <int>(); foreach (var tile in _tiles) { var tilesThatCanBeAdjacent = _tiles.Where(t => t.Id != tile.Id && tile.CouldBeAdjacentOf(t)).ToList(); var emptyBorder = 4 - tilesThatCanBeAdjacent.Count; if (Width == 1 || Height == 1) { if (emptyBorder == 3) { Corners.Add(tile); } else { if (emptyBorder == 2) { Borders.Add(tile); } else { if (Width == 1 && Height == 1) { Corners.Add(tile); } } } } else { if (emptyBorder == 2) { Corners.Add(tile); tile.MarkAsCorner(tilesThatCanBeAdjacent); } else { if (emptyBorder == 1) { Borders.Add(tile); tile.MarkAsBorder(tilesThatCanBeAdjacent); } else { tile.MarkAsInsidePiece(tilesThatCanBeAdjacent); } } } } }
//--------------------------------------------------------------------------- private void FindCorners(List <Room> rooms, List <Corridor> corridors) { foreach (Room room in rooms) { Corners.Add(room.TopLeft()); Corners.Add(room.TopRight()); Corners.Add(room.BottomLeft()); Corners.Add(room.BottomRight()); } foreach (Corridor corridor in corridors) { Corners.AddRange(corridor.Corners); } }
public void AddCornerIfAbsent(Vector2 corner) { //due to possible floating point undeterminism same corner might be //calculated 2 times differently, it's safest to check similarity rather than simply //call Contains() or something for (int i = 0; i < Corners.Count; i++) { if (Corners[i].Similar(corner)) { return; } } Corners.Add(corner); }
//--------------------------------------------------------------------------- public void AddCorners() { foreach (CorridorSegment segment in Segments) { Corners.Add(new Corner(new Point(segment.End.X - 2, segment.End.Y - 2), new Vector2(0.0f, -5.0f))); Corners.Add(new Corner(new Point(segment.End.X - 2, segment.Start.Y + 3), new Vector2(0.0f, 5.0f))); Corners.Add(new Corner(new Point(segment.Start.X + 3, segment.End.Y - 2), new Vector2(0.0f, -5.0f))); Corners.Add(new Corner(new Point(segment.Start.X + 3, segment.Start.Y + 3), new Vector2(0.0f, 5.0f))); Corners.Add(new Corner(new Point(segment.End.X - 2, segment.End.Y - 2), new Vector2(0.0f, 5.0f))); Corners.Add(new Corner(new Point(segment.End.X - 2, segment.Start.Y + 3), new Vector2(0.0f, -5.0f))); Corners.Add(new Corner(new Point(segment.Start.X + 3, segment.End.Y - 2), Vector2.Zero)); Corners.Add(new Corner(new Point(segment.Start.X + 3, segment.Start.Y + 3), Vector2.Zero)); } }
private void FindPotentialCorners() { var groupSize = Vertices.Count / NumberOfCorners; for (var i = 0; i < NumberOfCorners; i++) { var thisGroup = i; var thisOuterGroup = thisGroup - 1 < 0 ? NumberOfCorners - 1 : thisGroup - 1; var nextGroup = thisGroup + 1 >= NumberOfCorners ? 0 : thisGroup + 1; var nextOuterGroup = nextGroup + 1 >= NumberOfCorners ? 0 : nextGroup + 1; Corners.Add(new Exit(i, Vertices[thisOuterGroup * groupSize + 6], Vertices[thisOuterGroup * groupSize + 5], Vertices[thisGroup * groupSize + 5], Vertices[thisGroup * groupSize + 6], Vertices[nextGroup * groupSize + 6], Vertices[nextGroup * groupSize + 5], Vertices[nextOuterGroup * groupSize + 5], Vertices[nextOuterGroup * groupSize + 6])); } }
/// <summary> /// Adds a corner to the corner point list /// </summary> /// <param name="p">the new corner</param> public void addCorner(AGraphMLCorner p) { Corners.Add(p); }
// Takes a List containing another List per face with the vertex indexes belonging to that face private bool CreateFaces(List <List <int> > faceIndexes) { Dictionary <string, int> edgeCount = new Dictionary <string, int>(); Dictionary <string, MeshHalfEdge> existingHalfEdges = new Dictionary <string, MeshHalfEdge>(); Dictionary <MeshHalfEdge, bool> hasTwinHalfEdge = new Dictionary <MeshHalfEdge, bool>(); // Create the faces, edges and half-edges, non-boundary loops and link references when possible; foreach (List <int> indexes in faceIndexes) { MeshFace f = new MeshFace(); Faces.Add(f); List <MeshHalfEdge> tempHEdges = new List <MeshHalfEdge>(indexes.Count); // Create empty half-edges for (int i = 0; i < indexes.Count; i++) { MeshHalfEdge h = new MeshHalfEdge(); tempHEdges.Add(h); } // Fill out each half edge for (int i = 0; i < indexes.Count; i++) { // Edge goes from v0 to v1 int v0 = indexes[i]; int v1 = indexes[(i + 1) % indexes.Count]; MeshHalfEdge h = tempHEdges[i]; // Set previous and next h.Next = tempHEdges[(i + 1) % indexes.Count]; h.Prev = tempHEdges[(i + indexes.Count - 1) % indexes.Count]; h.OnBoundary = false; hasTwinHalfEdge.Add(h, false); // Set half-edge & vertex mutually h.Vertex = Vertices[v0]; Vertices[v0].HalfEdge = h; // Set half-edge face & vice versa h.Face = f; f.HalfEdge = h; // Reverse v0 and v1 if v0 > v1 if (v0 > v1) { int temp = v0; v0 = v1; v1 = temp; } string key = v0 + " " + v1; if (existingHalfEdges.ContainsKey(key)) { // If this half-edge key already exists, it is the twin of this current half-edge MeshHalfEdge twin = existingHalfEdges[key]; h.Twin = twin; twin.Twin = h; h.Edge = twin.Edge; hasTwinHalfEdge[h] = true; hasTwinHalfEdge[twin] = true; edgeCount[key]++; } else { // Create an edge and set its half-edge MeshEdge e = new MeshEdge(); Edges.Add(e); h.Edge = e; e.HalfEdge = h; // Record the newly created half-edge existingHalfEdges.Add(key, h); edgeCount.Add(key, 1); } } HalfEdges.AddRange(tempHEdges); } // Create boundary edges for (int i = 0; i < HalfEdges.Count; i++) { MeshHalfEdge h = HalfEdges[i]; if (!hasTwinHalfEdge[h]) { MeshFace f = new MeshFace(); Boundaries.Add(f); List <MeshHalfEdge> boundaryCycle = new List <MeshHalfEdge>(); MeshHalfEdge hE = h; do { MeshHalfEdge bH = new MeshHalfEdge(); HalfEdges.Add(bH); boundaryCycle.Add(bH); MeshHalfEdge nextHE = hE.Next; while (hasTwinHalfEdge[nextHE]) { nextHE = nextHE.Twin.Next; } bH.Vertex = nextHE.Vertex; bH.Edge = hE.Edge; bH.OnBoundary = true; bH.Face = f; f.HalfEdge = bH; bH.Twin = hE; hE.Twin = bH; hE = nextHE; }while (hE != h); int n = boundaryCycle.Count; for (int j = 0; j < n; j++) { boundaryCycle[j].Next = boundaryCycle[(j + n - 1) % n]; boundaryCycle[j].Prev = boundaryCycle[(j + 1) % n]; hasTwinHalfEdge[boundaryCycle[j]] = true; hasTwinHalfEdge[boundaryCycle[j].Twin] = true; } } if (!h.OnBoundary) { MeshCorner corner = new MeshCorner { HalfEdge = h, }; h.Corner = corner; Corners.Add(corner); } } // Check mesh for common errors if (HasIsolatedFaces() || HasIsolatedVertices() || HasNonManifoldEdges()) { return(false); } // Index elements IndexElements(); return(true); }
public override ITurnAction Update(IBot ownBot, IBattlefield battlefield) { if (!Corners.Any()) { Corners.Add(new Point(10, 10)); Corners.Add(new Point(10, battlefield.Height - 10)); Corners.Add(new Point(battlefield.Width - 10, battlefield.Height - 10)); Corners.Add(new Point(battlefield.Width - 10, 10)); } if (ownBot.EquippedWeapon.Ammunition.Remaining == 0) { var weapon = battlefield.Weapons.OrderBy(a => a.DistanceTo(ownBot)).FirstOrDefault(); if (weapon != null) { return(ownBot.DistanceTo(weapon) > ownBot.Radius ? TurnAction.MoveTowards(weapon) : TurnAction.PickUpWeapon()); } } if (ownBot.HitPoints.Percent < 50) { if (ownBot.HasResource) { return(TurnAction.DropDownResource()); } return(TurnAction.MoveTowards(battlefield.Hospitals.First())); } if (ownBot.HasResource) { return(ownBot.DistanceTo(ownBot.Home) > ownBot.Radius ? TurnAction.MoveTowards(ownBot.Home) : TurnAction.DropDownResource()); } var target = battlefield.Bots.Except(new[] { ownBot }) .Where(b => b.HasResource) .OrderBy(b => b.DistanceTo(ownBot)) .FirstOrDefault(); if (target != null) { return(ownBot.DistanceTo(target) < ownBot.EquippedWeapon.MaxRange ? TurnAction.ShootAt(target) : TurnAction.MoveTowards(target)); } if (myAttacker != null) { if (ownBot.HasResource) { return(TurnAction.DropDownResource()); } if (battlefield.Bots.Contains(myAttacker)) { return(ownBot.DistanceTo(myAttacker) < ownBot.EquippedWeapon.MaxRange ? TurnAction.ShootAt(myAttacker) : TurnAction.MoveTowards(myAttacker)); } myAttacker = null; } if (battlefield.Resources.Any()) { var resource = battlefield.Resources.OrderBy(r => r.DistanceTo(ownBot)).First(); if (ownBot.DistanceTo(resource) < ownBot.Radius) { return(TurnAction.PickUpResource()); } return(TurnAction.MoveTowards(resource.Position)); } return(TurnAction.Idle); }
public void RunEdgeDetection(EdgeDetectionOptions options) { if (HasRunEdgeDetection) { return; } using (Bitmap newBitmap = LoadBitmap()) { Rectangle rect = new Rectangle(0, 0, newBitmap.Width, newBitmap.Height); using (UnmanagedImage image = new UnmanagedImage(newBitmap.LockBits(rect, ImageLockMode.ReadWrite, newBitmap.PixelFormat))) { using (UnmanagedImage grayImage = UnmanagedImage.Create(image.Width, image.Height, PixelFormat.Format8bppIndexed)) { Grayscale.CommonAlgorithms.BT709.Apply(image, grayImage); Threshold threshold = new Threshold(options.Threshold); using (UnmanagedImage edgesImage = EDGE_DETECTOR.Apply(grayImage)) { Threshold thresholdFilter = new Threshold(options.Threshold); thresholdFilter.ApplyInPlace(edgesImage); if (options.ShowEdgesImage) { ImageForm.ShowImage("Enhanced Edges Image", edgesImage); } BlobCounter blobCounter = new BlobCounter(); blobCounter.MinHeight = MINIMUM_BLOB_SIZE; blobCounter.MinWidth = MINIMUM_BLOB_SIZE; blobCounter.FilterBlobs = true; blobCounter.ObjectsOrder = ObjectsOrder.Size; blobCounter.ProcessImage(edgesImage); Blob[] blobs = blobCounter.GetObjectsInformation(); Corners.Clear(); foreach (Blob blob in blobs) { List <IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blob); List <IntPoint> corners = null; if (SHAPE_CHECKER.IsQuadrilateral(edgePoints, out corners)) { List <IntPoint> leftEdgePoints, rightEdgePoints; blobCounter.GetBlobsLeftAndRightEdges(blob, out leftEdgePoints, out rightEdgePoints); Corners.Add(corners); if (options.ShowBlobImages) { QuadrilateralTransformation quadTransformation = new QuadrilateralTransformation(corners, 200, 200); using (UnmanagedImage quadImage = quadTransformation.Apply(image)) { ImageForm.ShowImage("Quad Image", quadImage); } } } } } } } } }
/// <summary> /// Adds the specified point as corner of the figure. /// </summary> /// <param name="pt">The point to add.</param> public void AddCorner(FigurePoint pt) { Corners.Add(pt); RefillPathWithCorners(); }
public void CanvasMouseDown(object sender, MouseButtonEventArgs e) { MousePressed = true; if (Corners == null) { Corners = new List <Corner>(); } if (Walls == null) { Walls = new List <Wall>(); } var mousePosition = e.MouseDevice.GetPosition(ShapeGen.Can); var tempPoint = new Corner(mousePosition.X, mousePosition.Y); if (HoveredCorner == null) { Corners.ForEach(x => { if (x.RepEllipse.IsMouseDirectlyOver) { HoveredCorner = x; } }); } if (HoveredCorner == null) { var cor = new Corner(mousePosition.X, mousePosition.Y) { FillBrush = Brushes.Black, Height = 10, Width = 10, StrokeBrush = Brushes.White, StrokeThickness = 1 }; Corners.ForEach(x => { if (cor.DistanceFrom(x) <= SnapTolerance) { cor = x; } }); if (Corners.Count(x => x.X == cor.X && x.Y == cor.Y) == 0) { Corners.Add(cor); } cor.DrawPoint(); if (AddingWall && LastNode != null) { var wall = new Wall(LastNode, cor); Walls.Add(wall); wall.StrokeBrush = Brushes.Black; wall.DrawLine(); } LastNode = cor; LastMousePosition = mousePosition; AddingWall = true; } }