internal void CopyFrom(SimpleFixedSizeList <T> points) { //if (points._count > _count) // Debug.LogError("Source array is larger than destination!"); _count = points._count; for (int i = 0; i < _count; i++) { _elements[i] = points[i]; } }
internal static bool ClipPointsAgainstAABBEdge(SimpleFixedSizeList <Vector2> points, bool isBottomOrTopEdge, bool isBottomOrLeftEdge, float edgePosition) { int inputPointsCount = points.Count; if (inputPointsCount < 1) { return(false); } _outputPoints.Clear(); int coord = isBottomOrTopEdge ? 1 : 0; // 1->y : 0->x Vector2 previousPoint = points[inputPointsCount - 1]; bool isPreviousPointInside = isBottomOrLeftEdge ? (previousPoint[coord] > edgePosition) : (previousPoint[coord] < edgePosition); bool areInputPointsUnchanged = isPreviousPointInside; for (int i = 0; i < inputPointsCount; i++) { Vector2 currentPoint = points[i]; bool isCurrentPointInside = isBottomOrLeftEdge ? (currentPoint[coord] > edgePosition) : (currentPoint[coord] < edgePosition); if (isCurrentPointInside != isPreviousPointInside) { //intersection Vector2 dir = currentPoint - previousPoint; float x = !isBottomOrTopEdge ? edgePosition : previousPoint.x + (dir.x / dir.y) * (edgePosition - previousPoint.y); float y = isBottomOrTopEdge ? edgePosition : previousPoint.y + (dir.y / dir.x) * (edgePosition - previousPoint.x); _outputPoints.Add(new Vector2(x, y)); areInputPointsUnchanged = false; } if (isCurrentPointInside) { _outputPoints.Add(currentPoint); } previousPoint = currentPoint; isPreviousPointInside = isCurrentPointInside; } points.CopyFrom(_outputPoints); return(areInputPointsUnchanged); }