Exemple #1
0
		public void Stroke_Default ()
		{
			Stroke s = new Stroke ();

			Assert.AreEqual (0, s.StylusPoints.Count, "StylusPoints");

			Assert.Throws<ArgumentException> (delegate {
				s.HitTest (null);
			}, "HitTest-null");
			Assert.IsFalse (s.HitTest (s.StylusPoints), "HitTest-StylusPoints");
		}
Exemple #2
0
		public void Stroke_StylusPointCollection ()
		{
			StylusPointCollection spc = new StylusPointCollection ();
			spc.Add (new StylusPoint (1, 2));

			Stroke s = new Stroke (spc);
			Assert.AreEqual (1, s.StylusPoints.Count, "StylusPoints-1");

			spc.Add (new StylusPoint (3, 4));
			Assert.AreEqual (2, s.StylusPoints.Count, "StylusPoints-2");

			s.StylusPoints.Add (new StylusPoint (5, 6));
			Assert.AreEqual (3, s.StylusPoints.Count, "StylusPoints-3a");
			Assert.AreEqual (3, spc.Count, "StylusPoints-3b");

			Assert.Throws<ArgumentException> (delegate {
				s.HitTest (null);
			}, "HitTest-null");
			Assert.IsTrue (s.HitTest (s.StylusPoints), "HitTest-StylusPoints");
		}
Exemple #3
0
        void ProcessPointErase(Stroke stroke, StylusPointCollection pointErasePoints)
        {
            Stroke splitStroke1, splitStroke2, hitTestStroke;

            // Determine first split stroke.
            splitStroke1 = new Stroke();
            hitTestStroke = new Stroke();
            hitTestStroke.StylusPoints.Add(stroke.StylusPoints);
            hitTestStroke.DrawingAttributes = stroke.DrawingAttributes;

            //Iterate through the stroke from index 0 and add each stylus point to splitstroke1 until
            //a stylus point that intersects with the input stylus point collection is reached.
            while (true)
            {
                StylusPoint sp = hitTestStroke.StylusPoints[0];
                hitTestStroke.StylusPoints.RemoveAt(0);
                if (!hitTestStroke.HitTest(pointErasePoints)) break;
                splitStroke1.StylusPoints.Add(sp);
            }

            //Determine second split stroke.
            splitStroke2 = new Stroke();
            hitTestStroke = new Stroke();
            hitTestStroke.StylusPoints.Add(stroke.StylusPoints);
            hitTestStroke.DrawingAttributes = stroke.DrawingAttributes;
            while (true)
            {
                StylusPoint sp = hitTestStroke.StylusPoints[hitTestStroke.StylusPoints.Count - 1];
                hitTestStroke.StylusPoints.RemoveAt(hitTestStroke.StylusPoints.Count - 1);
                if (!hitTestStroke.HitTest(pointErasePoints)) break;
                splitStroke2.StylusPoints.Insert(0, sp);
            }

            // Replace stroke with splitstroke1 and splitstroke2.
            if (splitStroke1.StylusPoints.Count > 1)
            {
                splitStroke1.DrawingAttributes = stroke.DrawingAttributes;
                _presenter.Strokes.Add(splitStroke1);
                //App.inkStorage.Strokes.Add(splitStroke1);
            }
            if (splitStroke2.StylusPoints.Count > 1)
            {
                splitStroke2.DrawingAttributes = stroke.DrawingAttributes;
                _presenter.Strokes.Add(splitStroke2);
                 //App.inkStorage.Strokes.Add(splitStroke2);
            }
            _presenter.Strokes.Remove(stroke);
            // App.inkStorage.Strokes.Remove(stroke);
        }
