Esempio n. 1
0
        /// <summary>
        /// Tese to see if the Path has a convex angle.
        /// </summary>
        /// <returns><c>true</c>, if a concave angle is found, it returns false.
        /// If it makes it to the end with no concave angles, it returns fales.</returns>
        /// <param name="path">Path.</param>
        public static bool isConvex(Path path)
        {
            for (int i = 0; i < path.Count; i++)
            {
                VertexProperties vps = getVertexProperties(path, i);

                if (vps.bevelAngle < 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Splits the into convex paths.
        /// If the Path has a concave angle, the bisector is extended to find an intersection
        /// with line sgements further allong.
        /// Once the intersection is found two paths are generated and returned.
        // This is run recursively.
        /// </summary>
        /// <returns>A set of convex paths.</returns>
        /// <param name="path">Path.</param>
        public static Paths splitIntoConvexPaths(Path path, int gener = 0, int part = 0)
        {
            Paths returnPaths = new Paths();

            if (gener > 25)
            {
                returnPaths.Add(path);
                return(returnPaths);
            }

//			Debug.Log("["+gener+"]["+part+"] * * * * * * * * * * * * splitIntoConvexPaths * * * * * * * * * * * *");
//			Pather.printPath(path);



            for (int i = 0; i < path.Count; i++)
            {
                VertexProperties vps = getVertexProperties(path, i);

                //Debug.Log(bevelAng);

                if (vps.bevelAngle < 0f)
                {
                    Vector2 nBisector = -vps.bisector;

                    //Debug.Log("CONCAVE FOUND at (" + i + "): " + path[i] +" this is concave! bisector=" + nBisector);

                    PointOnPathSegment pops = findSelfIntersection(path, i, nBisector);
                    //Debug.Log("Intersection Before: "+pops.index+", (" + pops.point.X+", "+pops.point.Y+")");

                    if (pops.index >= 0)
                    {
                        // split paths at this index

                        // A

                        Path a = new Path();

                        a.Add(path[i]);

                        if (pops.t < .2f)
                        {
                            a.Add(path[prevI(path, pops.index)]);
                        }
                        else if (pops.t < .9f)
                        {
                            a.Add(pops.point);
                        }

                        int j = pops.index;
                        while (j != i)
                        {
                            a.Add(path[j]);
                            j = nextI(path, j);
                        }


                        // B

                        Path b = new Path();

                        //Debug.Log (gener + ":"+part+ "; t="+pops.t + ",  index="+pops.index);

                        if (pops.t < .9f)
                        {
                            if (pops.t > .2f)
                            {
                                b.Add(pops.point);
                            }
                        }
                        else
                        {
                            b.Add(path[pops.index]);
                        }


                        b.Add(path[i]);

                        j = nextI(path, i);
                        while (j != pops.index)
                        {
                            b.Add(path[j]);
                            j = nextI(path, j);
                        }

                        //Debug.Log("["+gener+"] ADD A %%%%");
                        returnPaths.AddRange(splitIntoConvexPaths(a, gener + 1, 1));
                        //Debug.Log("["+gener+"] ADD A %%%% -- END");

                        //Debug.Log("["+gener+"] ADD B %%%%");
                        returnPaths.AddRange(splitIntoConvexPaths(b, gener + 1, 2));
                        //Debug.Log("["+gener+"] ADD B %%%% -- END");

                        //printPaths(returnPaths);
                    }
//					if (gener == 0)
//						printPaths(returnPaths);

                    return(returnPaths);
                }
            }

            //Debug.Log("!!! ["+gener+"] No concave found..............");
            returnPaths.Add(path);

            return(returnPaths);
        }