示例#1
0
        /* Determines whether the stroke coule be interpreted as a
         * scratchout by checking that the length is greater than
         * three times the width of its bounding box, that it has
         * at least three self intersections, and its height is at
         * most three quarters of its width.
         */
        public static bool isScratchOut(Stroke s)
        {
            Rectangle rect   = s.GetBoundingBox();
            double    length = StrokeManager.StrokeLength(s);

            return(length > 3 * rect.Width && rect.Height <= rect.Width * 3 / 4 && s.SelfIntersections.Length > 2);
        }
示例#2
0
        public Node(Stroke stroke)
        {
            this.stroke = stroke;
            this.id     = stroke.Id;
            Rectangle r = stroke.GetBoundingBox();

            //Determine whether this node is a rectangle or not
            isRect      = r.Width * Math.PI < StrokeManager.StrokeLength(stroke);
            centerPoint = new Point(r.X + r.Width / 2, r.Y + r.Height / 2);
            fillColor   = DEFAULT;
            edges       = new Edges();
            textColor   = TEXT_DEFAULT;
            text        = "";
            //Set initial distance to infinity (max int)
            distance = Int32.MaxValue;
        }
示例#3
0
        /* Returns true if the stroke resembles a rectangle given a tolerance.
         * Accomplishes this by taking the perimeter of a rectangle that
         * would be bounded in the area the stroke is bounded and
         * comparing it to the length of the stroke.
         */
        public static bool FitsRectProperties(Stroke e, double tolerance)
        {
            if (e == null || FitsCircleProperties(e, CIRCLE_TOLERANCE))
            {
                return(false);
            }
            Rectangle r = e.GetBoundingBox();

            if (r.Height < MIN_WIDTH || r.Width < MIN_WIDTH)
            {
                return(false);
            }
            double perimeter    = r.Height * 2 + r.Width * 2;
            double strokeLength = StrokeManager.StrokeLength(e);

            return(Math.Abs(perimeter - strokeLength) <= tolerance);
        }
示例#4
0
        /* Returns true if the stroke resembles a circle given a tolerance.
         * Accomplishes this by taking the perimeter of a circle that
         * would be bounded in the area the stroke is bounded and
         * comparing it to the length of the stroke.
         */
        public static bool FitsCircleProperties(Stroke e, double tolerance)
        {
            if (e == null)
            {
                return(false);
            }
            Rectangle r      = e.GetBoundingBox();
            double    radius = StrokeManager.Avg(r.Height, r.Width) / 2.0;

            if (radius < MIN_WIDTH / 2)
            {
                return(false);
            }
            double perimeter = 2.0 * radius * Math.PI;

            Point[] points       = e.GetPoints();
            double  strokeLength = StrokeManager.StrokeLength(e);

            return(Math.Abs(perimeter - strokeLength) <= tolerance);
        }
示例#5
0
        /* Checks if the stroke drawn is within the range of a
         * edge from Graph g.  The range of an edge is roughly
         * around its center.
         */
        public static Edge HitEdgeTest(Stroke s, Graph g)
        {
            if (StrokeManager.StrokeLength(s) > HIT_TEST_THRESHOLD)
            {
                return(null);
            }
            float distance = 1300;
            Edge  hitedge  = null;

            for (int i = 0; i < g.Edges.Length(); i++)
            {
                float     tmp;
                Edge      e    = g.Edges[i];
                Rectangle rect = e.Stroke.GetBoundingBox();
                Point     p    = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
                s.NearestPoint(p, out tmp);
                if (tmp < distance)
                {
                    distance = tmp;
                    hitedge  = e;
                }
            }
            return(hitedge);
        }