public override KeyValuePair <double, Handle> GetSelectionDistance(SysPoint point) { BoardPoint boardPoint = Board.GetBoardPoint(point); double distance = Math.Max(Math.Abs(Position.X - boardPoint.X), Math.Abs(Position.Y - boardPoint.Y)) * Board.ZoomFactor; if (distance <= 6) { return(new KeyValuePair <double, Handle>(distance, null)); } // if we're drawing a motion vector and the vector is not controlled by waypoints, allow the user to grab that, too if (ShouldDrawMotionVector && Speed > 0 && !Children.Any(c => c is Waypoint)) { Vector2 vector = new Vector2(0, Speed * ManeuveringBoard.VectorTime).Rotate(-Direction); // use two pixels before the endpoint as the hotspot, since that's closer to the center of mass of the arrow head vector.GetNormal(vector.Length - 2 / Board.ZoomFactor); distance = boardPoint.DistanceTo(Position + vector) * Board.ZoomFactor; if (distance <= 5) { return(new KeyValuePair <double, Handle>(distance, vectorHandle)); } } return(new KeyValuePair <double, Handle>(double.NaN, null)); }
public override KeyValuePair <double, Handle> GetSelectionDistance(SysPoint point) { BoardPoint boardPoint = Board.GetBoardPoint(point); double distanceFromStart = boardPoint.DistanceTo(Start) * Board.ZoomFactor; double distanceFromEnd = boardPoint.DistanceTo(End) * Board.ZoomFactor; if (distanceFromStart <= 5 || distanceFromEnd <= 5) { return(new KeyValuePair <double, Handle>(Math.Min(distanceFromStart, distanceFromEnd), distanceFromStart < distanceFromEnd ? startHandle : endHandle)); } double distanceFromSegment = new Line2(Start, End).SegmentDistanceTo(boardPoint) * Board.ZoomFactor; return(new KeyValuePair <double, Handle>(distanceFromSegment <= 4 ? distanceFromSegment : double.NaN, moveHandle)); }
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)); }
public override KeyValuePair <double, Handle> GetSelectionDistance(SysPoint point) { BoardPoint boardPoint = Board.GetBoardPoint(point); // get the minimum from either the center point or the circle itself, whichever is smaller double distanceFromCenter = boardPoint.DistanceTo(Position), distanceFromEdge = Math.Abs(distanceFromCenter - Radius); if (distanceFromCenter < distanceFromEdge) { distanceFromCenter *= Board.ZoomFactor; return(new KeyValuePair <double, Handle>(distanceFromCenter <= 5 ? distanceFromCenter : double.NaN, null)); } else { distanceFromEdge *= Board.ZoomFactor; return(new KeyValuePair <double, Handle>(distanceFromEdge <= 4 ? distanceFromEdge : double.NaN, edgeHandle)); } }
public override void Render(Graphics graphics) { if (ShouldRender) { BoardPoint observerPosition = GetEffectiveObserverPosition(); observerPosition = new BoardPoint(observerPosition.X * Board.ZoomFactor, -observerPosition.Y * Board.ZoomFactor); Vector2 screenVector = new Vector2(0, -1).Rotate(Bearing); Line2 bearingLine = new Line2(observerPosition, screenVector); // since the bearing line is infinitely long, we'll test the intersection of the line against all four sides of the clipping // rectangle, and draw the line to the furthest intersection BoardRect clipRect = new BoardRect(graphics.VisibleClipBounds); BoardPoint endPoint = BoardPoint.Invalid; double maxDistance = 0; for (int i = 0; i < 4; i++) { Line2 edge = clipRect.GetEdge(i); LineIntersection intersection = bearingLine.GetIntersectionInfo(edge); if (intersection.OnSecond) { double distance = observerPosition.DistanceTo(intersection.Point); // find the closest point on the segment to ensure that we're only considering intersections in the forward direction of the // vector if (distance > maxDistance && bearingLine.ClosestPointOnSegment(intersection.Point) != bearingLine.Start) { endPoint = intersection.Point; maxDistance = distance; } } } if (endPoint.IsValid) { graphics.DrawLine(Pen, observerPosition.ToPointF(), endPoint.ToPointF()); graphics.DrawCircle(Pen, observerPosition.ToPointF(), 3); RenderTime(graphics, (observerPosition + (endPoint - observerPosition) * 0.5).ToPointF()); } } }