示例#1
0
        private bool ValidPoint(PathingData outlineData, IntPoint position)
        {
            long movedDist = 0;

            OutlineData.Polygons.MovePointInsideBoundary(position, out (int polyIndex, int pointIndex, IntPoint position)movedPosition, OutlineData.EdgeQuadTrees, OutlineData.PointKDTrees, OutlineData.PointIsInside);
            if (movedPosition.polyIndex != -1)
            {
                movedDist = (position - movedPosition.position).Length();
            }

            if (outlineData.Polygons.TouchingEdge(position, outlineData.EdgeQuadTrees) ||
                outlineData.PointIsInside(position) != QTPolygonsExtensions.InsideState.Outside ||
                movedDist <= 200)
            {
                return(true);
            }

            return(false);
        }
示例#2
0
        public PathFinder(Polygons outlinePolygons,
                          long avoidInset,
                          IntRect?stayInsideBounds = null,
                          bool useInsideCache      = true,
                          string name = "")
        {
            this.Name = name;
            if (outlinePolygons.Count == 0)
            {
                return;
            }

            // Check if the outline is convex and no holes, if it is, don't create pathing data we can move anywhere in this object
            if (outlinePolygons.Count == 1)
            {
                var    currentPolygon = outlinePolygons[0];
                int    pointCount     = currentPolygon.Count;
                double negativeTurns  = 0;
                double positiveTurns  = 0;
                for (int pointIndex = 0; pointIndex < pointCount; pointIndex++)
                {
                    int      prevIndex    = (pointIndex + pointCount - 1) % pointCount;
                    int      nextIndex    = (pointIndex + 1) % pointCount;
                    IntPoint prevPoint    = currentPolygon[prevIndex];
                    IntPoint currentPoint = currentPolygon[pointIndex];
                    IntPoint nextPoint    = currentPolygon[nextIndex];

                    double turnAmount = currentPoint.GetTurnAmount(prevPoint, nextPoint);

                    if (turnAmount < 0)
                    {
                        negativeTurns += turnAmount;
                    }
                    else
                    {
                        positiveTurns += turnAmount;
                    }
                }

                if (positiveTurns == 0 || negativeTurns == 0)
                {
                    // all the turns are the same way this thing is convex
                    IsSimpleConvex = true;
                }
            }

            InsetAmount = avoidInset;

            var outsidePolygons = FixWinding(outlinePolygons);

            outsidePolygons = Clipper.CleanPolygons(outsidePolygons, InsetAmount / 60);
            if (stayInsideBounds != null)
            {
                var boundary = stayInsideBounds.Value;
                outsidePolygons.Add(new Polygon()
                {
                    new IntPoint(boundary.minX, boundary.minY),
                    new IntPoint(boundary.maxX, boundary.minY),
                    new IntPoint(boundary.maxX, boundary.maxY),
                    new IntPoint(boundary.minX, boundary.maxY),
                });

                outsidePolygons = FixWinding(outsidePolygons);
            }

            // set it to 1/4 the inset amount
            int devisor = 4;

            OutlineData = new PathingData(outsidePolygons, Math.Abs(avoidInset / devisor), useInsideCache);
        }