コード例 #1
0
        internal int GetIndexforNewPoint(Point point)
        {
            int          index = 0;
            LineGeometry pathGeom;

            for (int i = 0; i < path.Count - 1 && index == 0; i++)
            {
                pathGeom = new LineGeometry(path[i].ToPoint(), path[i + 1].ToPoint());

                double tolerance = 2;
                tolerance += getThickness();

                if (pathGeom.FillContains(point, tolerance, ToleranceType.Absolute))
                {
                    index = i + 1;
                }
            }


            return(index);
        }
コード例 #2
0
        public bool DotIsOnLine(Dot dot)
        {
            var ChekDot = new Point(dot.X, dot.Y);

            for (int i = 0; i < WireDotList.Count - 1; i++)
            {
                var A = WireDotList.ElementAt(i);
                var B = WireDotList.ElementAt(i + 1);


                var start = new Point(A.X, A.Y);
                var end   = new Point(B.X, B.Y);

                var line = new LineGeometry(start, end);

                if (line.FillContains(ChekDot, 2, ToleranceType.Absolute))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        private bool HitTestDrawing(GeometryDrawing drawing, Point pt)
        {
            Pen   pen   = drawing.Pen;
            Brush brush = drawing.Brush;

            if (pen != null)
            {
                if (drawing.Geometry.StrokeContains(pen, pt))
                {
                    return(true);
                }
                Geometry geometry = drawing.Geometry;

                LineGeometry      line      = null;
                EllipseGeometry   ellipse   = null;
                RectangleGeometry rectangle = null;
                PathGeometry      path      = null;

                if (TryCast.Cast(geometry, out path))
                {
                    if (path.FillContains(pt, 1, ToleranceType.Absolute))
                    {
                        return(true);
                    }

                    //PathFigureCollection pathFigures = path.Figures;
                    //int itemCount = pathFigures.Count;
                    //if (itemCount == 1)
                    //{
                    //    if (pathFigures[0].IsClosed && path.FillContains(pt))
                    //    {
                    //        return true;
                    //    }
                    //}
                    //else
                    //{
                    //    for (int f = 0; f < itemCount; f++)
                    //    {
                    //        PathFigure pathFigure = pathFigures[f];
                    //        if (pathFigure.IsClosed)
                    //        {
                    //            PathFigureCollection testFigures = new PathFigureCollection();
                    //            testFigures.Add(pathFigure);

                    //            PathGeometry testPath = new PathGeometry();
                    //            testPath.Figures = testFigures;

                    //            if (testPath.FillContains(pt))
                    //            {
                    //                return true;
                    //            }
                    //        }
                    //    }
                    //}
                }
                else if (TryCast.Cast(geometry, out line))
                {
                    if (line.FillContains(pt))
                    {
                        return(true);
                    }
                }
                else if (TryCast.Cast(geometry, out ellipse))
                {
                    if (ellipse.FillContains(pt))
                    {
                        return(true);
                    }
                }
                else if (TryCast.Cast(geometry, out rectangle))
                {
                    if (rectangle.FillContains(pt))
                    {
                        return(true);
                    }
                }
            }
            else if (brush != null && drawing.Geometry.FillContains(pt))
            {
                return(true);
            }
            else if (drawing.Geometry.FillContains(pt))
            {
                return(true);
            }

            return(false);
        }