Beispiel #1
0
        private bool DoesLineCrossBoundery(IntPoint startPoint, IntPoint endPoint)
        {
            for (int bounderyIndex = 0; bounderyIndex < bounderyPolygons.Count; bounderyIndex++)
            {
                Polygon boundryPolygon = bounderyPolygons[bounderyIndex];
                if (boundryPolygon.Count < 1)
                {
                    continue;
                }

                IntPoint lastPosition = boundryPolygon[boundryPolygon.Count - 1];
                for (int pointIndex = 0; pointIndex < boundryPolygon.Count; pointIndex++)
                {
                    IntPoint currentPosition = boundryPolygon[pointIndex];
                    int      startSide       = startPoint.GetLineSide(lastPosition, currentPosition);
                    int      endSide         = endPoint.GetLineSide(lastPosition, currentPosition);
                    if (startSide != 0)
                    {
                        if (startSide + endSide == 0)
                        {
                            // each point is distinctly on a different side
                            return(true);
                        }
                    }
                    else
                    {
                        // if we terminate on the line that will count as crossing
                        return(true);
                    }

                    if (endSide == 0)
                    {
                        // if we terminate on the line that will count as crossing
                        return(true);
                    }

                    lastPosition = currentPosition;
                }
            }
            return(false);
        }
		private bool DoesLineCrossBoundery(IntPoint startPoint, IntPoint endPoint)
		{
			for (int bounderyIndex = 0; bounderyIndex < bounderyPolygons.Count; bounderyIndex++)
			{
				Polygon boundryPolygon = bounderyPolygons[bounderyIndex];
				if (boundryPolygon.Count < 1)
				{
					continue;
				}

				IntPoint lastPosition = boundryPolygon[boundryPolygon.Count - 1];
				for (int pointIndex = 0; pointIndex < boundryPolygon.Count; pointIndex++)
				{
					IntPoint currentPosition = boundryPolygon[pointIndex];
					int startSide = startPoint.GetLineSide(lastPosition, currentPosition);
					int endSide = endPoint.GetLineSide(lastPosition, currentPosition);
					if (startSide != 0)
					{
						if (startSide + endSide == 0)
						{
							// each point is distinctly on a different side
							return true;
						}
					}
					else
					{
						// if we terminate on the line that will count as crossing
						return true;
					}
					
					if (endSide == 0)
					{
						// if we terminate on the line that will count as crossing
						return true;
					}

					lastPosition = currentPosition;
				}
			}
			return false;
		}