using System.Collections.Generic;
using ProceduralToolkit.ClipperLib;
using UnityEngine;
namespace ProceduralToolkit
{
///
/// Utility class for conversion of Clipper data from and to Unity format
///
public class ClipperUtility
{
public const float ClipperScale = 100000;
public static List ToIntPath(IReadOnlyList path)
{
var intPath = new List(path.Count);
foreach (var vertex in path)
{
intPath.Add(ToIntPoint(vertex));
}
return intPath;
}
public static List ToIntPath(List path)
{
return path.ConvertAll(ToIntPoint);
}
public static List ToVector2Path(List intPath)
{
return intPath.ConvertAll(ToVector2);
}
public static List> ToIntPaths(List> paths)
{
return paths.ConvertAll(ToIntPath);
}
public static List> ToVector2Paths(List> intPaths)
{
return intPaths.ConvertAll(ToVector2Path);
}
public static void ToVector2Paths(List> intPaths, ref List> paths)
{
paths.Clear();
foreach (List intPath in intPaths)
{
paths.Add(ToVector2Path(intPath));
}
}
public static IntPoint ToIntPoint(Vector2 vector2)
{
return new IntPoint(vector2.x*ClipperScale, vector2.y*ClipperScale);
}
public static Vector2 ToVector2(IntPoint intPoint)
{
return new Vector2(intPoint.X/ClipperScale, intPoint.Y/ClipperScale);
}
}
}