/// <summary> /// Clip /// </summary> /// <param name="cutAt">Fragment markers for clipping</param> private StrokeCollection Clip(StrokeFIndices[] cutAt) { System.Diagnostics.Debug.Assert(cutAt != null); System.Diagnostics.Debug.Assert(cutAt.Length != 0); #if DEBUG // // Assert there are no overlaps between multiple StrokeFIndices // AssertSortedNoOverlap(cutAt); #endif StrokeCollection leftovers = new StrokeCollection(); if (cutAt.Length == 0) { return(leftovers); } if ((cutAt.Length == 1) && cutAt[0].IsFull) { leftovers.Add(this.Clone()); //clip and erase always return clones return(leftovers); } StylusPointCollection sourceStylusPoints = this.StylusPoints; if (this.DrawingAttributes.FitToCurve) { sourceStylusPoints = this.GetBezierStylusPoints(); } // // Assert the findices are NOT out of range with the packets // System.Diagnostics.Debug.Assert(false == ((!DoubleUtil.AreClose(cutAt[cutAt.Length - 1].EndFIndex, StrokeFIndices.AfterLast)) && Math.Ceiling(cutAt[cutAt.Length - 1].EndFIndex) > sourceStylusPoints.Count - 1)); for (int i = 0; i < cutAt.Length; i++) { StrokeFIndices fragment = cutAt[i]; if (DoubleUtil.GreaterThanOrClose(fragment.BeginFIndex, fragment.EndFIndex)) { // ISSUE-2004/06/26-vsmirnov - temporary workaround for bugs // in point erasing: drop invalid fragments System.Diagnostics.Debug.Assert(DoubleUtil.LessThan(fragment.BeginFIndex, fragment.EndFIndex)); continue; } Stroke stroke = Copy(sourceStylusPoints, fragment.BeginFIndex, fragment.EndFIndex); // Add the stroke to the output collection leftovers.Add(stroke); } return(leftovers); }
/// <summary> /// Performs a deep copy of the StrokeCollection. /// </summary> public virtual StrokeCollection Clone() { StrokeCollection clone = new StrokeCollection(); foreach (Stroke s in this) { // samgeo - Presharp issue // Presharp gives a warning when get methods might deref a null. It's complaining // here that s could be null, but StrokeCollection never allows nulls to be added // so this is not possible #pragma warning disable 1634, 1691 #pragma warning suppress 6506 clone.Add(s.Clone()); #pragma warning restore 1634, 1691 } // // clone epc if we have them // if (_extendedProperties != null) { clone._extendedProperties = _extendedProperties.Clone(); } return(clone); }
/// <summary> /// Hit-testing with rectangle /// </summary> /// <param name="bounds">hitting rectangle</param> /// <param name="percentageWithinBounds">the percentage of the stroke that must be within /// the bounds to be considered hit</param> /// <returns>collection of strokes found inside the rectangle</returns> public StrokeCollection HitTest(Rect bounds, int percentageWithinBounds) { // Check the input parameters if ((percentageWithinBounds < 0) || (percentageWithinBounds > 100)) { throw new System.ArgumentOutOfRangeException("percentageWithinBounds"); } if (bounds.IsEmpty) { return(new StrokeCollection()); } // Enumerate thru the strokes collect those found within the rectangle. StrokeCollection hits = new StrokeCollection(); foreach (Stroke stroke in this) { // samgeo - Presharp issue // Presharp gives a warning when get methods might deref a null. It's complaining // here that 'stroke'' could be null, but StrokeCollection never allows nulls to be added // so this is not possible #pragma warning disable 1634, 1691 #pragma warning suppress 6506 if (true == stroke.HitTest(bounds, percentageWithinBounds)) { hits.Add(stroke); } #pragma warning restore 1634, 1691 } return(hits); }
/// <summary> /// Calculates the position of an error label based upon the bounding box of the elements /// causing the error. /// /// Helper Function /// </summary> private System.Drawing.Point getLabelPosition(ParseError e, List <System.Windows.Ink.Stroke> iStrokes) { if (e.errors.Count == 0) { // TEMP HACK return the origin (or near it) when there are no associated elements return(new System.Drawing.Point(10, 10)); } // Get bounding box of strokes in screen space System.Drawing.Point bbUpperLeft; System.Drawing.Point bbLowerRight; System.Windows.Ink.StrokeCollection strokes = new System.Windows.Ink.StrokeCollection(); foreach (System.Windows.Ink.Stroke s in iStrokes) { strokes.Add(s); } System.Windows.Rect strokesBB = strokes.GetBounds(); bbUpperLeft = new System.Drawing.Point((int)strokesBB.X, (int)strokesBB.Y); bbLowerRight = new System.Drawing.Point((int)strokesBB.Right, (int)strokesBB.Bottom); // return position just to the right of the bounding box System.Drawing.Point returnPoint = new System.Drawing.Point(bbLowerRight.X + 10, bbUpperLeft.Y + 10); return(returnPoint); }
public static WindowsInk.StrokeCollection ToWindowsStrokes(Collection<NineInk.Stroke> nineStrokes) { var windowsStrokes = new WindowsInk.StrokeCollection(); foreach (var stroke in nineStrokes) windowsStrokes.Add(ToWindowsStroke(stroke)); return windowsStrokes; }
public static WindowsInk.StrokeCollection ToWindowsStrokes(Collection <NineInk.Stroke> nineStrokes) { var windowsStrokes = new WindowsInk.StrokeCollection(); foreach (var stroke in nineStrokes) { windowsStrokes.Add(ToWindowsStroke(stroke)); } return(windowsStrokes); }
/// <summary> /// Replace /// </summary> /// <param name="strokeToReplace"></param> /// <param name="strokesToReplaceWith"></param> public void Replace(Stroke strokeToReplace, StrokeCollection strokesToReplaceWith) { if (strokeToReplace == null) { throw new ArgumentNullException(SR.Get(SRID.EmptyScToReplace)); } StrokeCollection strokesToReplace = new StrokeCollection(); strokesToReplace.Add(strokeToReplace); this.Replace(strokesToReplace, strokesToReplaceWith); }
/// <summary> /// Return all hit strokes that the StylusShape intersects and returns them in a StrokeCollection /// </summary> private StrokeCollection PointHitTest(Point point, StylusShape shape) { // Create the collection to return StrokeCollection hits = new StrokeCollection(); for (int i = 0; i < this.Count; i++) { Stroke stroke = this[i]; if (stroke.HitTest(new Point[] { point }, shape)) { hits.Add(stroke); } } return(hits); }
/// <summary> /// Calculate the after-erasing Strokes. Only the "out-segments" are left after this operation. /// </summary> /// <param name="cutAt">Array of intersections indicating the erasing locations</param> /// <returns></returns> internal StrokeCollection Erase(StrokeIntersection[] cutAt) { System.Diagnostics.Debug.Assert(cutAt != null); // Nothing needs to be erased if (cutAt.Length == 0) { StrokeCollection strokes = new StrokeCollection(); strokes.Add(this.Clone()); //clip and erase always return clones for this condition return(strokes); } // Two assertions are deferred to the private erase function to avoid duplicate code. // 1. AssertSortedNoOverlap // 2. Check whether the insegments are out of range with the packets StrokeFIndices[] hitSegments = StrokeIntersection.GetHitSegments(cutAt); return(this.Erase(hitSegments)); }
/// <summary> /// Issue: what's the return value /// </summary> /// <param name="path"></param> /// <param name="stylusShape"></param> /// <returns></returns> public StrokeCollection HitTest(IEnumerable <Point> path, StylusShape stylusShape) { // Check the input parameters if (stylusShape == null) { throw new System.ArgumentNullException("stylusShape"); } if (path == null) { throw new System.ArgumentNullException("path"); } if (IEnumerablePointHelper.GetCount(path) == 0) { return(new StrokeCollection()); } // validate input ErasingStroke erasingStroke = new ErasingStroke(stylusShape, path); Rect erasingBounds = erasingStroke.Bounds; if (erasingBounds.IsEmpty) { return(new StrokeCollection()); } StrokeCollection hits = new StrokeCollection(); foreach (Stroke stroke in this) { // samgeo - Presharp issue // Presharp gives a warning when get methods might deref a null. It's complaining // here that 'stroke'' could be null, but StrokeCollection never allows nulls to be added // so this is not possible #pragma warning disable 1634, 1691 #pragma warning suppress 6506 if (erasingBounds.IntersectsWith(stroke.GetBounds()) && erasingStroke.HitTest(StrokeNodeIterator.GetIterator(stroke, stroke.DrawingAttributes))) { hits.Add(stroke); } #pragma warning restore 1634, 1691 } return(hits); }
/// <summary> /// Hit-testing with lasso /// </summary> /// <param name="lassoPoints">points making the lasso</param> /// <param name="percentageWithinLasso">the margin value to tell whether a stroke /// is in or outside of the rect</param> /// <returns>collection of strokes found inside the rectangle</returns> public StrokeCollection HitTest(IEnumerable <Point> lassoPoints, int percentageWithinLasso) { // Check the input parameters if (lassoPoints == null) { throw new System.ArgumentNullException("lassoPoints"); } if ((percentageWithinLasso < 0) || (percentageWithinLasso > 100)) { throw new System.ArgumentOutOfRangeException("percentageWithinLasso"); } if (IEnumerablePointHelper.GetCount(lassoPoints) < 3) { return(new StrokeCollection()); } Lasso lasso = new SingleLoopLasso(); lasso.AddPoints(lassoPoints); // Enumerate through the strokes and collect those captured by the lasso. StrokeCollection lassoedStrokes = new StrokeCollection(); foreach (Stroke stroke in this) { if (percentageWithinLasso == 0) { lassoedStrokes.Add(stroke); } else { StrokeInfo strokeInfo = null; try { strokeInfo = new StrokeInfo(stroke); StylusPointCollection stylusPoints = strokeInfo.StylusPoints; double target = strokeInfo.TotalWeight * percentageWithinLasso / 100.0f - Stroke.PercentageTolerance; for (int i = 0; i < stylusPoints.Count; i++) { if (true == lasso.Contains((Point)stylusPoints[i])) { target -= strokeInfo.GetPointWeight(i); if (DoubleUtil.LessThanOrClose(target, 0f)) { lassoedStrokes.Add(stroke); break; } } } } finally { if (strokeInfo != null) { //detach from event handlers, or else we leak. strokeInfo.Detach(); } } } } // Return the resulting collection return(lassoedStrokes); }