/// Sets the given array of points to TerrainCurve possibly replacing some (or all) of its existing nodes.
    private void SetPointsToCurve(Vector2[] points, bool fullRebuild)
    {
        // rebuild all?
        if (fullRebuild || Terrain.TerrainCurve.Count == 0)
        {
            Terrain.AddCurvePoints(points, 0, Terrain.TerrainCurve.Count - 1);
            return;
        }

        int[] indices = GetCurveIndicesInTargetArea();

        // if the boundary doesn't cross the curve, see to which of the ends of the curve should we attach
        // the generated terrain
        if (indices[0] == -2)
        {
            float firstToLastDistSq = (Terrain.TerrainCurve[0].position - points[points.Length - 1]).sqrMagnitude;
            float lastToFirstDistSq = (Terrain.TerrainCurve[Terrain.TerrainCurve.Count - 1].position - points[0]).sqrMagnitude;
            if (firstToLastDistSq < lastToFirstDistSq)
            {
                indices[0] = 0;
                indices[1] = -1;
            }
            else
            {
                indices[0] = Terrain.TerrainCurve.Count;
                indices[1] = Terrain.TerrainCurve.Count - 1;
            }
        }

        // set the points to the curve
        Terrain.AddCurvePoints(points, indices[0], indices[1]);
    }