public static RectangleStroke GetRectangleStroke(StylusPointCollection stylusPoints) { var count = stylusPoints.Count; for (int i = 1; i <= count - 2; i++) { stylusPoints.RemoveAt(1); } return(new RectangleStroke(stylusPoints)); }
protected override void OnStylusMove(RawStylusInput rawStylusInput) { StylusPointCollection stylusPoints = rawStylusInput.GetStylusPoints(); //// 让收集到的点只剩下起点和终点 while (stylusPoints.Count > 2) { stylusPoints.RemoveAt(stylusPoints.Count - 2); } this.Reset(Stylus.CurrentStylusDevice, stylusPoints); base.OnStylusMove(rawStylusInput); }
public static StylusPointCollection toPolyline(StylusPointCollection points_) { const int separation = 3; if (points_.Count <= 1) { return(new StylusPointCollection(points_)); } StylusPointCollection points = resample(points_, 3); StylusPointCollection r = new StylusPointCollection(); r.Add(points[0]); int i; for (i = separation; i + separation < points.Count; ++i) { StylusPoint prev = points[i - separation], cur = points[i], next = points[i + separation]; double dx1 = cur.X - prev.X, dy1 = cur.Y - prev.Y; double n1 = Math.Sqrt(dx1 * dx1 + dy1 * dy1); dx1 /= n1; dy1 /= n1; double dx2 = next.X - cur.X, dy2 = next.Y - cur.Y; double n2 = Math.Sqrt(dx2 * dx2 + dy2 * dy2); dx2 /= n2; dy2 /= n2; if (dx1 * dx2 + dy1 * dy2 < 0.7) { if (i < separation * 2) { r.RemoveAt(0); } r.Add(points[i]); i = i + separation * 2 - 1; } } if (i + separation == points.Count) { r.Add(points[points.Count - 1]); } return(r); }
public static StylusPointCollection toPolyline(StylusPointCollection points_) { const int separation = 3; if (points_.Count <= 1) return new StylusPointCollection(points_); StylusPointCollection points = resample(points_, 3); StylusPointCollection r = new StylusPointCollection(); r.Add(points[0]); int i; for (i = separation; i + separation < points.Count; ++i) { StylusPoint prev = points[i - separation], cur = points[i], next = points[i + separation]; double dx1 = cur.X - prev.X, dy1 = cur.Y - prev.Y; double n1 = Math.Sqrt(dx1 * dx1 + dy1 * dy1); dx1 /= n1; dy1 /= n1; double dx2 = next.X - cur.X, dy2 = next.Y - cur.Y; double n2 = Math.Sqrt(dx2 * dx2 + dy2 * dy2); dx2 /= n2; dy2 /= n2; if (dx1 * dx2 + dy1 * dy2 < 0.7) { if (i < separation*2) { r.RemoveAt(0); } r.Add(points[i]); i = i + separation * 2 - 1; } } if (i + separation == points.Count) { r.Add(points[points.Count - 1]); } return r; }