/// <summary> /// Handle manipulation delta of quad corner /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InteractiveQuadRenderer_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e) { var cornerControl = sender as ImageCropperThumb; double x = Math.Min(m_canvas.ActualWidth, Math.Max(0.0, Canvas.GetLeft(cornerControl) + e.Delta.Translation.X)); double y = Math.Min(m_canvas.ActualHeight, Math.Max(0.0, Canvas.GetTop(cornerControl) + e.Delta.Translation.Y)); Canvas.SetLeft(cornerControl, x); Canvas.SetTop(cornerControl, y); // Refresh polygon drawing var points = new PointCollection(); foreach (var corner in m_cornerControls) { points.Add(new Point( Math.Min(m_canvas.ActualWidth, Math.Max(0.0, Canvas.GetLeft(corner))), Math.Min(m_canvas.ActualHeight, Math.Max(0.0, Canvas.GetTop(corner))))); } m_polygon.Points = points; // Notify a change in corner value happened if (CornersChanged != null) { CornersChanged.Invoke(points.Select((p) => { p.X /= m_canvas.ActualWidth; p.Y /= m_canvas.ActualHeight; return(p); }).ToList()); } }
public static PointCollection Shifted(this PointCollection points, double shift, double duration) { if (points == null) { return(null); } var shifted = points.Select(p => new Point(p.X - shift, p.Y)) .ToList(); // by now, always quadruples (boxes). Preserve that! var clipped = new List <Point>(shifted.Count); for (int i = 0; i < shifted.Count / 4; i++) { var q = shifted.Skip(i * 4).Take(4).ToArray(); if (q.All(p => p.X < 0 || p.X > duration)) { continue; } q = q.Clamped(0, duration).ToArray(); clipped.AddRange(q); } return(new PointCollection(clipped)); }
/// <summary> /// Transforms the collection of Points to ILocations according to the matrix. /// </summary> /// <param name="pc"> /// The collection of Points to be transformed. /// </param> /// <returns> /// The transformed Points as ILocations. /// </returns> public IList <ILocation> Transform(PointCollection pc) { return (pc.Select( p => MilSymFactory.Location( Order.LatLon, (p.X * this.M12) + (p.Y * this.M22) + this.M32, (p.X * this.M11) + (p.Y * this.M21) + this.M31)).ToList()); }
private int?FindNearestPointIndex(PointCollection points, Point newPoint) { if (points == null || !points.Any()) { return(null); } Func <Point, Point, double> getLength = (p1, p2) => Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2)); var items = points.Select((p, i) => new { Point = p, Length = getLength(p, newPoint), Index = i }); var minLength = items.Min(item => item.Length); return(items.First(item => item.Length == minLength).Index); }
public static void DrawSpline(this DrawingContext dc, PointCollection pointCollection, double offsetX, double offsetY, Format format) { pointCollection = PointCollection.Parse( string.Join(" ", pointCollection .Select(x => new Point(x.X + offsetX, x.Y + offsetY)) .Select(x => $"{x.X},{x.Y}")) ); StreamGeometry streamGeometry = new StreamGeometry(); using (StreamGeometryContext gcx = streamGeometry.Open()) { gcx.BeginFigure(pointCollection.First(), true, true); gcx.PolyLineTo(pointCollection, true, true); } dc.DrawGeometry(format.brushBackground, new Pen(format.brushForeground, format.penWidth), streamGeometry); }