/// <summary> /// Check whether a certain percentage of the stroke is within the lasso /// </summary> /// <param name="lassoPoints"></param> /// <param name="percentageWithinLasso"></param> /// <returns></returns> public bool HitTest(IEnumerable<Point> lassoPoints, int percentageWithinLasso) { if (lassoPoints == null) { throw new System.ArgumentNullException("lassoPoints"); } if ((percentageWithinLasso < 0) || (percentageWithinLasso > 100)) { throw new System.ArgumentOutOfRangeException("percentageWithinLasso"); } if (percentageWithinLasso == 0) { return true; } StrokeInfo strokeInfo = null; try { strokeInfo = new StrokeInfo(this); StylusPointCollection stylusPoints = strokeInfo.StylusPoints; double target = strokeInfo.TotalWeight * percentageWithinLasso / 100.0f - PercentageTolerance; Lasso lasso = new SingleLoopLasso(); lasso.AddPoints(lassoPoints); for (int i = 0; i < stylusPoints.Count; i++) { if (true == lasso.Contains((Point)stylusPoints[i])) { target -= strokeInfo.GetPointWeight(i); if (DoubleUtil.LessThan(target, 0f)) { return true; } } } return false; } finally { if (strokeInfo != null) { //detach from event handlers, or else we leak. strokeInfo.Detach(); } } }
/// <summary> /// Erase with lasso points. /// </summary> /// <param name="lassoPoints">Lasso points to erase with</param> /// <returns>The after-erasing strokes</returns> public StrokeCollection GetEraseResult(IEnumerable<Point> lassoPoints) { // Check the input parameters if (lassoPoints == null) { throw new System.ArgumentNullException("lassoPoints"); } if (IEnumerablePointHelper.GetCount(lassoPoints) == 0) { throw new ArgumentException(SR.Get(SRID.EmptyArray)); } Lasso lasso = new SingleLoopLasso(); lasso.AddPoints(lassoPoints); return this.Erase(this.HitTest(lasso)); }