Beispiel #1
0
        /// <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();
                }
            }

        }
Beispiel #2
0
 /// <summary>
 /// C-tor.
 /// </summary>
 /// <param name="strokes">strokes to hit-test</param>
 /// <param name="percentageWithinLasso">a hit-testing parameter that defines the minimal
 /// percent of nodes of a stroke to be inside the lasso to consider the stroke hit</param>
 internal IncrementalLassoHitTester(StrokeCollection strokes, int percentageWithinLasso)
     : base(strokes)
 {
     System.Diagnostics.Debug.Assert((percentageWithinLasso >= 0) && (percentageWithinLasso <= 100));
     _lasso = new SingleLoopLasso();
     _percentIntersect = percentageWithinLasso;
 }
Beispiel #3
0
        /// <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));
        }