public override KeyValuePair <double, Handle> GetSelectionDistance(SysPoint point) { double distance; if (!ShouldRender) { distance = double.NaN; } else { BoardPoint boardPoint = Board.GetBoardPoint(point); BoardPoint observerPosition = GetEffectiveObserverPosition(); Line2 bearingLine = new Line2(observerPosition, new Vector2(0, 1).Rotate(-Bearing)); distance = Math.Abs(bearingLine.DistanceTo(boardPoint)) * Board.ZoomFactor; // the distance measurement considers the entire infinite line, but we only want to consider the ray starting from the observer, so // we'll ignore the portion of the line on the other side of the observer point if (distance > 4 || bearingLine.ClosestPointOnSegment(boardPoint) == bearingLine.Start && boardPoint.DistanceTo(bearingLine.Start) * Board.ZoomFactor > 4) { distance = double.NaN; } } return(new KeyValuePair <double, Handle>(distance, null)); }
private void DrawResults() { Vector2 point = Point.position; Line2 line = CreateLine2(Line); Vector2 closestPoint; float dist0 = Distance.Point2Line2(ref point, ref line, out closestPoint); float dist1 = line.DistanceTo(point); DrawVectorLine(closestPoint, point); /* * List<Vector2> linePoints = new List<Vector2>(); * linePoints.Add(closestPoint); // ...one on the left side of the screen somewhere * linePoints.Add(point); * // ...and one on the right * * // Make a VectorLine object using the above points, with a width of 2 pixels * var vectorLine = new VectorLine("Line", linePoints, 2.0f); * * // Draw the line * vectorLine.Draw(); */ LogInfo(dist0 + " " + dist1); }
private void OnDrawGizmos() { Vector2 point = Point.position; Line2 line = CreateLine2(Line); Vector2 closestPoint; float dist0 = Distance.Point2Line2(ref point, ref line, out closestPoint); float dist1 = line.DistanceTo(point); FiguresColor(); DrawLine(ref line); ResultsColor(); DrawPoint(closestPoint); LogInfo(dist0 + " " + dist1); }