﻿using System;
using Gamelogic.Grids;
using UnityEngine;

public class PointyHexShape : CustomGridBuilder
{
	public int size = 1;
	public override IGrid<TCell, TPoint> MakeGrid<TCell, TPoint>()
	{
		if (typeof (TPoint) != typeof (PointyHexPoint))
		{
			throw new Exception("This script can only be used with PointyHexGrids");
		}

		return (IGrid<TCell, TPoint>) PointyHexGrid<TCell>
			.BeginShape()
			.Hexagon(2*size - 1)
			.Filter(p => Rotate30(p).Magnitude() < (3.5f * size - 3) * Mathf.Sqrt(3) / 2)
			.EndShape();
	}

	private PointyHexPoint Rotate30(PointyHexPoint p)
	{
		return new PointyHexPoint(p.X - p.Y, p.X + 2 * p.Y);
	}
}
