/// <summary> /// Determines whether the last click is a double click. /// </summary> /// <param name="sender">The sender.</param> /// <param name="position">The position.</param> /// <returns>True if the click was a double click.</returns> internal static bool IsDoubleClick(object sender, Point position) { long clickTicks = DateTime.Now.Ticks; long elapsedTicks = clickTicks - lastClickTicks; long elapsedTime = elapsedTicks / TimeSpan.TicksPerMillisecond; bool quickClick = elapsedTime <= DoubleClickSpeed; bool senderMatch = lastSender != null && sender.Equals(lastSender.Target); if (senderMatch && quickClick && position.Distance(lastPosition) <= MaxMoveDistance) { // Double click! lastClickTicks = 0; lastSender = null; return true; } // Not a double click lastClickTicks = clickTicks; lastPosition = position; if (!quickClick) { lastSender = new WeakReference(sender); } return false; }
/// <summary> /// Computes the closest point on this line segment to another point. /// </summary> /// <param name="p">The point to find the closest point to.</param> /// <returns> /// A Coordinate which is the closest point on the line segment to the point p. /// </returns> public static Point ClosestPoint(Point p, Point LineSegFrom, Point LineSegTo) { var factor = ProjectionFactor(p, LineSegFrom, LineSegTo); if (factor > 0 && factor < 1) return Project(p, LineSegFrom, LineSegTo); var dist0 = LineSegFrom.Distance(p); var dist1 = LineSegTo.Distance(p); return dist0 < dist1 ? LineSegFrom : LineSegTo; }
public double GetCentreToBoundaryDistance(ILinearEquation line) { var relativeOrigin = new Point(0, 0); var relativeBoundaryIntersection = GetRelativeIntersectionPoint(line); double distanceToBoundary = relativeOrigin.Distance(relativeBoundaryIntersection); return distanceToBoundary; }
public static Triangle FromTwoPointsAndTwoLengths(Point point1, Point point2, double l1, double l2) { double l3 = point1.Distance(point2); double area = Triangle.AreaByLenghts(l1, l2, l3); double angle = Math.Asin(2 * area / (l1 * l3)); Vector horizontal = point1.VectorTo(point1.AddX(1)); double angle0 = horizontal.AngleWith(point1.VectorTo(point2)); double x = l1 * Math.Cos(angle0 - angle); double y = l1 * Math.Sin(angle0 - angle); Point point3 = point1.AddX(x).AddY(y); return new Triangle(point1, point2, point3); }
private static int func(Point p1, Point p2, Point p3) { int h, t; h = p1.Distance(); t = p2.x + h; h += p2.Distance(); if (p3.y == t) { h += p3.Distance(); } return h; }
private bool IsClosingALoop(LineString gpxLine, int currentIndex, double closestPointTolerance) { int indexOfLinePrefix = currentIndex - 1; var currentCoordinatePoint = new Point(gpxLine[currentIndex]); while (indexOfLinePrefix >= 0) { if (currentCoordinatePoint.Distance(new Point(gpxLine.Coordinates[indexOfLinePrefix])) > closestPointTolerance) { break; } indexOfLinePrefix--; } if (indexOfLinePrefix < 0) { return false; } var distance = indexOfLinePrefix > 0 ? currentCoordinatePoint.Distance(new LineString(gpxLine.Coordinates.Take(indexOfLinePrefix + 1).ToArray())) : currentCoordinatePoint.Distance(new Point(gpxLine.Coordinates[indexOfLinePrefix])); return distance < closestPointTolerance; }
/// <summary> /// Determines if the polygon is within the specified distance from the point. /// </summary> /// <param name="polygon"></param> /// <param name="point"></param> /// <param name="distance"></param> /// <returns></returns> public static bool WithinDistance(this Polygon polygon, Point point, double distance) { if (Null(polygon, point)) return false; return point.Distance(polygon) < distance; }
/// <summary> /// Calculates the shortest distance to the point. /// </summary> /// <param name="polygon"></param> /// <param name="point"></param> /// <returns></returns> public static double Distance(this Polygon polygon, Point point) { AssertNotNull(polygon, point); return point.Distance(polygon); }
/// <summary> /// Calculates the shortest distance to the point. /// </summary> /// <param name="polyline"></param> /// <param name="point"></param> /// <returns></returns> public static double Distance(this Polyline polyline, Point point) { AssertNotNull(polyline, point); return point.Distance(polyline); }
/// <summary> /// Determines if the multipoint is within the specified distance from the point. /// </summary> /// <param name="multipoint"></param> /// <param name="point"></param> /// <param name="distance"></param> /// <returns></returns> public static bool WithinDistance(this Multipoint multipoint, Point point, double distance) { if (Null(multipoint, point)) return false; return point.Distance(multipoint) < distance; }
Element ElementNearestToPoint(Point position, Element caller, out double minDistance, out ThumbPosition nearestThumbPosition) { minDistance = double.PositiveInfinity; Element hitElement = null; nearestThumbPosition = ThumbPosition.NotSet; foreach (Element element in UnconnectedElements) { if(element == caller) continue; foreach (ThumbPosition thumbPosition in element.AvailableIncomingConnectors) { Point elementLocation = element.GetCanvasThumbPosition(thumbPosition); double distance = position.Distance(elementLocation); if(distance < minDistance) { minDistance = distance; hitElement = element; nearestThumbPosition = thumbPosition; } } } return hitElement; }
public static IEnumerable<IFeature> GetFeaturesInRange(ICoordinate coordinate, IEnumerable<IFeature> features, double tolerance) { var minDistance = tolerance; var point = new Point(coordinate); return (from feature in features where feature.Geometry != null // Distance method requires a defined Geometry let distance = point.Distance(feature.Geometry) where distance <= minDistance select feature).ToList(); }
Point GetEndPoint(Point startPoint, int minSteps, int maxSteps, int maxSize) { Point endPoint = null; var maxTryes = maxSteps * maxSteps; var distance = 0; do { endPoint = new Point(random.Next(0, maxSize), random.Next(0, maxSize)); maxTryes--; distance = startPoint.Distance(endPoint); } while (maxTryes > 0 && (distance < minSteps || distance >= maxSteps)); if (maxTryes == 0) { return null; } return endPoint; }
public static IFeature GetNearestFeature(ICoordinate coordinate, IEnumerable<IFeature> features, double tolerance) { var minDistance = tolerance; IFeature minDistanceFeature = null; var point = new Point(coordinate); foreach (var feature in features) { if(feature.Geometry == null) continue; var distance = point.Distance(feature.Geometry); if (distance <= minDistance) { minDistance = distance; minDistanceFeature = feature; } } return minDistanceFeature; }
/// <summary> /// Calculates the shortest distance to the point. /// </summary> /// <param name="multipoint"></param> /// <param name="point"></param> /// <returns></returns> public static double Distance(this Multipoint multipoint, Point point) { AssertNotNull(multipoint, point); return point.Distance(multipoint); }
public static double Distance(Point a, Point b) { return a.Distance(b); }
public Node(Point pos_, float G_, Point fromPos, Point toPos) { pos = pos_; G = G_ + pos.Distance(fromPos); H = pos.Distance(toPos); F = G + H; }
/// <summary> /// Computes the distance from a point p to a line segment AB. /// Note: NON-ROBUST! /// </summary> /// <param name="p">The point to compute the distance for.</param> /// <param name="A">One point of the line.</param> /// <param name="B">Another point of the line (must be different to A).</param> /// <returns> The distance from p to line segment AB.</returns> public static double DistancePointLine(Point p, Point A, Point B) { // if start == end, then use pt distance if (A.Equals(B)) return p.Distance(A); // otherwise use comp.graphics.algorithms Frequently Asked Questions method /*(1) AC dot AB r = --------- ||AB||^2 r has the following meaning: r=0 Point = A r=1 Point = B r<0 Point is on the backward extension of AB r>1 Point is on the forward extension of AB 0<r<1 Point is interior to AB */ double r = ((p.X - A.X) * (B.X - A.X) + (p.Y - A.Y) * (B.Y - A.Y)) / ((B.X - A.X) * (B.X - A.X) + (B.Y - A.Y) * (B.Y - A.Y)); if (r <= 0.0) return p.Distance(A); if (r >= 1.0) return p.Distance(B); /*(2) (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay) s = ----------------------------- Curve^2 Then the distance from C to Point = |s|*Curve. */ double s = ((A.Y - p.Y) * (B.X - A.X) - (A.X - p.X) * (B.Y - A.Y)) / ((B.X - A.X) * (B.X - A.X) + (B.Y - A.Y) * (B.Y - A.Y)); return Math.Abs(s) * Math.Sqrt(((B.X - A.X) * (B.X - A.X) + (B.Y - A.Y) * (B.Y - A.Y))); }