/// <summary> /// Sorts a list of Dynamo Curves. /// </summary> /// <param name="curves">THe list of Curves.</param> /// <returns></returns> private IList <Curve> SortCurves(IList <Curve> curves) { int n = curves.Count; for (int i = 0; i < n; i++) { Curve c = curves[i]; Point endPoint = c.EndPoint; bool found = i + 1 >= n; Point p = null; for (int j = i + 1; j < n; j++) { p = curves[j].StartPoint; if (p.DistanceTo(endPoint) < 0.00001) { if (i + 1 != j) { Curve temp = curves[i + 1]; curves[i + 1] = curves[j]; curves[j] = temp; } found = true; break; } p = curves[j].EndPoint; if (p.DistanceTo(endPoint) < 0.00001) { if (i + 1 == j) { curves[i + 1] = curves[j].Reverse(); } else { Curve temp = curves[i + 1]; curves[i + 1] = curves[j].Reverse(); curves[j] = temp; } found = true; break; } } } return(curves); }
public void DistanceTo() { var zero = new Point(); var p = new Point(3, 4); Assert.AreEqual(5, zero.DistanceTo(p)); Assert.AreEqual(0, zero.DistanceTo(zero)); }
public static bool IsBlackListedZone(Point position, string cId = "") { try { if (string.IsNullOrEmpty(cId)) { cId = Usefuls.ContinentNameMpq; } foreach (var zone in DangerousZones) { if (zone.ContinentId != cId) { continue; } if (position.DistanceTo(zone.Position) <= zone.Radius && position.DistanceTo(ObjectManager.Me.Position) > 6f) { return(true); } } return(false); } catch (Exception e) { Logging.WriteError("IsBlackListedZone(Point position): " + e); return(false); } }
public void Distance() { var zero = new Point(); var p = new Point(3, 4); Assert.AreEqual(5, zero.DistanceTo(p)); Assert.AreEqual(0, zero.DistanceTo(zero)); }
/// <summary> /// Gets the distance to the specified rectangle edge from a <see cref="Point"/> perpendicular to the middle of the specified rectangle edge. /// </summary> /// <param name="perpendicularPoint">A <see cref="Point"/> perpendicular to the <paramref name="rectangleEdge"/>.</param> /// <param name="rectangleEdge"> /// A <see cref="RectangleSide"/> value describing the edge of the rectangle perpendicular to the <paramref name="perpendicularPoint"/>. /// </param> /// <returns>The distance from the <paramref name="perpendicularPoint"/> to the <paramref name="rectangleEdge"/>.</returns> public double DistanceFromPerpendicularPointToEdgeMidPoint(Point perpendicularPoint, RectangleSide rectangleEdge) { Line edge = GetEdge(rectangleEdge); double distance = edge.MidPoint.DistanceTo(perpendicularPoint); Point center = Center; return((center.DistanceTo(edge.MidPoint) > center.DistanceTo(perpendicularPoint)) ? -distance : distance); }
private Point RecursiveNearestNeighborSearch(Point point, DoublyLinkedNode <Point> root) { if (root.Parent != null && point.DistanceTo(root.Parent.Item) < point.DistanceTo(root.Item)) { return(root.Parent.Item); } return(root.Dimension == Dimension.X ? RecursiveNearestNeighborSearch(point, point.X <= root.Item.X ? root.Left : root.Right) : RecursiveNearestNeighborSearch(point, point.Y <= root.Item.Y ? root.Left : root.Right)); }
private protected override double GetDistance(Point P) { var P1 = Point1.ToPoint(Chart); var P2 = Point2.ToPoint(Chart); double A = P1.DistanceTo(P2); double B = P.DistanceTo(P2); double C = P.DistanceTo(P1); double pp = (A + B + C) / 2; return((2 * Math.Sqrt(pp * (pp - A) * (pp - B) * (pp - C))) / A); }
public static void Main(string[] args) { var pt1 = new Point(0, 0); var pt2 = new Point(3, 4); var d = pt1.DistanceTo(pt2); var circ = new Circle(3, 4, 5); var d2 = pt1.DistanceTo(circ); var d3 = circ.DistanceTo(pt2); }
public void DistanceToIntsTest() { Point src = new Point(1, 1); Assert.AreEqual(3.6056, src.DistanceTo(3, 4), 0.0001); src.SetCoordinates(-2, 4); Assert.AreEqual(17.2046, src.DistanceTo(8, -10), 0.0001); src.SetCoordinates(0, 0); Assert.AreEqual(8.6023, src.DistanceTo(-5, -7), 0.0001); Assert.AreEqual(0, src.DistanceTo(0, 0), 0.0001); src.SetCoordinates(-1, -3); Assert.AreEqual(12.3693, src.DistanceTo(2, 9), 0.0001); }
private MazeVisualizerDTO Solve(int[,] matrix, Point startPoint, Point endPoint, int matrixWidth, int matrixHeight) { List <Point> visitedPoints = new List <Point>(); List <Point> solution = new List <Point>(); Dictionary <Point, Point> parentDict = new Dictionary <Point, Point>(); PriorityQueue <double, Point> pQueue = new PriorityQueue <double, Point>(new PriorityQueue_MinComparer()); Point current = startPoint; pQueue.Enqueue(current.DistanceTo(endPoint), current); while (!pQueue.IsEmpty) { current = pQueue.DequeueValue(); if (current.DistanceTo(endPoint) <= 1.0) //exclude destination from solution { solution = ParseSolution(current, parentDict, startPoint); break; } int[] offsets = { 1, 0, 0, -1, -1, 0, 0, 1 }; for (int i = 0; i < offsets.Length; i += 2) { int next_i = current.I + offsets[i]; int next_j = current.J + offsets[i + 1]; Point tempPoint = new Point(next_i, next_j, current.Value + 1); parentDict.TryAdd(tempPoint, current); bool alreadyVisited = false; foreach (Point p in visitedPoints) { if (p.I == tempPoint.I && p.J == tempPoint.J) { alreadyVisited = true; } } if (next_i >= 0 && next_i < matrixHeight && next_j >= 0 && next_j < matrixWidth && matrix[next_i, next_j] != -1 && !alreadyVisited) { double distance = tempPoint.DistanceTo(endPoint); pQueue.Enqueue(distance, tempPoint); visitedPoints.Add(tempPoint); } } } visitedPoints.Sort((p1, p2) => p1.Value.CompareTo(p2.Value)); solution.Sort((p1, p2) => p1.Value.CompareTo(p2.Value)); return(new MazeVisualizerDTO(visitedPoints, solution)); }
public float DistanceToPoint(Point point) { switch (LocateProjection(point)) { case ProjectionLocation.RayA: return(point.DistanceTo(start)); case ProjectionLocation.RayB: return(point.DistanceTo(end)); default: return(line.DistanceToPoint(point)); } }
private Point GetClosestLocation(Point diagonalPoint, HashSet <Point> points) { var min = double.MaxValue; var closestPoint = new Point(); foreach (var point in points) { if (diagonalPoint.DistanceTo(point) < min) { min = diagonalPoint.DistanceTo(point); closestPoint = point; } } return(closestPoint); }
public void DistanceBetweenTwoPointsTest() { var pointA = new Point(3, 5); var pointB = new Point(6, 1); Assert.That(pointA.DistanceTo(pointB), Is.EqualTo(5)); }
///////////////////////////////////////////////////////////// // Use: Returns True if conical thread is expanding. // Works only for tapered threads. ///////////////////////////////////////////////////////////// public static bool IsExpanding( ThreadInfo threadInfo, Face threadedFace) { Point basePoint = threadInfo.ThreadBasePoints[1] as Point; Vector direction = threadInfo.ThreadDirection; Point endPoint = _Tg.CreatePoint( basePoint.X + direction.X, basePoint.Y + direction.Y, basePoint.Z + direction.Z); UnitVector yAxis = direction.AsUnitVector(); UnitVector xAxis = Toolkit.GetOrthoVector(yAxis); Line l1 = Toolkit.GetFaceSideDirection(threadedFace, xAxis); Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector()); Line l3 = _Tg.CreateLine(endPoint, xAxis.AsVector()); Point p1 = l1.IntersectWithCurve(l2, 0.0001)[1] as Point; Point p2 = l1.IntersectWithCurve(l3, 0.0001)[1] as Point; double dBase = p1.DistanceTo(basePoint); double dEnd = p2.DistanceTo(endPoint); return(dBase < dEnd); }
/// <summary>Action to call when the mouse moves on the correct canvas.</summary> public void MouseMove(MouseEventArgs e, Canvas boundingBoxCanvas) { if (!isDrawing) { return; } var position = e.GetPosition(boundingBoxCanvas); if (boundingBox == null && startPoint.DistanceTo(position) > threshold) { boundingBox = new Border(); boundingBox.BorderBrush = Brushes.White; boundingBox.BorderThickness = new Thickness(3); boundingBox.Width = Math.Max(3, position.X - startPoint.X); boundingBox.Height = Math.Max(3, position.Y - startPoint.Y); Canvas.SetLeft(boundingBox, startPoint.X); Canvas.SetTop(boundingBox, startPoint.Y); boundingBoxCanvas.Children.Add(boundingBox); } else if (boundingBox != null) { boundingBox.Width = Math.Max(3, position.X - startPoint.X); boundingBox.Height = Math.Max(3, position.Y - startPoint.Y); } }
public void DistanceToTest() { Point punctA = new Point(1, 3); Point punctB = new Point(2, 4); Assert.AreEqual(punctA.DistanceTo(punctB), 1, 4142135623731); }
public void DistanceTo(double x1, double y1, double x2, double y2, double expected) { var pt1 = new Point(x1, y1); var pt2 = new Point(x2, y2); pt1.DistanceTo(pt2).Should().BeApproximately(expected, 0.0001); }
private void LoopRecordWay() { try { const float distanceZSeparator = 5.0f; _loopRecordPoint = true; _profile.Points.Add(ObjectManager.Me.Position); RefreshForm(); while (_loopRecordPoint) { Point lastPoint = _profile.Points[_profile.Points.Count - 1]; float disZTemp = lastPoint.DistanceZ(ObjectManager.Me.Position); if ((lastPoint.DistanceTo(ObjectManager.Me.Position) > (double)nSeparatorDistance.Value) || disZTemp >= distanceZSeparator) { _profile.Points.Add(ObjectManager.Me.Position); RefreshForm(); } Application.DoEvents(); Thread.Sleep(50); } } catch (Exception e) { Logging.WriteError("Fisherbot > Bot > ProfileCreator > LoopRecordWay(): " + e); } }
static void Main() { int[] array = { 2, 1, 3 }; // 1. Sorting array with an Extension Method, the method is in Extensions.cs Console.WriteLine(new string('-', 40)); array.Sort(); Console.WriteLine("Sorted array: " + string.Join(", ", array)); // 2. Sorting and Reversing an array with Extension Method, the method is in Extensions.cs Console.WriteLine(new string('-', 40)); array.Sort(true); Console.WriteLine("Sorted and reversed array: " + string.Join(", ", array)); // 3. Reversing an array with an Extension Method, the method is in Extensions.cs Console.WriteLine(new string('-', 40)); array.Reverse(); Console.WriteLine("Reversed Array" + string.Join(", ", array)); // 4. Extending the built in Point class to find distance between two points. Console.WriteLine(new string('-', 40)); Point p1 = new Point(20, 20); Point p2 = new Point(50, 60); // Distance between p1 and p2, saved in a Distance object and printed on the console Distance dist = p1.DistanceTo(p2); }
public void DistanceToPointAtSamePosition() { var point = new Point(0, 0); var target = new Point(0, 0); Assert.AreEqual(point.DistanceTo(target), 0d); }
private void LoopRecordWay() { try { const float distanceZSeparator = 3.0f; int lastRotation = 0; _loopRecordPoint = true; _profile.BattlegrounderZones[_idZone].Points.Add(ObjectManager.Me.Position); RefreshForm(); while (_loopRecordPoint) { Point lastPoint = _profile.BattlegrounderZones[_idZone].Points[ _profile.BattlegrounderZones[_idZone].Points.Count - 1]; float disZTemp = lastPoint.DistanceZ(ObjectManager.Me.Position); if (((lastPoint.DistanceTo(ObjectManager.Me.Position) > (double)DistanceBetweenRecord.Value) && lastRotation != (int)Math.RadianToDegree(ObjectManager.Me.Rotation)) || disZTemp >= distanceZSeparator) { _profile.BattlegrounderZones[_idZone].Points.Add(ObjectManager.Me.Position); lastRotation = (int)Math.RadianToDegree(ObjectManager.Me.Rotation); RefreshForm(); } Application.DoEvents(); Thread.Sleep(50); } } catch (Exception e) { Logging.WriteError("Battlegrounder > Bot > ProfileCreator > LoopRecordWay(): " + e); } }
public void DistanceToTest() { Point p1 = new Point(2, 3); Point p2 = new Point(2, 4); Assert.Equal(1, p1.DistanceTo(p2)); }
public bool Contains(Point p) { var v = CenterPoint.VectorTo(p); var r = RadiusInDirection(v); return(CenterPoint.DistanceTo(p) <= r); }
public void DistanceBetweenTwoPointsOnTheXAxisTest() { var pointA = new Point(0,0); var pointB = new Point(6,0); Assert.That(pointA.DistanceTo(pointB), Is.EqualTo(6)); }
public void DistanceToTest() { Point point1 = new Point(10, 20); Point point2 = new Point(5, 18); Assert.AreEqual((float)Math.Sqrt((5 * 5) + (2 * 2)), point1.DistanceTo(point2)); }
public static double DistanceBetweenPoints(this Surface surface, UV point1, UV point2) { Point A = surface.PointAtParameter(point1.U, point1.V); Point B = surface.PointAtParameter(point2.U, point2.V); return(A.DistanceTo(B)); }
private static Point?GetClosestUnexploredLocation(TerrainMap terrainMap, VisibilityMap visibilityMap, IMovementProfile movementProfile, Point location) { int closestDistance = int.MaxValue; Point?closestLocation = null; // We want to explore rooms before we explore corridors DungeonPrefab currentRoom = terrainMap.GetPrefabAtLocation(location); // If we are in a room then get the closest unseen location in the room foreach ( Point unseenLocation in currentRoom == null ? GetWalkableUnseenLocations(terrainMap, visibilityMap, movementProfile) : GetWalkableUnseenLocationsWithinPrefab(currentRoom, terrainMap, visibilityMap, movementProfile)) { int currentDistance = location.DistanceTo(unseenLocation); if (currentDistance >= closestDistance) { continue; } closestDistance = currentDistance; closestLocation = unseenLocation; } return(closestLocation); }
public static void HandlePlayer(MapleClient c, PacketReader pr) { MapleCharacter chr = c.Account.Character; if (!chr.DisableActions()) { return; } pr.Skip(1); try { int tickCount = pr.ReadInt(); Point position = pr.ReadPoint(); int objectId = pr.ReadInt(); if (position.DistanceTo(chr.Position) >= 50) { c.CheatTracker.AddOffence(AntiCheat.OffenceType.LootFarAwayItem); } bool success = chr.Map.HandlePlayerItemPickup(c, objectId); chr.EnableActions(!success); //Client doesn't need to be notified if it was succesful } catch { chr.EnableActions(); } }
public void TestDistanceTo() { Point a = new Point(1, 2); Point b = new Point(4, 5); a.DistanceTo(b).Should().BeApproximately(3 * Math.Sqrt(2), DoubleComparer.DefaultEpsilon); }
public HUDLine(Point start, Point finish, TColor color) : base(new Rectangle(start, start)) { _start = start; _color = color; _length = start.DistanceTo(finish); _angle = HUDMathUtil.GetRadiansAngleFromTwoPoints(start, finish); }
public void DistanceBetweenPointsTest_Success() { var point1 = new Point(5, 1); var point2 = new Point(10, 5); Assert.That(point1.DistanceTo(point2), Is.EqualTo(6.403).Within(0.001)); Assert.That(point2.DistanceTo(point1), Is.EqualTo(6.403).Within(0.001)); }
public bool IsPointOnLine(Point p) { if (StartPoint.DistanceTo(p) < Constants.Tolerance) { return(true); } var v = p - StartPoint; var angleBetween = Vector.AngleBetween(Direction, v); if (Math.Abs(angleBetween) > Constants.Tolerance) { return(false); } return(v.Length <= Length + Constants.Tolerance); }
static void Main(string[] args) { Point headquarters = new Point() { X = int.Parse(Console.ReadLine()), Y = int.Parse(Console.ReadLine()) }; int distanceToBorder = int.Parse(Console.ReadLine()); // shooting range int numPlanes = int.Parse(Console.ReadLine()); for (int i = 0; i < numPlanes; i++) { Point plane = new Point() { X = int.Parse(Console.ReadLine()), Y = int.Parse(Console.ReadLine())}; double distanceToPlane = headquarters.DistanceTo(plane); if (distanceToPlane <= distanceToBorder) Console.WriteLine("You destroyed a plane at [{0},{1}]", plane.X, plane.Y); } }
public void TestShipLength() { var point1 = new Point('E', 6, false, false); var point2 = new Point('E', 6, false, false); Assert.AreEqual(1, point1.DistanceTo(point2)); point1 = new Point('E', 6, false, false); point2 = new Point('F', 6, false, false); Assert.AreEqual(2, point1.DistanceTo(point2)); point1 = new Point('A', 1, false, false); point2 = new Point('J', 1, false, false); Assert.AreEqual(10, point1.DistanceTo(point2)); point1 = new Point('A', 1, false, false); point2 = new Point('A', 10, false, false); Assert.AreEqual(10, point1.DistanceTo(point2)); }
static void Main() { // Points based on integers Point<int> pti1 = new Point<int>(); Point<int> pti2 = new Point<int>(5, 3); Console.WriteLine(pti1.DistanceTo(pti2)); // Points based on doubles Point<double> ptd1 = new Point<double>(13.5, 15); Point<double> ptd2 = new Point<double>(3.54, 5E-1); Console.WriteLine(ptd2.DistanceTo(ptd1)); // Points based on strings Point<string> pts1 = new Point<string>("34", "27"); Point<string> pts2 = new Point<string>("0", "0"); Console.WriteLine(pts1.DistanceTo(pts2)); }
public Point FindStart(Point hint) { Point found = Point.Empty; //Check all pixels for (int x = 0; x < vinyl.Width; x++) for (int y = 0; y < vinyl.Height; y++) { //Get which point to check Point toCheck = new Point(x, y); //Check if the point should not be ignored and has 1 surrounding point if (!IgnoreColor(GetColor(toCheck)) && SurroundingPoints(toCheck) == 1) //Check if the distance from the new point to the ceanter is greater if (found.IsEmpty || toCheck.DistanceTo(hint) < found.DistanceTo(hint)) found = toCheck; } return found; }
public void InitializePathfindingSearch(RectangleCharacter startPosition) { Point initp = new Point(WM, WM.Character.xPos, WM.Character.yPos); Point aux = new Point(WM, 9999, 9999); float dist = 99999999999; foreach (Point p in WM.Mesh) { float auxd = initp.DistanceTo(p); if (auxd <= dist) { aux = p; dist = auxd; } } Connection c = new Connection(WM, initp, aux); c.categorie = c.SLIDEONPLATFORM; initp.addConnection(c); NodeRecord nri = new NodeRecord(); nri.node = initp; nri.gValue = 0; nri.hValue = 0; nri.fValue = 0; nri.Points = 0; var bestNode = nri; this.StartNode = initp; this.InProgress = true; this.TotalProcessedNodes = 0; this.MaxOpenNodes = 0; this.Open.Initialize(); this.Open.AddToOpen(bestNode); this.Closed.Initialize(); }
bool TryMove(Point start, Point end, double noTouch, out double success) { success = start.DistanceTo(end); bool result = true; Edge other = new Edge(start, end); Point intersection; foreach (Edge edge in edges) if (edge.ComputeIntersection(other, out intersection) && intersection.Between(other.P1, other.P2)) { success = Math.Min(success, start.DistanceTo(intersection) - noTouch); result = false; } if (success < 0) success = 0; return result; }
//------------------------------------------------------------------------------ private void OffsetPoint(int j, ref int k, JoinType jointype, double eps) { sinA = (normals[k].X * normals[j].Y - normals[j].X * normals[k].Y); if (sinA > 1.0) sinA = 1.0; else if (sinA < -1.0) sinA = -1.0; if (sinA * delta < 0) { var p1 = new Point((srcPoly[j].X + normals[k].X * delta), (srcPoly[j].Y + normals[k].Y * delta)); var p2 = new Point((srcPoly[j].X + normals[j].X * delta), (srcPoly[j].Y + normals[j].Y * delta)); destPoly.Add(p1); if (p1.DistanceTo(srcPoly[j]) > eps) destPoly.Add(srcPoly[j]); if (p2.DistanceTo(srcPoly[j]) > eps) destPoly.Add(p2); } else { switch (jointype) { case JoinType.Miter: { var r = 1 + (normals[j].X * normals[k].X + normals[j].Y * normals[k].Y); if (r >= miterLim) DoMiter(j, k, r); else DoSquare(j, k); break; } case JoinType.Square: DoSquare(j, k); break; case JoinType.Round: Do(j, k); break; } } k = j; }
public bool IsFree(Point point) { foreach (Edge edge in edges) if (point.DistanceTo(edge) < Util.Epsilon) return false; return true; }
public double DistanceToPoint(Point destination) { return destination.DistanceTo(TopLeft); }
public void GenerateContext() { this.Context = new GameContext(); this.Context.Teams = Enumerable.Range(0, _players.Length) .Select(teamId => new Team(teamId, _nbrDrones)).ToList(); var random = new Random(); var minZoneX = Zone.Radius; var maxZoneX = GameContext.FieldWidth - 2 * Zone.Radius; var minZoneY = Zone.Radius; var maxZoneY = GameContext.FieldHeight - 2 * Zone.Radius; int minDistanceBetweenZones = 300; // zones this.Context.Zones = new List<Zone>(); for(int i = 0; i < _nbrZones; i++) { Point zoneCenter; do { zoneCenter = new Point(random.Next(minZoneX, maxZoneX), random.Next(minZoneY, maxZoneY)); } while(this.Context.Zones.Any(z => zoneCenter.DistanceTo(z.Center) < minDistanceBetweenZones)); this.Context.Zones.Add(new Zone(i, zoneCenter)); } // drone starting points _droneStartingPoints = new Point[_nbrDrones]; for(int i = 0; i < _droneStartingPoints.Length; i++) _droneStartingPoints[i] = new Point(random.Next(GameContext.FieldWidth), random.Next(GameContext.FieldHeight)); }
private static bool TryGetCorner(Point intersectionPoint, Point cornerPoint, double radius, Func<Point, double, Circle> factory, out Circle corner) { if (intersectionPoint.DistanceTo(cornerPoint) < radius) { corner = factory(cornerPoint, radius); return true; } corner = default(Circle); return false; }
public void Update(GameTime gameTime) { Point endLocation = new Point(Game1.GRID_TILE_SIZE * GridLocation.X, Game1.GRID_TILE_SIZE * GridLocation.Y); if (RealLocation != endLocation) { MoveAnimation.Update(gameTime); int distance = endLocation.DistanceTo(RealLocation); if (distance >= MOVE_SPEED) { int dX = (int)(MOVE_SPEED * (endLocation.X - RealLocation.X)) / distance; int dY = (int)(MOVE_SPEED * (endLocation.Y - RealLocation.Y)) / distance; RealLocation = new Point(RealLocation.X + dX, RealLocation.Y + dY); } else { RealLocation = endLocation; } } }