Exemple #4
0
        public override bool takeStroke(Stroke s)
        {
            InkUtils.depressurize(s.StylusPoints);
            StylusPointCollection col = InkUtils.toPolyline(s.StylusPoints);
            if (xAxis == null || yAxis == null)
            {
                if (col.Count == 2)
                {
                    StylusPoint p1 = col[0];
                    StylusPoint p2 = col[1];
                    if (xAxis == null && Math.Abs(p2.X - p1.X) > 100 && Math.Abs((p2.Y - p1.Y) / (p2.X - p1.X)) < 0.3)
                    {
                        if (yAxis == null)
                        {
                            if (p1.X < p2.X)
                            {
                                origin = new Point(p1.X, p1.Y);
                                xEnd = new Point(p2.X, p1.Y);
                            }
                            else
                            {
                                origin = new Point(p2.X, p2.Y);
                                xEnd = new Point(p1.X, p2.Y);
                            }
                        }
                        else if (InkUtils.distSquared(p2, InkUtils.sp(origin)) < 20 * 20)
                        {
                            xEnd = new Point(p1.X, origin.Y);
                        }
                        else if (InkUtils.distSquared(p1, InkUtils.sp(origin)) < 20 * 20)
                        {
                            xEnd = new Point(p2.X, origin.Y);
                        }
                        else
                        {
                            goto notX;
                        }
                        xAxis = s;
                        s.StylusPoints = InkUtils.xkcd(new StylusPointCollection(new Point[] { origin, xEnd }));
                        return true;
                    }
                notX:
                    if (yAxis == null && Math.Abs(p2.Y - p1.Y) > 100 && Math.Abs((p2.X - p1.X) / (p2.Y - p1.Y)) < 0.3)
                    {
                        if (xAxis == null)
                        {
                            if (p1.Y > p2.Y)
                            {
                                origin = new Point(p1.X, p1.Y);
                                yEnd = new Point(p1.X, p2.Y);
                            }
                            else
                            {
                                origin = new Point(p2.X, p2.Y);
                                yEnd = new Point(p2.X, p1.Y);
                            }
                        }
                        else if (InkUtils.distSquared(p2, InkUtils.sp(origin)) < 20 * 20)
                        {
                            yEnd = new Point(origin.X, p1.Y);
                        }
                        else if (InkUtils.distSquared(p1, InkUtils.sp(origin)) < 20 * 20)
                        {
                            yEnd = new Point(origin.X, p2.Y);
                        }
                        else
                        {
                            goto notY;
                        }
                        yAxis = s;
                        s.StylusPoints = InkUtils.xkcd(new StylusPointCollection(new Point[] { origin, yEnd }));
                        return true;
                    }
                notY: { }
                }
            }
            else
            {
                StylusPoint spOrigin = InkUtils.sp(origin), spXEnd = InkUtils.sp(xEnd), spYEnd = InkUtils.sp(yEnd);
                // Support bars
                if (col.Count == 4
                    // Vertical bars
                    && InkUtils.isVertical(col[0], col[1])
                    //&& InkUtils.isHorizontal(col[1], col[2])
                    && InkUtils.isVertical(col[2], col[3])
                    && InkUtils.similar(Math.Sqrt(InkUtils.distSquared(col[0], col[1])),
                    Math.Sqrt(InkUtils.distSquared(col[2], col[3])))
                    && InkUtils.lineDistSquared(spOrigin, spXEnd, col[0]) < 400
                    && InkUtils.lineDistSquared(spOrigin, spXEnd, col[3]) < 400)
                {
                    double x1 = (col[0].X + col[1].X) / 2;
                    double x2 = (col[2].X + col[3].X) / 2;
                    double y = (col[1].Y + col[2].Y) / 2;
                    s.StylusPoints = InkUtils.xkcd(new StylusPointCollection(new Point[] {
                        new Point(x1, origin.Y),
                        new Point(x1, y),
                        new Point(x2, y),
                        new Point(x2, origin.Y)
                    }));
                    fillBar(x1, origin.Y, x2, y);
                }
                else if (col.Count == 4
                    // Horizontal bars
                    && InkUtils.isHorizontal(col[0], col[1])
                    //&& InkUtils.isVertical(col[1], col[2])
                    && InkUtils.isHorizontal(col[2], col[3])
                    && InkUtils.similar(Math.Sqrt(InkUtils.distSquared(col[0], col[1])),
                    Math.Sqrt(InkUtils.distSquared(col[2], col[3])))
                    && InkUtils.lineDistSquared(spOrigin, spYEnd, col[0]) < 400
                    && InkUtils.lineDistSquared(spOrigin, spYEnd, col[3]) < 400)
                {
                    double y1 = (col[0].Y + col[1].Y) / 2;
                    double y2 = (col[2].Y + col[3].Y) / 2;
                    double x = (col[1].X + col[2].X) / 2;
                    s.StylusPoints = InkUtils.xkcd(new StylusPointCollection(new Point[] {
                        new Point(origin.X, y1),
                        new Point(x, y1),
                        new Point(x, y2),
                        new Point(origin.X, y2)
                    }));
                    fillBar(origin.X, y1, x, y2);
                }
                // Maybe it's inside the graph itself?
                else if (s.HitTest(new Rect(xEnd, yEnd), 80))
                {
                    s.StylusPoints = InkUtils.xkcd(s.StylusPoints);
                }
            }

            curves.Add(s);
//            s.StylusPoints = InkUtils.xkcd(col);

            //analyzer.AddStroke(s);
            //analyzer.Analyze();
            return true;
        }
Exemple #5
0
 public bool containsStroke(Stroke s)
 {
     return s.HitTest(bounds, 80);
 }