예제 #1
0
 public Graph(IDelegate _del, Stroke b)
 {
     del                          = _del;
     box                          = b;
     bounds                       = box.GetBounds();
     box.StylusPoints             = InkUtils.xkcd(InkUtils.box(bounds));
     box.DrawingAttributes.Color  = Colors.Blue;
     analyzer                     = new InkAnalyzer();
     analyzer.ContextNodeCreated += ContextNodeCreated;
 }
예제 #2
0
        protected override void ContextNodeCreated(object sender, ContextNodeCreatedEventArgs e)
        {
            Debug.WriteLine("Holy molly! {0}", e.NodeCreated);
            InkDrawingNode n = e.NodeCreated as InkDrawingNode;

            if (n != null)
            {
                Debug.WriteLine("Yeah!");
                foreach (Stroke x in n.Strokes)
                {
                    Debug.WriteLine("Uhhhhh {0}", x);
                    analyzer.RemoveStroke(x);
                    x.StylusPoints = InkUtils.xkcd(x.StylusPoints);
                }
            }
        }
예제 #3
0
        private void fillBar(double _x1, double _y1, double _x2, double _y2)
        {
            const double dist = 14, stdev = 4, fillGap = 0.05;
            double       x1         = Math.Min(_x1, _x2),
                         x2         = Math.Max(_x1, _x2),
                         y1         = Math.Min(_y1, _y2),
                         y2         = Math.Max(_y1, _y2);
            double d                = x1 + y1 + dist;
            StylusPointCollection r = new StylusPointCollection();
            //r.Add(new StylusPoint(x1, y1));
            bool side = false;

            while (d < x2 + y2 - dist)
            {
                if (side = !side)
                {
                    double x1_ = x1 + (x2 - x1) * Math.Abs(InkUtils.stdNorm() * fillGap);
                    double y2_ = y2 - (y2 - y1) * Math.Abs(InkUtils.stdNorm() * fillGap);
                    if (d - x1_ < y2_)
                    {
                        r.Add(new StylusPoint(x1_, d - x1_));
                    }
                    else
                    {
                        r.Add(new StylusPoint(d - y2_, y2_));
                    }
                }
                else
                {
                    double x2_ = x2 - (x2 - x1) * Math.Abs(InkUtils.stdNorm() * fillGap);
                    double y1_ = y1 + (y2 - y1) * Math.Abs(InkUtils.stdNorm() * fillGap);
                    if (d - x2_ > y1_)
                    {
                        r.Add(new StylusPoint(x2_, d - x2_));
                    }
                    else
                    {
                        r.Add(new StylusPoint(d - y1_, y1_));
                    }
                    d += Math.Abs(InkUtils.stdNorm() * stdev + dist);
                }
            }
            Stroke s = new Stroke(InkUtils.xkcd(r));

            s.DrawingAttributes.Color = colGen.nextColor();
            addStroke(s);
        }
예제 #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);
        }