Пример #1
0
        /// <summary>
        /// Splits the path at the given point if the point lies on the path.
        /// </summary>
        /// <param name="path">Path to split</param>
        /// <param name="splitPoint">Point at which to cut the path</param>
        /// <returns>An enumeration of parts, or a single part if no split occurred</returns>
        public static IEnumerable <ILucidLine> Split(IEnumerable <IPoint> path, IPoint splitPoint)
        {
            var current = new LucidLine();

            current.AddVertex(path.First());

            foreach (var vertices in path.SlidingWindow(2))
            {
                var line = new AlgebraicLine(vertices);

                var lineExtent = CalculateExtent(line);
                if (Intersects(splitPoint, lineExtent))
                {
                    current.AddVertex(splitPoint);
                    yield return(current);

                    current = new LucidLine();
                    current.AddVertex(splitPoint);
                }

                current.AddVertex(line.End);
            }

            yield return(current);
        }
Пример #2
0
        /// <summary>
        /// Splits the path by the supplied by line
        /// </summary>
        /// <param name="path">Path to split</param>
        /// <param name="cutter">Cutter to cut the path by</param>
        /// <returns>An enumeration of parts, or a single part if not split occurred</returns>
        public static IEnumerable <ILucidLine> Split(IEnumerable <IPoint> path, ILucidLine cutter)
        {
            var current = new LucidLine();

            current.AddVertex(path.First());

            foreach (var vertices in path.SlidingWindow(2))
            {
                var line       = new AlgebraicLine(vertices);
                var lineExtent = CalculateExtent(line);

                foreach (var cutterLine in cutter.Vertices.SlidingWindow(2))
                {
                    var byLine       = new AlgebraicLine(cutterLine);
                    var intersection = Intersection(line, byLine);

                    if (intersection != null && Intersects(intersection, lineExtent) &&
                        Intersects(intersection, CalculateExtent(byLine)))
                    {
                        current.AddVertex(intersection);
                        yield return(current);

                        current = new LucidLine();
                        current.AddVertex(intersection);
                        break;
                    }
                }

                current.AddVertex(line.End);
            }

            yield return(current);
        }
Пример #3
0
        /// <summary>
        /// Creates a circular path form the provided referenc point, with the provided radius (size) and number of vertices
        /// </summary>
        /// <param name="point">Center point</param>
        /// <param name="size">The radius of the circular path around the center point</param>
        /// <param name="vertexOutCount">The number of vertices on the path</param>
        /// <returns></returns>
        public static ILucidLine CircularPathFromPoint(IPoint point, double size, int vertexOutCount)
        {
            double vertextSpacing = ((2d * Math.PI) / (double)vertexOutCount);
            double currentAngle   = 0;
            var    lineOut        = new LucidLine();

            for (int i = 0; i < vertexOutCount; i++)
            {
                lineOut.AddVertex(new LucidVertex()
                {
                    X = (size * Math.Cos(currentAngle)) + point.X,
                    Y = (size * Math.Sin(currentAngle)) + point.Y
                });

                currentAngle += vertextSpacing;
            }

            lineOut.AddVertex(lineOut.Vertices.First());

            return(lineOut);
        }